processed.
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 Pekka Riikonen
+ Copyright (C) 2003 - 2004 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
unsigned int lcolor_set : 1;
/* Command */
+ unsigned int loadmap : 1;
unsigned int writemap : 1;
unsigned int writehtml : 1;
unsigned int writemaphtml : 1;
/* Bitmap data */
unsigned char *bitmap; /* Loaded bitmap image */
- SilcUInt32 bitsilc_map_size; /* Size of bitmap */
+ SilcUInt32 bitmap_size; /* Size of bitmap */
SilcUInt32 width; /* Bitmap width in pixels */
SilcUInt32 height; /* Bitmap height in pixels */
SilcUInt32 maxcolor; /* Max color value in bitmap */
MapFonts font; /* Current font */
/* Output methods */
+ SilcMapCommandStruct loadmap;
SilcMapCommandStruct writemap;
SilcMapCommandStruct writehtml;
SilcMapCommandStruct writerel;
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 Pekka Riikonen
+ Copyright (C) 2003 - 2004 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
/* Read width and height */
- ret = fscanf(fp, "%s %ld %ld %ld ",
- type, &map->width, &map->height, &map->maxcolor);
+ ret = fscanf(fp, "%s %ld %ld %ld ", type,
+ (unsigned long *)&map->width,
+ (unsigned long *)&map->height,
+ (unsigned long *)&map->maxcolor);
if (ret < 4) {
fprintf(stderr, "Invalid PPM file");
retval = FALSE;
}
/* Read the picture */
- map->bitsilc_map_size = map->width * 3 * map->height;
- map->bitmap = silc_malloc(map->bitsilc_map_size);
- ret = fread(map->bitmap, map->bitsilc_map_size, 1, fp);
+ map->bitmap_size = map->width * 3 * map->height;
+ map->bitmap = silc_malloc(map->bitmap_size);
+ ret = fread(map->bitmap, map->bitmap_size, 1, fp);
if (ret < 0) {
fprintf(stderr, "fread: %s\n", strerror(errno));
retval = FALSE;
{
FILE *fp;
int retval = TRUE;
- int i, k;
SILC_LOG_DEBUG(("Write PPM '%s'", filename));
}
/* Write the header */
- fprintf(fp, "P6 %ld %ld %ld\n", map->width, map->height, map->maxcolor);
+ fprintf(fp, "P6 %ld %ld %ld\n",
+ (unsigned long)map->width,
+ (unsigned long)map->height,
+ (unsigned long)map->maxcolor);
/* Write the bitmap */
- fwrite(map->bitmap, map->bitsilc_map_size, 1, fp);
+ fwrite(map->bitmap, map->bitmap_size, 1, fp);
fclose(fp);
return retval;
/* Sanity checks */
if (height > map->height - y) {
- fprintf(stderr, "Requesting too much height: %ld\n", height);
+ fprintf(stderr, "Requesting too much height: %ld\n",
+ (unsigned long)height);
return FALSE;
}
if (width > map->width - x) {
- fprintf(stderr, "Requesting too much width: %ld\n", width);
+ fprintf(stderr, "Requesting too much width: %ld\n",
+ (unsigned long)width);
return FALSE;
}
(*ret_map)->width = width;
(*ret_map)->height = height;
(*ret_map)->maxcolor = map->maxcolor;
- (*ret_map)->bitsilc_map_size = (width * 3) * height;
- (*ret_map)->bitmap = silc_malloc((*ret_map)->bitsilc_map_size);
+ (*ret_map)->bitmap_size = (width * 3) * height;
+ (*ret_map)->bitmap = silc_malloc((*ret_map)->bitmap_size);
/* Copy the requested area */
for (i = 0; i < height; i++) {
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 Pekka Riikonen
+ Copyright (C) 2003 - 2004 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
SilcInt16 r, g, b, lr, lg, lb;
int i;
- map->conn_num++;
SILC_LOG_DEBUG(("Processing the data from server (%d/%d)",
map->conn_num, map->conns_num));
- /* Change colors according to server status */
- silc_map_parse_color(mapconn->up_color, &r, &g, &b);
- silc_map_parse_color(mapconn->up_text_color, &lr, &lg, &lb);
- if (mapconn->down) {
- silc_map_parse_color(mapconn->down_color, &r, &g, &b);
- silc_map_parse_color(mapconn->down_text_color, &lr, &lg, &lb);
- }
+ map->conn_num++;
+ if (map->conn_num != map->conns_num)
+ return;
- /* Execute the map commands */
- silc_dlist_start(mapconn->commands);
- while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) {
- if (cmd->cut) {
- if (silc_map_cut(map, cmd->x, cmd->y, cmd->width,
- cmd->height, &ret_map)) {
- silc_map_write_ppm(ret_map, cmd->filename);
- silc_map_free(ret_map);
- }
- continue;
+ /* Load the map image to be processed */
+ if (!map->bitmap) {
+ if (!map->loadmap.loadmap || !map->loadmap.filename) {
+ silc_schedule_task_add(map->client->schedule, 0,
+ silc_map_process_done, map, 0, 1,
+ SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ return;
}
- if (cmd->draw_line) {
- if (cmd->color_set) {
- r = cmd->r;
- g = cmd->g;
- b = cmd->b;
- }
- silc_map_draw_line(map, cmd->width, cmd->x, cmd->y, cmd->x2, cmd->y2,
- r, g, b);
- continue;
+ if (!silc_map_load_ppm(map, map->loadmap.filename)) {
+ silc_schedule_task_add(map->client->schedule, 0,
+ silc_map_process_done, map, 0, 1,
+ SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
+ return;
}
+ }
- if (cmd->draw_text) {
- if (cmd->color_set) {
- lr = cmd->r;
- lg = cmd->g;
- lb = cmd->b;
- }
- silc_map_draw_text(map, cmd->text, cmd->x, cmd->y, lr, lg, lb);
+ /* Now process all received data one by one */
+ silc_dlist_start(map->conns);
+ while ((mapconn = silc_dlist_get(map->conns)) != SILC_LIST_END) {
- continue;
+ /* Change colors according to server status */
+ silc_map_parse_color(mapconn->up_color, &r, &g, &b);
+ silc_map_parse_color(mapconn->up_text_color, &lr, &lg, &lb);
+ if (mapconn->down) {
+ silc_map_parse_color(mapconn->down_color, &r, &g, &b);
+ silc_map_parse_color(mapconn->down_text_color, &lr, &lg, &lb);
}
- if (cmd->draw_circle) {
- if (cmd->color_set) {
- r = cmd->r;
- g = cmd->g;
- b = cmd->b;
+ /* Execute the map commands */
+ silc_dlist_start(mapconn->commands);
+ while ((cmd = silc_dlist_get(mapconn->commands)) != SILC_LIST_END) {
+ if (cmd->cut) {
+ if (silc_map_cut(map, cmd->x, cmd->y, cmd->width,
+ cmd->height, &ret_map)) {
+ silc_map_write_ppm(ret_map, cmd->filename);
+ silc_map_free(ret_map);
+ }
+ continue;
}
- if (cmd->lcolor_set) {
- lr = cmd->lr;
- lg = cmd->lg;
- lb = cmd->lb;
+
+ if (cmd->draw_line) {
+ if (cmd->color_set) {
+ r = cmd->r;
+ g = cmd->g;
+ b = cmd->b;
+ }
+ silc_map_draw_line(map, cmd->width, cmd->x, cmd->y, cmd->x2, cmd->y2,
+ r, g, b);
+ continue;
+ }
+
+ if (cmd->draw_text) {
+ if (cmd->color_set) {
+ lr = cmd->r;
+ lg = cmd->g;
+ lb = cmd->b;
+ }
+ silc_map_draw_text(map, cmd->text, cmd->x, cmd->y, lr, lg, lb);
+ continue;
}
- silc_map_draw_circle(map, cmd->x, cmd->y, r, g, b,
- cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb);
- continue;
- }
- if (cmd->draw_rectangle) {
- if (cmd->color_set) {
- r = cmd->r;
- g = cmd->g;
- b = cmd->b;
+ if (cmd->draw_circle) {
+ if (cmd->color_set) {
+ r = cmd->r;
+ g = cmd->g;
+ b = cmd->b;
+ }
+ if (cmd->lcolor_set) {
+ lr = cmd->lr;
+ lg = cmd->lg;
+ lb = cmd->lb;
+ }
+ silc_map_draw_circle(map, cmd->x, cmd->y, r, g, b,
+ cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb);
+ continue;
}
- if (cmd->lcolor_set) {
- lr = cmd->lr;
- lg = cmd->lg;
- lb = cmd->lb;
+
+ if (cmd->draw_rectangle) {
+ if (cmd->color_set) {
+ r = cmd->r;
+ g = cmd->g;
+ b = cmd->b;
+ }
+ if (cmd->lcolor_set) {
+ lr = cmd->lr;
+ lg = cmd->lg;
+ lb = cmd->lb;
+ }
+ silc_map_draw_rectangle(map, cmd->x, cmd->y, r, g, b,
+ cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb);
+ continue;
}
- silc_map_draw_rectangle(map, cmd->x, cmd->y, r, g, b,
- cmd->text, cmd->lposx, cmd->lposy, lr, lg, lb);
- continue;
}
+ /* Write the html data file */
+ if (map->writehtml.writehtml)
+ silc_map_writehtml(map, mapconn);
+
+ /* Write uptime reliability data */
+ if (map->writerel.writerel)
+ silc_map_writerel(map, mapconn);
+
}
- /* Write the html data file */
- if (map->writehtml.writehtml)
- silc_map_writehtml(map, mapconn);
+ SILC_LOG_DEBUG(("All connections processed"));
- /* Write uptime reliability data */
- if (map->writerel.writerel)
- silc_map_writerel(map, mapconn);
-
- /* If this was last connection, we are done and ready to quit. */
- if (map->conn_num == map->conns_num) {
- SILC_LOG_DEBUG(("All connections processed"));
-
- /* Produce output */
- if (map->writemap.writemap)
- silc_map_write_ppm(map, map->writemap.filename);
- for (i = 0; i < map->cut_count; i++) {
- if (silc_map_cut(map, map->cut[i].x, map->cut[i].y, map->cut[i].width,
- map->cut[i].height, &ret_map)) {
- silc_map_write_ppm(ret_map, map->cut[i].filename);
- silc_map_free(ret_map);
- }
+ /* Produce output */
+ if (map->writemap.writemap)
+ silc_map_write_ppm(map, map->writemap.filename);
+ for (i = 0; i < map->cut_count; i++) {
+ if (silc_map_cut(map, map->cut[i].x, map->cut[i].y, map->cut[i].width,
+ map->cut[i].height, &ret_map)) {
+ silc_map_write_ppm(ret_map, map->cut[i].filename);
+ silc_map_free(ret_map);
}
+ }
- /* Write the HTML index file */
- if (map->writehtml.writehtml)
- silc_map_writehtml_index(map);
+ /* Write the HTML index file */
+ if (map->writehtml.writehtml)
+ silc_map_writehtml_index(map);
- /* Write the HTML map file(s) */
- silc_map_writemaphtml(map);
+ /* Write the HTML map file(s) */
+ silc_map_writemaphtml(map);
- /* Write uptime reliability graph */
- if (map->writerel.writerel)
- silc_map_writerelhtml(map);
+ /* Write uptime reliability graph */
+ if (map->writerel.writerel)
+ silc_map_writerelhtml(map);
- /* Schedule to stop */
- silc_schedule_task_add(map->client->schedule, 0,
- silc_map_process_done, map, 0, 1,
- SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
- }
+ /* Schedule to stop */
+ silc_schedule_task_add(map->client->schedule, 0,
+ silc_map_process_done, map, 0, 1,
+ SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);
}
/* Timeout callback to detect if server is down. */
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 Pekka Riikonen
+ Copyright (C) 2003 - 2004 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* Destroy old bitmap if loadmaped */
silc_free(map->bitmap);
+ map->bitmap = NULL;
- /* Loadmap the bitmap image */
- if (!silc_map_load_ppm(map, filename))
- retval = SILC_CONFIG_ESILENT;
+ /* Execute directly if there are no connections */
+ if (map->conns_num == 0) {
+ /* Load the bitmap image */
+ if (!silc_map_load_ppm(map, filename))
+ retval = SILC_CONFIG_ESILENT;
+ } else {
+ map->loadmap.filename = strdup(filename);
+ map->loadmap.writemap = TRUE;
+ }
/* Cleanup */
silc_free(filename);
}
/* Execute directly if not for connection */
- if (!curr_conn) {
+ if (!curr_conn && map->bitmap) {
/* Draw the rectangle */
ret = silc_map_draw_rectangle(map, silc_map_lon2x(map, lon),
silc_map_lat2y(map, lat),
}
/* Execute directly if not for connection */
- if (!curr_conn) {
+ if (!curr_conn && map->bitmap) {
/* Draw the circle */
ret = silc_map_draw_circle(map, silc_map_lon2x(map, lon),
silc_map_lat2y(map, lat),
width = 1;
/* Execute directly if not for connection */
- if (!curr_conn) {
+ if (!curr_conn && map->bitmap) {
/* Draw the line */
ret = silc_map_draw_line(map, width,
silc_map_lon2x(map, lon),
lat, lon, r, g, b, text));
/* Execute directly if not for connection */
- if (!curr_conn) {
+ if (!curr_conn && map->bitmap) {
/* Print the text */
ret = silc_map_draw_text(map, text,
silc_map_lon2x(map, lon),
SILC_LOG_DEBUG(("Parsing status: %s", silc_config_strerror(ret)));
if (ret && ret != SILC_CONFIG_ESILENT) {
- fprintf(stderr, "Error parsing commands: %s, line %ld\n",
+ fprintf(stderr, "Error parsing commands: %s, line %d\n",
silc_config_strerror(ret), silc_config_get_line(file));
retval = FALSE;
}
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 Pekka Riikonen
+ Copyright (C) 2003 - 2004 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
if (mapconn->clients) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "Local clients</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.clients);
+ (unsigned long)mapconn->data.clients);
}
if (mapconn->channels) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "Local channels</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.channels);
+ (unsigned long)mapconn->data.channels);
}
if (mapconn->server_ops) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "Local server operators</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.server_ops);
+ (unsigned long)mapconn->data.server_ops);
}
if (mapconn->router_ops) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "Local router operators</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.router_ops);
+ (unsigned long)mapconn->data.router_ops);
}
if (mapconn->cell_clients) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "Cell clients</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.cell_clients);
+ (unsigned long)mapconn->data.cell_clients);
}
if (mapconn->cell_channels) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "Cell channels</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.cell_channels);
+ (unsigned long)mapconn->data.cell_channels);
}
if (mapconn->cell_servers) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "Cell servers</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.cell_servers);
+ (unsigned long)mapconn->data.cell_servers);
}
if (mapconn->all_clients) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "All SILC clients</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.all_clients);
+ (unsigned long)mapconn->data.all_clients);
}
if (mapconn->all_channels) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "All SILC channels</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.all_channels);
+ (unsigned long)mapconn->data.all_channels);
}
if (mapconn->all_servers) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "All SILC servers</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.all_servers);
+ (unsigned long)mapconn->data.all_servers);
}
if (mapconn->all_routers) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "All SILC routers</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.all_routers);
+ (unsigned long)mapconn->data.all_routers);
}
if (mapconn->all_server_ops) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "All SILC server operators</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.all_server_ops);
+ (unsigned long)mapconn->data.all_server_ops);
}
if (mapconn->all_router_ops) {
fprintf(fp, "<tr><td> ");
fprintf(fp, "All SILC router operators</td><td> :</td><td> %ld</td></tr>\n",
- mapconn->data.all_router_ops);
+ (unsigned long)mapconn->data.all_router_ops);
}
fprintf(fp, "</table>\n");
}