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
SILC_CONFIG_CALLBACK(silc_map_cmd_writemap);
SILC_CONFIG_CALLBACK(silc_map_cmd_writemaphtml);
SILC_CONFIG_CALLBACK(silc_map_cmd_writehtml);
+SILC_CONFIG_CALLBACK(silc_map_cmd_writerel);
SILC_CONFIG_CALLBACK(silc_map_cmd_cut);
SILC_CONFIG_CALLBACK(silc_map_cmd_rectangle);
SILC_CONFIG_CALLBACK(silc_map_cmd_circle);
static const SilcConfigTable silc_map_table_loadmap[] =
{
{ "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_loadmap, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_writemap[] =
{
{ "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_writemap, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_writemaphtml[] =
{ "image", SILC_CONFIG_ARG_STR, silc_map_cmd_writemaphtml, NULL },
{ "cut_lat", SILC_CONFIG_ARG_STRE, silc_map_cmd_writemaphtml, NULL },
{ "cut_lon", SILC_CONFIG_ARG_STRE, silc_map_cmd_writemaphtml, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_writehtml[] =
{
{ "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_writehtml, NULL },
{ "class", SILC_CONFIG_ARG_STRE, silc_map_cmd_writehtml, NULL },
+ { NULL },
+};
+
+static const SilcConfigTable silc_map_table_writerel[] =
+{
+ { "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_writerel, NULL },
+ { "class", SILC_CONFIG_ARG_STRE, silc_map_cmd_writerel, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_cut[] =
{ "width", SILC_CONFIG_ARG_INT, silc_map_cmd_cut, NULL },
{ "height", SILC_CONFIG_ARG_INT, silc_map_cmd_cut, NULL },
{ "filename", SILC_CONFIG_ARG_STR, silc_map_cmd_cut, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_rectangle[] =
{ "lposx", SILC_CONFIG_ARG_INT, silc_map_cmd_rectangle, NULL },
{ "lposy", SILC_CONFIG_ARG_INT, silc_map_cmd_rectangle, NULL },
{ "lcolor", SILC_CONFIG_ARG_STR, silc_map_cmd_rectangle, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_circle[] =
{ "lposx", SILC_CONFIG_ARG_INT, silc_map_cmd_circle, NULL },
{ "lposy", SILC_CONFIG_ARG_INT, silc_map_cmd_circle, NULL },
{ "lcolor", SILC_CONFIG_ARG_STR, silc_map_cmd_circle, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_line[] =
{ "b_lon", SILC_CONFIG_ARG_STR, silc_map_cmd_line, NULL },
{ "width", SILC_CONFIG_ARG_STR, silc_map_cmd_line, NULL },
{ "color", SILC_CONFIG_ARG_STR, silc_map_cmd_line, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_text[] =
{ "lon", SILC_CONFIG_ARG_STR, silc_map_cmd_text, NULL },
{ "color", SILC_CONFIG_ARG_STR, silc_map_cmd_text, NULL },
{ "text", SILC_CONFIG_ARG_STR, silc_map_cmd_text, NULL },
+ { NULL },
};
static const SilcConfigTable silc_map_table_server[] =
silc_map_cmd_line, silc_map_table_line },
{ "text", SILC_CONFIG_ARG_BLOCK,
silc_map_cmd_text, silc_map_table_text },
+ { NULL },
};
static const SilcConfigTable silc_map_table_main[] =
silc_map_cmd_writemaphtml, silc_map_table_writemaphtml },
{ "writehtml", SILC_CONFIG_ARG_BLOCK,
silc_map_cmd_writehtml, silc_map_table_writehtml },
+ { "writerel", SILC_CONFIG_ARG_BLOCK,
+ silc_map_cmd_writerel, silc_map_table_writerel },
{ "cut", SILC_CONFIG_ARG_BLOCK,
silc_map_cmd_cut, silc_map_table_cut },
{ "rectangle", SILC_CONFIG_ARG_BLOCK,
SilcMap map = context;
int retval = SILC_CONFIG_OK;
- if (!map->bitmap) {
+ if (!map->loadmap.loadmap) {
fprintf(stderr, "You must call loadmap command before server command\n");
return SILC_CONFIG_ESILENT;
}
SILC_LOG_DEBUG(("loadmap: file: %s", filename));
- /* Destroy old bitmap if loadmaped */
- silc_free(map->bitmap);
-
- /* Loadmap the bitmap image */
- if (!silc_map_load_ppm(map, filename))
- retval = SILC_CONFIG_ESILENT;
+ map->loadmap.filename = strdup(filename);
+ map->loadmap.loadmap = TRUE;
/* Cleanup */
silc_free(filename);
SILC_LOG_DEBUG(("writemap: file: %s", filename));
- /* Execute directly if there are no connections */
- if (map->conns_num == 0) {
- /* Writemap the map */
- if (!silc_map_write_ppm(map, filename))
- retval = SILC_CONFIG_ESILENT;
- } else {
- map->writemap.filename = strdup(filename);
- map->writemap.writemap = TRUE;
- }
+ map->writemap.filename = strdup(filename);
+ map->writemap.writemap = TRUE;
/* Cleanup */
silc_free(filename);
int retval = SILC_CONFIG_OK;
if (type == SILC_CONFIG_ARG_BLOCK) {
+ int i;
if (!filename)
return SILC_CONFIG_EMISSFIELDS;
- SILC_LOG_DEBUG(("writehmaphtml: file: %s", filename));
+ SILC_LOG_DEBUG(("writemaphtml: file: %s", filename));
/* Will generate HTML map page */
- map->writemaphtml.filename = filename;
- map->writemaphtml.text = text;
+ i = map->writemaphtml_count;
+ map->writemaphtml = silc_realloc(map->writemaphtml,
+ sizeof(*map->writemaphtml) * (i + 1));
+ map->writemaphtml[i].filename = filename;
+ map->writemaphtml[i].text = text;
if (lon)
- map->writemaphtml.x = silc_map_lon2x(map, lon);
+ map->writemaphtml[i].alon = strdup(lon);
if (lat)
- map->writemaphtml.y = silc_map_lat2y(map, lat);
- map->writemaphtml.writemaphtml = TRUE;
+ map->writemaphtml[i].alat = strdup(lat);
+ map->writemaphtml[i].writemaphtml = TRUE;
+ map->writemaphtml_count++;
/* Clean up */
silc_free(lat);
return retval;
}
+/* Command: writerel, writes the uptime reliability graph. */
+
+SILC_CONFIG_CALLBACK(silc_map_cmd_writerel)
+{
+ SilcMap map = context;
+ int retval = SILC_CONFIG_OK;
+
+ if (type == SILC_CONFIG_ARG_BLOCK) {
+ if (!filename)
+ return SILC_CONFIG_EMISSFIELDS;
+
+ SILC_LOG_DEBUG(("writerel: file: %s", filename));
+
+ /* Will generate uptime reliability graph */
+ map->writerel.filename = filename;
+ map->writerel.text = text; /* class */
+ map->writerel.writerel = TRUE;
+ filename = text = NULL;
+
+ return retval;
+ }
+ if (!strcmp(name, "filename"))
+ filename = strdup((char *)val);
+ else if (!strcmp(name, "class"))
+ text = strdup((char *)val);
+ else
+ retval = SILC_CONFIG_ESILENT;
+
+ return retval;
+}
+
/* Command: cut, cut's a specified area from the map. */
SILC_CONFIG_CALLBACK(silc_map_cmd_cut)
if (type == SILC_CONFIG_ARG_BLOCK) {
SilcMap map2;
+ int i;
if (!filename || !lat || !lon || !width || !height)
return SILC_CONFIG_EMISSFIELDS;
retval = SILC_CONFIG_ESILENT;
} else {
/* After all connection blocks */
- map->cut.filename = strdup(filename);
- map->cut.x = silc_map_lon2x(map, lon);
- map->cut.y = silc_map_lat2y(map, lat);
- map->cut.width = width;
- map->cut.height = height;
- map->cut.cut = TRUE;
+ i = map->cut_count;
+ map->cut = silc_realloc(map->cut, sizeof(*map->cut) * (i + 1));
+ map->cut[i].filename = strdup(filename);
+ map->cut[i].alon = strdup(lon);
+ map->cut[i].alat = strdup(lat);
+ map->cut[i].width = width;
+ map->cut[i].height = height;
+ map->cut[i].cut = TRUE;
+ map->cut_count++;
}
} else {
SilcMapCommand cmd = silc_calloc(1, sizeof(*cmd));
silc_dlist_add(curr_conn->commands, cmd);
cmd->filename = strdup(filename);
- cmd->x = silc_map_lon2x(map, lon);
- cmd->y = silc_map_lat2y(map, lat);
+ cmd->alon = strdup(lon);
+ cmd->alat = strdup(lat);
cmd->width = width;
cmd->height = height;
cmd->cut = TRUE;
}
/* 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),
cmd->lr = lr;
cmd->lg = lg;
cmd->lb = lb;
- cmd->x = silc_map_lon2x(map, lon);
- cmd->y = silc_map_lat2y(map, lat);
- cmd->text = strdup(text);
+ cmd->alon = strdup(lon);
+ cmd->alat = strdup(lat);
+ cmd->text = text ? strdup(text) : NULL;
cmd->lposx = lposx;
cmd->lposy = lposy;
cmd->draw_rectangle = TRUE;
}
/* 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),
cmd->lr = lr;
cmd->lg = lg;
cmd->lb = lb;
- cmd->x = silc_map_lon2x(map, lon);
- cmd->y = silc_map_lat2y(map, lat);
- cmd->text = strdup(text);
+ cmd->alon = strdup(lon);
+ cmd->alat = strdup(lat);
+ cmd->text = text ? strdup(text) : NULL;
cmd->lposx = lposx;
cmd->lposy = lposy;
cmd->draw_circle = TRUE;
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),
cmd->r = r;
cmd->g = g;
cmd->b = b;
- cmd->x = silc_map_lon2x(map, lon);
- cmd->y = silc_map_lat2y(map, lat);
- cmd->x2 = silc_map_lon2x(map, lon2);
- cmd->y2 = silc_map_lat2y(map, lat2);
+ cmd->alon = strdup(lon);
+ cmd->alat = strdup(lat);
+ cmd->blon = strdup(lon2);
+ cmd->blat = strdup(lat2);
cmd->width = width;
cmd->draw_line = TRUE;
cmd->color_set = color_set;
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),
cmd->r = r;
cmd->g = g;
cmd->b = b;
- cmd->x = silc_map_lon2x(map, lon);
- cmd->y = silc_map_lat2y(map, lat);
- cmd->text = strdup(text);
+ cmd->alon = strdup(lon);
+ cmd->alat = strdup(lat);
+ cmd->text = text ? strdup(text) : NULL;
cmd->draw_text = TRUE;
cmd->color_set = color_set;
}
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",
- silc_config_strerror(ret), silc_config_get_line(file));
+ fprintf(stderr, "Error parsing commands: %s, line %d\n",
+ silc_config_strerror(ret), (int)silc_config_get_line(file));
retval = FALSE;
}