aboutsummaryrefslogtreecommitdiff
path: root/src/clientinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/clientinfo.c')
-rw-r--r--src/clientinfo.c893
1 files changed, 0 insertions, 893 deletions
diff --git a/src/clientinfo.c b/src/clientinfo.c
deleted file mode 100644
index 0aa5e3b5..00000000
--- a/src/clientinfo.c
+++ /dev/null
@@ -1,893 +0,0 @@
1/* Copyrights 2002 Luis Figueiredo (stdio@netc.pt) All rights reserved.
2 *
3 * See the LICENSE file
4 *
5 * The origin of this software must not be misrepresented, either by
6 * explicit claim or by omission. Since few users ever read sources,
7 * credits must appear in the documentation.
8 *
9 * date: Wed Oct 9 19:56:22 GMT 2002
10 *
11 * -- parse http header into "ClientInfo"
12 *
13 */
14
15#include "clientinfo.h"
16
17/*********************************************************************************************************/
18/*
19 * Initialize ClientInfo structure
20 */
21void __ILWS_init_clientinfo(struct ClientInfo *ClientInfo) {
22 char *t;
23 struct outstream *tstream=current_web_client->outstream;
24
25 ClientInfo=__ILWS_malloc(sizeof(struct ClientInfo));
26 if(ClientInfo==NULL) {
27 return;
28 };
29
30 while(tstream->next!=NULL) {
31 tstream=tstream->next;
32 };
33
34 if(tstream->fstream!=NULL) ClientInfo->outfd=fileno(tstream->fstream); //take it off?
35
36 ClientInfo->mem=__ILWS_init_buffer_list(); // First thing, other fuctions use this to allocate
37
38
39 ClientInfo->request=__ILWS_clientinfo_getreqname();
40
41 ClientInfo->inetname=NULL;
42 t=inet_ntoa(current_web_client->sa.sin_addr);
43 if((ClientInfo->inetname=__ILWS_add_buffer(ClientInfo->mem,strlen(t)+1))) {
44 memcpy(ClientInfo->inetname,t,strlen(t));
45 ClientInfo->inetname[strlen(t)]='\0';
46 };
47
48 ClientInfo->method=__ILWS_clientinfo_getmethod();
49 ClientInfo->user=__ILWS_clientinfo_getauthuser();
50 ClientInfo->pass=__ILWS_clientinfo_getauthpass();
51
52
53
54 /* Initialize List's */
55 ClientInfo->HeaderList=NULL;
56 ClientInfo->QueryList=NULL;
57 ClientInfo->PostList=NULL;
58 ClientInfo->MultiPartList=NULL;
59 ClientInfo->CookieList=NULL;
60
61 ClientInfo->Header=__ILWS_Header;
62 ClientInfo->Query=__ILWS_Query;
63 ClientInfo->QueryString=__ILWS_clientinfo_getquerystring();
64 ClientInfo->Post=__ILWS_Post;
65 ClientInfo->PostData=__ILWS_clientinfo_getpostdata();
66 ClientInfo->MultiPart=__ILWS_MultiPart;
67 ClientInfo->Cookie=__ILWS_Cookie;
68 ClientInfo->Conf=__ILWS_Conf;
69 ClientInfo->CookieString=__ILWS_Header("Cookie");
70
71}
72
73/*
74 * Free ClientInfo structure
75 */
76void __ILWS_free_clientinfo(struct ClientInfo *ClientInfo) {
77 if(ClientInfo==NULL) {
78 return;
79 };
80 __ILWS_delete_buffer_list(ClientInfo->mem);
81
82 __ILWS_free(ClientInfo);
83 ClientInfo=NULL;
84}
85
86
87/*
88 * Header function for ClientInfo->Header("x")
89 */
90char *__ILWS_Header(struct ClientInfo *ClientInfo, char *str) {
91 char *tmp1,*tmp2,*tmp3,*ret;
92 struct _Header *hl=ClientInfo->HeaderList;
93 char *defret="";
94 size_t size;
95 size_t strsize;
96 if(str==NULL) { // request is null return whole header
97 return current_web_client->rbuf;
98 };
99 if(ClientInfo->HeaderList==NULL) {
100
101 ClientInfo->HeaderList=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Header));
102 if(ClientInfo->HeaderList==NULL) {
103 return defret;
104 };
105 ClientInfo->HeaderList->next=NULL;
106 ClientInfo->HeaderList->data=NULL;
107 ClientInfo->HeaderList->id=NULL;
108 hl=ClientInfo->HeaderList;
109 };
110 // First search if exists
111
112 while(hl->next!=NULL) {
113 if(hl->next->id!=NULL) {
114 if(!strcmp(hl->next->id,str)) {
115
116 return hl->next->data;
117 };
118 };
119 hl=hl->next;
120 };
121
122 /* Doesn't exists */
123 strsize=strlen(str);
124 if(!(hl->next=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Header)))) {
125 return defret;
126 };
127 if(!(hl->next->id=__ILWS_add_buffer(ClientInfo->mem,strsize+1))) {
128 return defret;
129 };
130
131 memcpy(hl->next->id,str,strsize);
132 hl->next->id[strsize]=0;
133 hl->next->data=defret;
134 hl->next->next=NULL;
135
136 if(!(tmp3=__ILWS_malloc(strsize+3))) {
137 return defret;
138 };
139 snprintf(tmp3,strsize+3,"%s: ",str);
140 tmp1=__ILWS_stristr(current_web_client->rbuf,tmp3);
141 __ILWS_free(tmp3);
142 if(tmp1==NULL) {
143 return defret;
144 };
145
146 tmp1+=strsize+2;
147 if(!(tmp2=strstr(tmp1,"\r\n"))) { // Unexpected (security anyway)
148 return defret;
149 };
150 if((size=(unsigned int)(tmp2-tmp1))<0) {
151 return defret;
152 };
153 if(!(ret=__ILWS_add_buffer(ClientInfo->mem,size+1))) { //malloc & register
154 return defret;
155 };
156 memcpy(ret,tmp1,size);
157 ret[size]=0;
158 hl->next->data=ret;
159 return ret;
160}
161
162/*
163 * Function for Querydata
164 */
165char *__ILWS_Query(struct ClientInfo *ClientInfo, char *handle) {
166 char *tmp1,*tmp2,*tmp3,*tmp4,*ret;
167 char *defret="";
168 size_t strsize;
169 size_t size;
170 int j=0,ch;
171 int seek=1;
172 unsigned int i;
173 unsigned int *iddb=NULL;
174 unsigned int *iddb2=NULL;
175 unsigned int idf=0;
176 int rw=0; // 0 data 1 number of vars; (return what?)
177 struct _Query *ql=ClientInfo->QueryList;
178
179
180 if(handle==NULL) {
181 return ClientInfo->QueryString;
182 };
183 if(handle[0]=='#') rw=1;
184 // allocate first node from the list
185 if(ClientInfo->QueryList==NULL) {
186 ClientInfo->QueryList=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Query));
187 if(ClientInfo->QueryList==NULL) {
188 if(rw) return 0;
189 return defret;
190 };
191 ClientInfo->QueryList->next=NULL;
192 ClientInfo->QueryList->data=NULL;
193 ClientInfo->QueryList->id=NULL;
194 ql=ClientInfo->QueryList;
195 };
196 // done allocating
197
198
199 // First search if exists and fetch values;
200
201 idf=1;
202 iddb=&idf;
203 seek=1;
204
205 while(ql->next!=NULL) {
206 if(ql->next->id!=NULL) {
207 if(!strcmp(ql->next->id,handle+rw) && *iddb >= 0) {
208 if(seek==1) {
209 iddb=&ql->next->index; // atribute iddb to first node
210 iddb2=&ql->next->idf; // atribute iddb2 to counting
211 if(rw) return (char *)*iddb2;
212 if(ql->next->idf==1) {
213 return ql->next->data;
214 };
215 j=*iddb;
216 seek++;
217 };
218 *iddb=*iddb-1;
219
220 if(*iddb<=0) {
221 *iddb=j-1;
222 if(j<=1) {
223 *iddb=*iddb2; // go to start if any
224 //return defret; // to be null
225 };
226 return ql->next->data; // Return existent
227 };
228
229 };
230 };
231 ql=ql->next;
232 };
233
234
235
236 /* Doesn't exists */
237 strsize=strlen(handle+rw);
238 tmp1=strstr(current_web_client->rbuf,"?");
239 tmp3=strstr(current_web_client->rbuf," HTTP"); // End of GET header
240 if(tmp1!=NULL && tmp1<tmp3) {
241 tmp1+=1;
242 } else {
243 if(rw)return 0;
244 return defret;
245 }
246
247 // Working here
248 idf=0;
249 ret=defret;
250 seek=1;
251 tmp4=tmp1;
252 while(seek==1) {
253 tmp1=tmp4;
254 do {
255 tmp2=strstr(tmp1,handle+rw);
256 if(tmp2==NULL) { // must be nonnull
257 if(iddb!=NULL && iddb2!=NULL) { // if iddb2 is null then is just one value;
258 *iddb2=*iddb;
259 if(!rw)*iddb=*iddb-1;
260 };
261 if(rw) {
262 if(ret==defret) return 0;
263 return (char *)*iddb2;
264 }
265 return ret; // if first null return defret (ret=defret);
266
267 };
268 tmp1=tmp2+strsize;
269 } while ((tmp2[-1]!='?' && tmp2[-1]!='&') || tmp2[strsize]!='='); // Johannes E. Schindelin Fix
270
271 if(tmp3<tmp2) {
272 if(iddb!=NULL && iddb2!=NULL) {
273 *iddb2=*iddb;
274 if(!rw)*iddb=*iddb-1;
275 };
276 if(rw) {
277 if(ret==defret) return 0;
278 return (char *)*iddb2;
279 }
280
281 return ret;
282 };
283
284 tmp4=tmp1;
285 // if not null, so add an node;
286
287 // Working here ^
288 ql->next=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Query));
289 if(ql->next==NULL) {
290 if(handle[0]=='#') rw=1;
291 return defret;
292 };
293 ql->next->id=__ILWS_add_buffer(ClientInfo->mem,strsize+1);
294 if(ql->next->id==NULL) {
295 if(handle[0]=='#') rw=1;
296 return defret;
297 };
298 memcpy(ql->next->id,handle+rw,strsize);
299 ql->next->id[strsize]=0;
300 if(idf==0) {
301 ql->next->index=0;
302 iddb=&ql->next->index;
303 iddb2=&ql->next->idf; // second holds information about number of fetchs;
304
305 };
306 ql->next->data=defret;
307 ql->next->next=NULL;
308
309
310 tmp1=strstr(tmp2,"&"); // tmp1 goes to next '&'
311 tmp2+=strsize+1; // tmp2 goes to start of data
312 tmp3=strstr(tmp2," HTTP"); // tmp3 goes to the end of Get header
313 if(tmp1==NULL || ((unsigned int)tmp1>(unsigned int)tmp3)) {
314 size=tmp3-tmp2; // MUST HAVE (" HTTP") else, server don't let in
315 } else {
316 size=tmp1-tmp2;
317 };
318 if(size<1) {
319 if(handle[0]=='#') rw=1;
320 return defret;
321 };
322
323
324 ql->next->data=__ILWS_add_buffer(ClientInfo->mem,size+1);
325 if(ql->next->data==NULL) {
326 if(handle[0]=='#') rw=1;
327 return defret;
328 };
329 j=0;
330 for(i=0;i<size;i++) { // Hex translation here
331 switch (ch=tmp2[j]) {
332 case '+':
333 ch=' ';
334 break;
335 case '%':
336
337 tmp1=__ILWS_malloc(3);
338 if(tmp1==NULL) {
339 if(rw) return 0;
340 return defret;
341 };
342 strncpy(tmp1,&tmp2[j+1],2);
343 tmp1[2]=0;
344 ch=strtol(tmp1,NULL,16);
345 j+=2;
346 size-=2;
347
348 __ILWS_free(tmp1);
349 break;
350 };
351 ql->next->data[i]=ch;
352 j++;
353 };
354 ql->next->data[size]='\0';
355 ret=ql->next->data; // to the last
356 ql=ql->next;
357 *iddb=*iddb+1;
358 idf++;
359 };
360 return ret;
361}
362
363/*
364 * Function for Postdata
365 */
366char *__ILWS_Post(struct ClientInfo *ClientInfo, char *handle) {
367 char *tmp1,*tmp2,*tmp3,*ret;
368 struct _Post *pl=ClientInfo->PostList;
369 char *defret="";
370 int *iddb=NULL,*iddb2=NULL;
371 int idf;
372 int seek=1;
373 size_t strsize;
374 size_t size;
375 int j=0,ch;
376 unsigned int i;
377 int rw=0; //return what;
378
379 tmp1=strstr(current_web_client->rbuf,"Content-type: multipart/form-data"); // multipart this post doesn't work
380 if(tmp1!=NULL) {
381 return ClientInfo->MultiPart(handle).data;
382 };
383 if(handle==NULL) {
384 return ClientInfo->PostData;
385 };
386 if(handle[0]=='#')rw=1;
387 /* Allocate the list */
388 if(ClientInfo->PostList==NULL) {
389 if(!(ClientInfo->PostList=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Post)))) {
390 if(rw) return 0;
391 return defret;
392 };
393 ClientInfo->PostList->next=NULL;
394 ClientInfo->PostList->data=NULL;
395 ClientInfo->PostList->id=NULL;
396 pl=ClientInfo->PostList;
397 };
398
399 // First search if exists
400 idf=1;
401 iddb=&idf;
402 seek=1;
403 while(pl->next!=NULL) {
404 if(pl->next->id!=NULL) {
405 if(!strcmp(pl->next->id,handle+rw) && iddb>=0) {
406 if(seek==1) {
407 iddb=&pl->next->index;
408 iddb2=&pl->next->idf;
409 if(rw) return (char *)(*iddb2);
410 if(pl->next->idf==1) {
411 return pl->next->data;
412 };
413 j=*iddb;
414 seek++;
415 };
416 *iddb=*iddb-1;
417
418 if(*iddb<=0) {
419 *iddb=j-1;
420 if(j<=1) {
421 *iddb=*iddb2;
422
423 //return defret;
424 };
425 return pl->next->data;
426 };
427 };
428 };
429 pl=pl->next;
430 };
431
432
433
434
435
436 /* Doesn't exists */
437 strsize=strlen(handle+rw);
438 tmp1=strstr(current_web_client->rbuf,"\r\n\r\n");
439 if(tmp1!=NULL)
440 tmp1+=4;
441 else {
442 if(rw) return 0;
443 return defret;
444 };
445 idf=0;
446 ret=defret;
447 seek=1;
448 tmp3=tmp1;
449 while(seek==1) {
450 tmp1=tmp3;
451 do {
452 tmp2=strstr(tmp1,handle+rw);
453 if(tmp2==NULL) { // mustn't be null
454 if(iddb!=NULL && iddb2!=NULL) { // if iddb2 is null then is just one value;
455 *iddb2=*iddb;
456 if(!rw)*iddb=*iddb-1;
457 };
458 if(rw) {
459 if(ret==defret) return 0;
460 return (char *)*iddb2;
461 }
462 return ret; // if first null return defret (ret=defret);
463
464 };
465 tmp1=tmp2+strsize;
466 } while ((tmp2[-1]!='\n' && tmp2[-1]!='&') || tmp2[strsize]!='='); // Johannes E. Schindelin Fix
467 tmp3=tmp1;
468
469
470 pl->next=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Post));
471 if(pl->next==NULL) {
472 if(rw) return 0;
473 return defret;
474 };
475 pl->next->id=__ILWS_add_buffer(ClientInfo->mem,strsize+1);
476 if(pl->next->id==NULL) {
477 if(rw) return 0;
478 return defret;
479 };
480 memcpy(pl->next->id,handle+rw,strsize);
481 pl->next->id[strsize]=0;
482 if(idf==0) {
483 pl->next->index=0;
484 iddb=&pl->next->index;
485 iddb2=&pl->next->idf;
486 };
487
488 pl->next->data=defret;
489 pl->next->next=NULL;
490
491 tmp1=strstr(tmp2,"&"); // goes to the next & (end of data)
492 tmp2+=strsize+1; // tmp2 goes to start of data
493 if(tmp1==NULL) {
494 size=strlen(tmp2);
495 } else {
496 size=tmp1-tmp2;
497 };
498 if(size==0) {
499 if(rw) return 0;
500 return defret;
501 };
502
503 pl->next->data=__ILWS_add_buffer(ClientInfo->mem,size+1);
504 if(pl->next->data==NULL) {
505 return defret;
506 };
507 j=0;
508 for(i=0;i<size;i++) { // hex translation here
509 switch (ch=tmp2[j]) {
510 case '+':
511 ch=' ';
512 break;
513 case '%':
514
515 tmp1=__ILWS_malloc(3);
516 if(tmp1==NULL) {
517 if(rw) return 0;
518 return defret;
519 };
520 strncpy(tmp1,&tmp2[j+1],2);
521 tmp1[2]=0;
522
523 ch=strtol(tmp1,NULL,16);
524 j+=2;
525 size-=2;
526
527 __ILWS_free(tmp1);
528 break;
529 };
530 pl->next->data[i]=ch;
531 j++;
532 };
533 pl->next->data[size]='\0';
534 ret=pl->next->data; // to the last
535 *iddb=*iddb+1;
536 idf++;
537 pl=pl->next;
538 //pl->next->data=ret;
539 };
540 return ret;
541}
542
543/*
544 * Function for MultiPart formdata
545 */
546struct _MultiPart __ILWS_MultiPart(struct ClientInfo *ClientInfo, char *handle) {
547 char *tmp1,*tmp2,*tmp3;
548 int i;
549 char *name;
550 size_t namesize;
551 struct _MultiPart *ml=ClientInfo->MultiPartList;
552 struct _MultiPart defret={"","",0,""};
553 size_t strsize;
554 char *boundary; size_t boundarysize;
555 // IE C43o6Fn6Et74e65n6Et74-2DT54y79p70e65:3A 20m6Du75l6Ct74i69p70a61r72t74/2Ff66o6Fr72m6D-2Dd64a61t74a61
556 // NS C43o6Fn6Et74e65n6Et74-2Dt74y79p70e65:3A 20m6Du75l6Ct74i69p70a61r72t74/2Ff66o6Fr72m6D-2Dd64a61t74a61
557 tmp1=__ILWS_stristr(current_web_client->rbuf,"Content-type: multipart/form-data");
558 if(tmp1==NULL) return defret;
559 if(ClientInfo->MultiPartList==NULL) {
560 ClientInfo->MultiPartList=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _MultiPart));
561 if(ClientInfo->MultiPartList==NULL) {
562 return defret;
563 };
564 ClientInfo->MultiPartList->next=NULL;
565 ClientInfo->MultiPartList->id=NULL;
566 ClientInfo->MultiPartList->data=NULL;
567 ClientInfo->MultiPartList->filename=NULL;
568 ClientInfo->MultiPartList->size=0;
569 ml=ClientInfo->MultiPartList;
570 };
571 // Check if handle exists
572 while(ml->next!=NULL) {
573 if(ml->next->id!=NULL) {
574 if(!strcmp(ml->next->id,handle)) {
575
576 return *ml->next;
577 };
578 };
579 ml=ml->next;
580 };
581
582
583 strsize=strlen(handle);
584 ml->next=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _MultiPart));
585 if(ml->next==NULL) {
586 return defret;
587 };
588 ml->next->id=__ILWS_add_buffer(ClientInfo->mem,strsize+1);
589 if(ml->next->id==NULL) {
590 return defret;
591 };
592 memcpy(ml->next->id,handle,strsize);
593 ml->next->id[strsize]=0;
594 ml->next->data="";
595 ml->next->filename="";
596 ml->next->size=0;
597 ml->next->next=NULL;
598
599 tmp1=strstr(tmp1,"boundary=");
600 if(tmp1==NULL) return defret;
601 tmp1+=9;
602 tmp2=strstr(tmp1,"\r\n");
603 if(tmp2<tmp1 || tmp2==NULL) return defret;
604 /* boundary */
605 boundarysize=tmp2-tmp1;
606 boundary=__ILWS_add_buffer(ClientInfo->mem,boundarysize+3);
607 if(boundary==NULL) {
608 return defret;
609 };
610 memcpy(boundary,tmp1,boundarysize);
611 boundary[boundarysize]=0;
612
613
614 /* handle */
615 namesize=boundarysize+41+strlen(handle);
616 name=__ILWS_add_buffer(ClientInfo->mem,namesize+1);
617 if(name==NULL) {
618 return defret;
619 };
620 snprintf(name,namesize,"%s\r\nContent-Disposition: form-data; name=",boundary);
621 namesize=strlen(name);
622
623 tmp1=strstr(tmp1,"\r\n\r\n"); // go to data
624 if(tmp1==NULL) return defret;
625
626 do {
627 i=memcmp(tmp1,name,namesize);
628 if(i==0) {
629 tmp1+=namesize;
630 if(tmp1[0]=='\"')tmp1+=1;
631 if(strncmp(tmp1,handle,strlen(handle))){
632 i=1;
633 }else {
634 if((tmp1[strsize]!=' ') && (tmp1[strsize]!='\"') && (tmp1[strsize]!='\r') && (tmp1[strsize]!=';') ) i=1;
635 };
636
637 }else {
638 tmp1+=1;
639 };
640 } while(i!=0 && (tmp1+namesize<current_web_client->rbuf+current_web_client->rbufsize)); // Search init of data
641 if(i!=0) return defret;
642 //tmp1+=namesize;
643 tmp2=strstr(tmp1,"filename="); // get filename
644 if(tmp2!=NULL) {
645 tmp2+=9;
646 if(tmp2[0]=='\"')tmp2+=1;
647 tmp3=strstr(tmp2,"\r\n");
648 ml->next->filename=__ILWS_add_buffer(ClientInfo->mem,(tmp3-tmp2)+1);
649 if(ml->next->filename==NULL) {
650 return defret;
651 };
652 memcpy(ml->next->filename,tmp2,tmp3-tmp2);
653 ml->next->filename[tmp3-tmp2]='\0';
654 if(ml->next->filename[tmp3-tmp2-1]=='\"')
655 ml->next->filename[tmp3-tmp2-1]='\0';
656
657 };
658 tmp2=strstr(tmp1,"\r\n\r\n"); // data init
659 if(tmp2==NULL)return defret;
660 tmp2+=4;
661 tmp3=tmp2;
662 do {
663
664 i=memcmp(tmp3,boundary,boundarysize);
665 if(i!=0)tmp3+=1;
666 } while(i!=0 && (tmp3+boundarysize<current_web_client->rbuf+current_web_client->rbufsize)); // End of data
667 if(i!=0) return defret;
668 tmp3-=4; // back "\r\n\r\n"
669
670 // copy data to node
671 if(!(ml->next->data=__ILWS_add_buffer(ClientInfo->mem,(tmp3-tmp2)+1))) {
672 return defret;
673 };
674 memcpy(ml->next->data,tmp2,tmp3-tmp2);
675 ml->next->data[tmp3-tmp2]='\0';
676 ml->next->size=tmp3-tmp2;
677
678
679
680
681 return *ml->next;
682
683};
684
685/*
686 * Function for CookieData
687 */
688char *__ILWS_Cookie(struct ClientInfo *ClientInfo, char *handle) {
689 char *defret="";
690 char *tmp1,*tmp2,*ret;
691 int size;
692 int strsize;
693 struct _Cookie *cl=ClientInfo->CookieList;
694
695
696 tmp1=strstr(current_web_client->rbuf,"\nCookie: "); // start of cookie string
697 if(tmp1==NULL) { // no cookies
698 return defret;
699 };
700 tmp1+=8;
701 if(handle==NULL) {
702 return ClientInfo->CookieString;
703 };
704
705 if(ClientInfo->CookieList==NULL) {
706
707 ClientInfo->CookieList=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Cookie));
708 if(ClientInfo->CookieList==NULL) {
709 return defret;
710 };
711 ClientInfo->CookieList->next=NULL;
712 ClientInfo->CookieList->data=NULL;
713 ClientInfo->CookieList->id=NULL;
714 cl=ClientInfo->CookieList;
715 }
716 // First search if exists
717 while(cl->next!=NULL) {
718 if(cl->next->id!=NULL) {
719 if(!strcmp(cl->next->id,handle)) {
720
721 return cl->next->data;
722 };
723 };
724 cl=cl->next;
725 };
726
727 strsize=strlen(handle);
728 if(!(cl->next=__ILWS_add_buffer(ClientInfo->mem,sizeof(struct _Cookie)))) {
729 return defret;
730 };
731 if(!(cl->next->id=__ILWS_add_buffer(ClientInfo->mem,strsize+1))) {
732 return defret;
733 };
734 memcpy(cl->next->id,handle,strsize);
735 cl->next->id[strsize]=0;
736 cl->next->data=defret;
737 cl->next->next=NULL;
738 do {
739 tmp2=strstr(tmp1,handle);
740 if(tmp2==NULL) {
741 return defret;
742 }else if(tmp2[strsize]==';' && tmp2[-1]==' ') {
743 cl->next->data=__ILWS_add_buffer(ClientInfo->mem,6);
744 snprintf(cl->next->data,5,"True");
745 return cl->next->data;
746 };
747 tmp1=tmp2+strsize;
748 }while(tmp2[-1]!=' ' || tmp2[strsize]!='=');
749
750 tmp1=strstr(tmp2,";"); // end of data
751 tmp2+=strsize+1; // start of data
752 if(tmp1==NULL) {
753 size=strstr(tmp2,"\r")-tmp2;
754
755 } else {
756 size=tmp1-tmp2;
757 };
758 if(size<1) {
759 return defret;
760 };
761
762 ret=__ILWS_add_buffer(ClientInfo->mem,size+1);
763 if(ret==NULL) {
764 return defret;
765 };
766
767 memcpy(ret,tmp2,size);
768 ret[size]='\0';
769 cl->next->data=ret;
770 return cl->next->data;
771};
772
773/*
774 * get whole query string
775 */
776char *__ILWS_clientinfo_getquerystring(struct ClientInfo *ClientInfo) {
777 char *tmp1,*tmp2,*ret;
778 char *defret="";
779 size_t size;
780 tmp1=strstr(current_web_client->rbuf,"?");
781 tmp2=strstr(current_web_client->rbuf,"HTTP");
782 if(tmp1!=NULL && tmp1<tmp2)
783 tmp1+=1;
784 else
785 return defret;
786 size=(tmp2-tmp1)-1;
787 ret=__ILWS_add_buffer(ClientInfo->mem,size+1);
788 if(ret==NULL) {
789 return defret;
790 };
791 memcpy(ret,tmp1,size);
792 ret[size]=0;
793 return ret;
794};
795
796/*
797 * get whole post data
798 */
799char *__ILWS_clientinfo_getpostdata(struct ClientInfo *ClientInfo) {
800 char *tmp1,*ret;
801 char *defret="";
802 size_t size;
803 tmp1=strstr(current_web_client->rbuf,"\r\n\r\n");
804 if(tmp1!=NULL && (tmp1+4)<(char*)(current_web_client->rbuf+current_web_client->rbufsize))
805 tmp1+=4;
806 else
807 return defret;
808 size=(current_web_client->rbuf+current_web_client->rbufsize)-tmp1;
809 ret=__ILWS_add_buffer(ClientInfo->mem,size+1);
810 if(ret==NULL) {
811 return defret;
812 };
813 memcpy(ret,tmp1,size);
814 ret[size]='\0';
815 return ret;
816}
817
818/*
819 * get method (GET POST HEAD etc)
820 */
821char *__ILWS_clientinfo_getmethod(struct ClientInfo *ClientInfo) {
822 char *tmp1,*ret;
823 char *defret="";
824 size_t size;
825 tmp1=strstr(current_web_client->rbuf," "); // first space
826 if(tmp1==NULL) {
827 return defret;
828 };
829 size=tmp1-current_web_client->rbuf;
830 ret=__ILWS_add_buffer(ClientInfo->mem,size+1);
831 if(ret==NULL) {
832 return defret;
833 };
834 memcpy(ret,current_web_client->rbuf,size);
835 ret[size]=0;
836 return ret;
837}
838
839/*
840 * get request name (GET /taltal HTTP/1.0) returning /taltal
841 */
842char *__ILWS_clientinfo_getreqname(struct ClientInfo *ClientInfo) {
843 char *ret;
844 char *tmp1=strstr(current_web_client->rbuf,"/"); // Must have /
845 char *tmp2=strstr(tmp1,"?");
846 char *tmp3=strstr(tmp1," HTTP");
847 char *defret="";
848 size_t i,j;
849 int ch;
850 size_t size=0;
851 if(tmp1==NULL || tmp3==NULL) return defret;
852 if(tmp2==NULL || tmp2>tmp3) {
853 tmp2=tmp3;
854 };
855 //tmp1+=1;
856 size=tmp2-tmp1;
857 if(size<1)
858 return defret;
859 ret=__ILWS_add_buffer(ClientInfo->mem,size+1);
860 if(ret==NULL) {
861 return defret;
862 };
863 j=0;
864 for(i=0;i<size;i++) { // hex translation here
865 switch (ch=tmp1[j]) {
866 case '+':
867 ch=' ';
868 break;
869 case '%':
870
871 tmp2=__ILWS_malloc(3);
872 if(tmp2==NULL) {
873 return defret;
874 };
875 strncpy(tmp2,&tmp1[j+1],2);
876 tmp2[2]=0;
877
878 ch=strtol(tmp2,NULL,16);
879 j+=2;
880 size-=2;
881 __ILWS_free(tmp2);
882 break;
883 };
884 ret[i]=ch;
885 j++;
886 };
887 //pl->next->data[size]='\0';
888 //memcpy(ret,tmp1,size);
889 ret[size]=0;
890 return ret;
891}
892
893