22 {
"gif",
"image/gif" },
23 {
"jpg",
"image/jpeg"},
24 {
"jpeg",
"image/jpeg"},
25 {
"png",
"image/png" },
26 {
"zip",
"image/zip" },
28 {
"tar",
"image/tar" },
29 {
"htm",
"text/html" },
30 {
"html",
"text/html" },
31 {
"js",
"text/javascript" },
34 {
"json",
"application/json" },
35 {
"ico",
"image/x-icon" },
50 nowtime =
time((time_t *)0);
51 nowtm = (
struct tm *)gmtime(&nowtime);
52 strftime(buffer, 128,
"%a, %d %b %Y %H:%M:%S GMT", nowtm);
58 static char date_buffer[128];
59 static char snd_buffer[
BUFSIZE+1];
62 case WERROR: (void)printf(
"ERROR: %s:%s exiting pid=%d\n",s1, s2, getpid());
break;
64 (void)
sprintf(logbuffer,
"<HTML><BODY><H1>webDid: %s %s</H1></BODY></HTML>\r\n", s1, s2);
66 (void)printf(
"webDid: %s %s\n",s1, s2);
68 (void)
sprintf(snd_buffer,
"HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n",
69 date_buffer, (
int)strlen(logbuffer),
"text/html");
70 (void)
web_write(conn_id,snd_buffer,(
int)strlen(snd_buffer));
71 (void)
web_write(conn_id,logbuffer,(
int)strlen(logbuffer));
73 case LOG: (void)printf(
"INFO: %s:%s:%d\n",s1, s2,conn_id);
88 int i, j, n = 0, found = 0;
91 if(!strchr(buffer,
'?'))
93 parptr = (
char *)pars;
94 for(i = 0; *parptr; i++)
98 if((ptr = strstr(buffer, parptr)))
100 ptrs[
i] = ptr+(int)strlen(parptr);
106 for(i = 0; ptrs[
i]; i++)
108 if((ptr = strchr(ptrs[i],
'&')))
110 while((ptr = strchr(ptrs[i],
'%')))
112 sscanf((ptr + 1),
"%2X",&code);
115 for(j = 0; *(ptr + 2); j++)
135 strcpy(pars[0],
"node=");
136 strcpy(pars[1],
"browser=");
141 strcpy(node, ptrs[0]);
142 sscanf(ptrs[1],
"%d",browser);
144 printf(
"parse pars - node %s, browser id %d\n", node, *browser);
155 strcpy(pars[0],
"dimnode=");
156 strcpy(pars[1],
"dimserver=");
157 strcpy(pars[2],
"dimserverid=");
158 strcpy(pars[3],
"browser=");
163 strcpy(node, ptrs[0]);
164 strcpy(server, ptrs[1]);
165 sscanf(ptrs[2],
"%d",pid);
166 sscanf(ptrs[3],
"%d",browser);
168 printf(
"parse pars - node %s, server %s, pid %d, browser %d\n",node, server, *pid, *browser);
178 strcpy(pars[0],
"dimservice=");
179 strcpy(pars[1],
"reqNr=");
180 strcpy(pars[2],
"reqId=");
181 strcpy(pars[3],
"force=");
186 strcpy(service, ptrs[0]);
187 sscanf(ptrs[1],
"%d",req);
188 sscanf(ptrs[2],
"%d",browser);
189 sscanf(ptrs[3],
"%d",force);
191 printf(
"\nparse service pars - service %s %d %d %d\n\n",service, *req, *browser, *force);
208 buffer_size = (int)strlen(buffer) + 1;
209 if(buffer_size > conv_buffer_size )
213 conv_buffer =
malloc((
size_t)buffer_size);
214 conv_buffer_size = buffer_size;
229 sscanf(ptr,
"%2X",&code);
242 static char date_buffer[128];
243 static char snd_buffer[
BUFSIZE+1];
244 static char snd_data_buffer[
BUFSIZE+1];
246 char node[128], server[256], service[256];
247 int pid, ret, req, browser, force;
256 strcpy(datatype,
"application/json");
271 strcpy(snd_data_buffer,
"{}");
272 ptr = snd_data_buffer;
284 strcpy(snd_data_buffer,
"{}");
285 ptr = snd_data_buffer;
298 strcpy(datatype,
"text/html");
305 strcpy(snd_data_buffer,
"{}");
306 ptr = snd_data_buffer;
319 strcpy(snd_data_buffer,
"{}");
320 ptr = snd_data_buffer;
326 strcpy(snd_data_buffer,
"");
328 strcpy(snd_data_buffer,
"load");
329 ptr = snd_data_buffer;
333 (void)
sprintf(snd_buffer,
"HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n",
334 date_buffer, (
int)strlen(ptr), datatype);
335 (void)
web_write(conn_id,snd_buffer,(
int)strlen(snd_buffer));
337 printf(
"SENDING DATA to conn %d:\n%s\n",conn_id, snd_buffer);
338 (void)
web_write(conn_id,ptr,(
int)strlen(ptr));
340 printf(
"SENDING DATA to conn %d:\n%s\n",conn_id, ptr);
346 static char date_buffer[128];
347 static char snd_buffer[
BUFSIZE+1];
348 static char snd_data_buffer[
BUFSIZE+1];
350 char node[128], server[256], service[256];
351 int pid, ret, req, browser, force;
360 strcpy(datatype,
"application/json");
375 strcpy(snd_data_buffer,
"{}");
376 ptr = snd_data_buffer;
388 strcpy(snd_data_buffer,
"{}");
389 ptr = snd_data_buffer;
402 strcpy(datatype,
"text/html");
409 strcpy(snd_data_buffer,
"{}");
410 ptr = snd_data_buffer;
423 strcpy(snd_data_buffer,
"{}");
424 ptr = snd_data_buffer;
430 strcpy(snd_data_buffer,
"");
432 strcpy(snd_data_buffer,
"load");
433 ptr = snd_data_buffer;
437 (void)
sprintf(snd_buffer,
"HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n",
438 date_buffer, (
int)strlen(ptr), datatype);
439 (void)
web_write(conn_id,snd_buffer,(
int)strlen(snd_buffer));
441 printf(
"SENDING DATA to conn %d:\n%s\n",conn_id, snd_buffer);
442 (void)
web_write(conn_id,ptr,(
int)strlen(ptr));
444 printf(
"SENDING DATA to conn %d:\n%s\n",conn_id, ptr);
449 int j, file_fd, buflen, len;
453 static char snd_buffer[
BUFSIZE+1];
454 static char date_buffer[128];
463 printf(
"Got %s\n", buffer);
464 if( strncmp(buffer,
"GET ",4) && strncmp(buffer,
"get ",4) )
466 log_it(
SORRY,
"Only simple GET operation supported",buffer,conn_id);
480 printf(
"Got 1 %s\n", buffer);
483 if(buffer[j] ==
'.' && buffer[j+1] ==
'.')
485 log_it(
SORRY,
"Parent directory (..) path names not supported",buffer,conn_id);
489 if((
int)strlen(buffer) == 5)
491 if( !strncmp(&buffer[0],
"GET /",5) || !strncmp(&buffer[0],
"get /",5) )
493 (void)strcpy(buffer,
"GET /index.html");
495 if((
int)strlen(buffer) == 8)
497 if( !strncmp(&buffer[0],
"GET /smi",8) || !strncmp(&buffer[0],
"get /smi",8) )
499 (
void)strcpy(buffer,
"GET /smi/index.html");
502 buflen=(int)strlen(buffer);
507 if( !strncmp(&buffer[buflen-len],
extensions[i].ext, (
size_t)len))
521 printf(
"Got %s\n", buffer);
522 if(!strncmp(&buffer[5],
"didHeader",9))
527 else if(!strncmp(&buffer[5],
"didData",7))
532 else if(!strncmp(&buffer[5],
"didServices",11))
537 else if(!strncmp(&buffer[5],
"didServiceData",14))
542 else if(!strncmp(&buffer[5],
"didPoll",7))
547 else if(!strncmp(&buffer[5],
"didQuery",8))
552 else if(!strncmp(&buffer[5],
"smiData",7))
557 else if(!strncmp(&buffer[5],
"smiObjects",10))
592 log_it(
SORRY,
"file extension type not supported",buffer,conn_id);
597 if(( file_fd = open(&buffer[5],O_RDONLY |
O_BINARY)) == -1)
599 log_it(
SORRY,
"failed to open file",&buffer[5],conn_id);
604 while ( (ret = (
int)read(file_fd, snd_buffer, BUFSIZE)) > 0 )
610 if(( file_fd = open(&buffer[5],O_RDONLY |
O_BINARY)) == -1)
612 log_it(
SORRY,
"failed to open file",&buffer[5],conn_id);
617 (void)
sprintf(snd_buffer,
"HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n",
618 date_buffer, flen, fstr);
619 (void)
web_write(conn_id,snd_buffer,(
int)strlen(snd_buffer));
621 printf(
"SENDING to conn %d:\n%s\n",conn_id, snd_buffer);
624 while ( (ret = (
int)read(file_fd, snd_buffer, BUFSIZE)) > 0 ) {
627 printf(
"SENDING data to conn %d: %d bytes\n",conn_id, ret);
643 printf(
" Disconnect received - conn: %d to %s@%s\n", conn_id,
652 printf(
" Connection request received - conn: %d\n", conn_id);
667 printf(
" - DIM panic: recv_rout(): Bad switch, exiting...\n");
686 int main(
int argc,
char **argv)
697 strcpy(currwd, argv[0]);
698 printf(
"arg %s\n",currwd);
699 ptr = strrchr(currwd,
'/');
704 ptr = strrchr(currwd,
'\\');
710 log_it(
LOG,
"webDid starting",argv[1],getpid());
void getTime(char *buffer)
char * getJSONSmiBuffer(char *node, int browser)
char * update_smi_objects(char *node, char *server, int pid, int browser)
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
static int conv_buffer_size
int getNodeParameters(char *buffer, char *node, int *browser)
int getParameters(char *buffer, char(*pars)[], char *ptrs[])
int getServiceParameters(char *buffer, char *service, int *req, int *browser, int *force)
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
void sendSmiData(int conn_id, char *buffer, int type)
int getServerParameters(char *buffer, char *node, char *server, int *pid, int *browser)
static char * conv_buffer
int main(int argc, char **argv)
char * unescape(char *buffer)
char * getJSONBuffer(char *node, int browser)
int check_browser_changes()
void sendData(int conn_id, char *buffer, int type)
void dim_print_date_time()
void dim_print_msg(char *msg, int severity)
static void handler(int conn_id, char *packet, int size, int status)
static void error_handler(int conn_id, int severity, int errcode, char *reason)
int get_node_name(char *node_name)
sprintf(name1,"NewService%d", i)
char * getJSONHeader(int isSMI)
void sendFile(int conn_id, char *buffer, int size)
int update_service_data(char *service, int conn_id, int subscribe, int req, int browser, int force)
void log_it(int type, char *s1, char *s2, int conn_id)