7f63318a2ca87c4ec54af1a708acf92ce9507412
[crypto.git] / apps / silcmap / silcmap.h
1 /*
2
3   silcmap.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2003 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SILCMAP_H
21 #define SILCMAP_H
22
23 /* Font context */
24 typedef struct {
25   int height;
26   struct {
27     char width;
28     unsigned char data[16 * 16];
29   } font[94];
30 } MapFonts;
31
32 /* SilcMap command context. */
33 typedef struct {
34   /* Map command datas */
35   char *filename;
36   SilcInt32 x;
37   SilcInt32 y;
38   SilcInt32 x2;
39   SilcInt32 y2;
40   SilcUInt32 width;
41   SilcUInt32 height;
42   char *text;
43   SilcInt32 lposx;
44   SilcInt32 lposy;
45
46   SilcInt16 r;
47   SilcInt16 g;
48   SilcInt16 b;
49   SilcInt16 lr;
50   SilcInt16 lg;
51   SilcInt16 lb;
52   unsigned int color_set      : 1;
53   unsigned int lcolor_set     : 1;
54
55   /* Command */
56   unsigned int writemap       : 1;
57   unsigned int writehtml      : 1;
58   unsigned int writemaphtml   : 1;
59   unsigned int cut            : 1;
60   unsigned int draw_line      : 1;
61   unsigned int draw_text      : 1;
62   unsigned int draw_circle    : 1;
63   unsigned int draw_rectangle : 1;
64 } *SilcMapCommand, SilcMapCommandStruct;
65
66 /* The SilcMap context. */
67 typedef struct {
68   /* Connection data */
69   SilcClient client;            /* SILC Client context */
70   char *conffile;               /* Config file name */
71   SilcDList conns;              /* Connections */
72   SilcUInt32 conns_num;         /* Number of created connections */
73   SilcUInt32 conn_num;          /* Current number of processed connections */
74
75   /* Bitmap data */
76   unsigned char *bitmap;        /* Loaded bitmap image */
77   SilcUInt32 bitsilc_map_size;  /* Size of bitmap */
78   SilcUInt32 width;             /* Bitmap width in pixels */
79   SilcUInt32 height;            /* Bitmap height in pixels */
80   SilcUInt32 maxcolor;          /* Max color value in bitmap */
81   MapFonts font;                /* Current font */
82
83   /* Output methods */
84   SilcMapCommandStruct writemap;
85   SilcMapCommandStruct writehtml;
86   SilcMapCommandStruct *writemaphtml;
87   SilcMapCommandStruct *cut;
88   SilcUInt32 writemaphtml_count;
89   SilcUInt32 cut_count;
90 } *SilcMap;
91
92 /* SilcMap connecetion context. */
93 typedef struct {
94   /* Server and connection details */
95   SilcDList hostnames;
96   SilcDList ips;
97   int port;
98   char *public_key;
99   char *country;
100   char *city;
101   char *admin;
102   char *description;
103   int connect_timeout;
104   char *html_url;
105
106   /* Flags */
107   unsigned int connect        : 1;
108   unsigned int starttime      : 1;
109   unsigned int uptime         : 1;
110   unsigned int clients        : 1;
111   unsigned int channels       : 1;
112   unsigned int server_ops     : 1;
113   unsigned int router_ops     : 1;
114   unsigned int cell_clients   : 1;
115   unsigned int cell_channels  : 1;
116   unsigned int cell_servers   : 1;
117   unsigned int all_clients    : 1;
118   unsigned int all_channels   : 1;
119   unsigned int all_servers    : 1;
120   unsigned int all_routers    : 1;
121   unsigned int all_server_ops : 1;
122   unsigned int all_router_ops : 1;
123   unsigned int motd           : 1;
124   unsigned int down           : 1;
125   unsigned int stats_received : 1;
126   unsigned int motd_received  : 1;
127
128   /* Gathered data */
129   struct {
130     SilcUInt32 starttime;
131     SilcUInt32 uptime;
132     SilcUInt32 clients;
133     SilcUInt32 channels;
134     SilcUInt32 server_ops;
135     SilcUInt32 router_ops;
136     SilcUInt32 cell_clients;
137     SilcUInt32 cell_channels;
138     SilcUInt32 cell_servers;
139     SilcUInt32 all_clients;
140     SilcUInt32 all_channels;
141     SilcUInt32 all_servers;
142     SilcUInt32 all_routers;
143     SilcUInt32 all_server_ops;
144     SilcUInt32 all_router_ops;
145     char *motd;
146   } data;
147
148   /* Status colors */
149   char *up_color;
150   char *down_color;
151   char *up_text_color;
152   char *down_text_color;
153
154   /* Map commands */
155   SilcDList commands;
156
157   /* Back pointers */
158   SilcMap map;
159   SilcClientConnection conn;
160 } *SilcMapConnection;
161
162 extern SilcClientOperations silc_map_client_ops;
163
164 SilcMap silc_map_alloc(const char *conffile);
165 void silc_map_free(SilcMap map);
166 bool silc_map_commands_parse(SilcMap map, const char *filename);
167 void silc_map_connect(SilcMap map, SilcMapConnection mapconn);
168 bool silc_map_load_ppm(SilcMap map, const char *filename);
169 bool silc_map_write_ppm(SilcMap map, const char *filename);
170 bool silc_map_cut(SilcMap map, SilcInt32 x, SilcInt32 y,
171                   SilcUInt32 width, SilcUInt32 height,
172                   SilcMap *ret_map);
173 bool silc_map_draw(SilcMap map,
174                    SilcInt32 x, SilcInt32 y,
175                    const unsigned char *bitmap,
176                    SilcUInt32 width, SilcUInt32 height);
177 bool silc_map_draw_raw(SilcMap map,
178                        SilcInt32 x, SilcInt32 y,
179                        const unsigned char *bitmap,
180                        SilcUInt32 width, SilcUInt32 height,
181                        SilcInt16 r, SilcInt16 g, SilcInt16 b);
182 bool silc_map_draw_line(SilcMap map, SilcUInt32 width,
183                         SilcInt32 a_x, SilcInt32 a_y,
184                         SilcInt32 b_x, SilcInt32 b_y,
185                         SilcInt16 r, SilcInt16 g, SilcInt16 b);
186 bool silc_map_draw_text(SilcMap map, const char *text,
187                         SilcInt32 x, SilcInt32 y,
188                         SilcInt16 r, SilcInt16 g, SilcInt16 b);
189 bool silc_map_draw_circle(SilcMap map, SilcInt32 x, SilcInt32 y,
190                           SilcInt16 r, SilcInt16 g, SilcInt16 b,
191                           const char *label, SilcInt32 lposx, SilcInt32 lposy,
192                           SilcInt16 lr, SilcInt16 lg, SilcInt16 lb);
193 bool silc_map_draw_rectangle(SilcMap map, SilcInt32 x, SilcInt32 y,
194                              SilcInt16 r, SilcInt16 g, SilcInt16 b,
195                              const char *label, SilcInt32 lposx,
196                              SilcInt32 lposy,
197                              SilcInt16 lr, SilcInt16 lg, SilcInt16 lb);
198 double silc_map_parse_pos(char *pos);
199 int silc_map_lon2x(SilcMap map, char *latitude);
200 int silc_map_lat2y(SilcMap map, char *longitude);
201 bool silc_map_parse_color(const char *color,
202                           SilcInt16 *r, SilcInt16 *g, SilcInt16 *b);
203 bool silc_map_load_font(SilcMap map, const char *filename);
204 bool silc_map_writehtml(SilcMap map, SilcMapConnection mapconn);
205 bool silc_map_writehtml_index(SilcMap map);
206 bool silc_map_writemaphtml(SilcMap map);
207
208 #endif /* SILCMAP_H */