JunkBox_Lib  1.10.2
http_tool.c
Go to the documentation of this file.
1 
10 #ifdef CPLUSPLUS
11  #undef CPLUSPLUS
12 #endif
13 
14 
15 #include "http_tool.h"
16 
17 
19 // Basic Function.
20 //
21 
56 int send_http_header(int sofd, tList* pp, int mode)
57 {
58  int hs=0, sz=0;
59  Buffer buf;
60 
61  if (pp==NULL) return JBXL_ARGS_ERROR;
62 
63  buf = restore_protocol_header(pp, (char*)": ", mode, &hs);
64  if (buf.vldsz>0) {
65  sz = tcp_send_Buffer(sofd, &buf);
66  if (mode==ON) sz = sz - hs;
67  }
68 
69  free_Buffer(&buf);
70  return sz;
71 }
72 
73 
75 {
76  Buffer rbd;
77  int nobody = FALSE;
78 
79  if (pl==NULL) {
80  rbd = dup_Buffer(*buf);
81  return rbd;
82  }
83  if (buf==NULL || buf->vldsz<0 || buf->buf==NULL) nobody = TRUE;
84 
85  if (!nobody) {
86  // Content-Length の書き換え
87  tList* pp = pl;
88  while(pp!=NULL) {
89  if (!strcasecmp((const char*)(pp->ldat.key.buf), "Content-Length")) {
90  copy_i2Buffer(buf->vldsz, &(pp->ldat.val));
91  break;
92  }
93  pp = pp->next;
94  }
95  }
96 
97  rbd = restore_protocol_header(pl, (char*)": ", OFF, NULL);
98  if (!nobody) cat_Buffer(buf, &rbd);
99 
100  return rbd;
101 }
102 
103 
116 int send_http_Buffer(int sofd, tList* pl, Buffer* buf)
117 {
118  int sz;
119  Buffer snd;
120 /*
121  int nobody = FALSE;
122 
123  if (pl==NULL) return JBXL_ARGS_ERROR;
124  if (buf==NULL || buf->vldsz<0 || buf->buf==NULL) nobody = TRUE;
125 
126  if (!nobody) {
127  // Content-Length の書き換え
128  tList* pp = pl;
129  while(pp!=NULL) {
130  if (!strcasecmp((const char*)(pp->ldat.key.buf), "Content-Length")) {
131  copy_i2Buffer(buf->vldsz, &(pp->ldat.val));
132  break;
133  }
134  pp = pp->next;
135  }
136  }
137 
138  snd = restore_protocol_header(pl, (char*)": ", OFF, NULL);
139  if (!nobody) cat_Buffer(buf, &snd);
140 */
141 
142  snd = rebuild_http_Buffer(pl, buf);
143  sz = tcp_send_Buffer(sofd, &snd);
144  free_Buffer(&snd);
145 
146  return sz;
147 }
148 
149 
163 int send_http_file(int sofd, tList* pl, const char* fname)
164 {
165  int sz = 0;
166  FILE* fp = NULL;
167  char num[20];
168  tList* pp;
169  unsigned char* html;
170  Buffer buf;
171 
172  size_t rs;
173  UNUSED(rs);
174 
175  if (pl==NULL) return JBXL_ARGS_ERROR;
176  if (fname!=NULL) sz = file_size((char*)fname);
177  if (sz<=0) sz = 0;
178  snprintf(num, 18, "%d", sz);
179 
180  // Content-Length の書き換え
181  pp = pl;
182  while(pp!=NULL) {
183  if (!strcasecmp((const char*)(pp->ldat.key.buf), "Content-Length")) {
184  copy_s2Buffer(num, &(pp->ldat.val));
185  break;
186  }
187  pp = pp->next;
188  }
189 
190  buf = restore_protocol_header(pl, (char*)": ", OFF, NULL);
191 
192  if (fname!=NULL && sz!=0) fp = fopen(fname, "rb");
193  if (fp!=NULL) {
194  html = (unsigned char*)malloc(sz+1);
195  if (html==NULL) {
196  fclose(fp);
197  free_Buffer(&buf);
198  return JBXL_MALLOC_ERROR;
199  }
200 
201  memset(html, 0, sz+1);
202  rs = fread(html, sz, 1, fp);
203  fclose(fp);
204 
205  cat_b2Buffer(html, &buf, sz);
206  free(html);
207  }
208 
209  sz = tcp_send_Buffer(sofd, &buf);
210  free_Buffer(&buf);
211 
212  return sz;
213 }
214 
215 
240 int recv_http_header(int sofd, tList** pl, int* len, int tm, FILE* fp, int* state)
241 {
242  int cc, sz, com;
243  Buffer mbuf;
244  tList* lp;
245  int connect = TRUE;
246 
247  if (sofd<=0) return JBXL_ARGS_ERROR;
248  if (len==NULL) return JBXL_ARGS_ERROR;
250 
251  mbuf = make_Buffer(RECVBUFSZ);
252 
253  sz = 0;
254  lp = NULL;
255  *pl = NULL;
256 
257  cc = tcp_recv_Buffer_wait(sofd, &mbuf, tm);
258  com = get_http_method((char*)mbuf.buf);
259 
260  if (com>HTTP_UNKNOWN_METHOD) {
261  Loop {
262  if (cc>0) {
263  if (fp!=NULL) fwrite(mbuf.buf, cc, 1, fp);
264  lp = get_protocol_header_list_seq(lp, mbuf, ':', TRUE, TRUE);
265  sz += cc;
266  /*
267  if (sz==cc) { // is HTTP ?
268  tList* ll = find_tList_top(lp);
269  if (get_http_header_method(ll)==HTTP_UNKNOWN_METHOD) {
270  connect = HTTP_HEADER_NOT_HTTP;
271  *pl = ll;
272  break;
273  }
274  }*/
275  }
276  else {
277  connect = FALSE;
278  break;
279  }
280  //
281  *pl = find_tList_top(lp);
282  if (strncasecmp_tList(*pl, (char*)HDLIST_END_KEY, 0, 1)!=NULL) break;
283  //
284  cc = tcp_recv_Buffer_wait(sofd, &mbuf, tm);
285  }
286  }
287  else {
288  if (mbuf.vldsz>0) {
290  *pl = add_tList_node_Buffer(NULL, key, mbuf);
291  free_Buffer(&key);
292  }
294  connect = FALSE;
295  }
296 
297  free_Buffer(&mbuf);
298  if (*pl!=NULL) (*pl)->ldat.id = com;
299  if (state!=NULL) *state = connect;
300  //
301  if (sz==0 && cc==0) return 0; // 正常切断
302  if (sz==0 && cc<0) return JBXL_NET_RECV_ERROR;
303  if (*pl==NULL) return JBXL_NET_RECV_ERROR;
304  if (*len==HTTP_HEADER_NOT_HTTP) return cc;
305 
306  // コンテンツの長さを得る.
307  /*
308  Buffer hbuf = search_protocol_header(*pl, (char*)HDLIST_FIRST_LINE_KEY, 1);
309  if (hbuf.buf!=NULL) {
310  if (!strncasecmp((char*)hbuf.buf, "GET ", 4)) {
311  *len = 0;
312  }
313  free_Buffer(&hbuf);
314  }*/
315 
316  if (com==HTTP_GET_METHOD) *len = 0;
317 
319  if (is_http_header_field(*pl, (char*)"Transfer-Encoding", (char*)"chunked", 1)) {
321  }
322  }
323 
325  Buffer hbuf = search_protocol_header(*pl, (char*)"Content-Length", 1);
326  if (hbuf.buf!=NULL) {
327  *len = atoi((const char*)hbuf.buf);
328  free_Buffer(&hbuf);
329  }
330  }
331 
333  if (get_http_version_num(*pl)<=1.0 && get_http_status_num(*pl)>=200) {
334  if (is_http_header_field(*pl, (char*)"Connection", (char*)"close", 1)) {
336  }
337  }
338  }
339 
340  return sz;
341 }
342 
343 
361 int recv_http_content(int sofd, Buffer* buf, int len, int tm, FILE* fp, int* state)
362 {
363  int cc, sz;
364  Buffer rcv;
365 
366  if (state!=NULL) *state = TRUE;
367 
368  sz = buf->vldsz;
369  if (sz>0 && fp!=NULL) fwrite(buf->buf, sz, 1, fp);
370 
371  // コンテンツの残りを受信
372  rcv = make_Buffer(RECVBUFSZ);
373  while(sz<len) {
374  //
375  cc = tcp_recv_Buffer_wait(sofd, &rcv, tm);
376  if (cc>0) {
377  if (fp!=NULL) fwrite(rcv.buf, cc, 1, fp);
378  cat_Buffer(&rcv, buf);
379  sz += cc;
380  }
381  else {
382  if (state!=NULL) *state = FALSE;
383  sz = cc;
384  break;
385  }
386  //memset(rcv.buf, 0, cc);
387  }
388  free_Buffer(&rcv);
389 
390  return sz;
391 }
392 
393 
410 int recv_http_chunked(int sofd, Buffer* buf, int tm, FILE* fp, int* state)
411 {
412  int cc, sz, i;
413  int chnksz, hdsz, tlsz;
414  if (state!=NULL) *state = TRUE;
415 
417 
418  sz = buf->vldsz;
419  if (sz<=0) { // chunk のサイズを含んだデータを読み込む
420  cc = tcp_recv_Buffer_wait(sofd, &tmp, tm);
421  if (cc<=0) {
422  if (state!=NULL) *state = FALSE;
423  free_Buffer(&tmp);
424  return cc;
425  }
426  }
427  else { // 既にコンテンツがある場合は tmpへ移動
428  cat_Buffer(buf, &tmp);
429  clear_Buffer(buf);
430  }
431 
432  //
433  chnksz = sz = get_chunked_size((char*)tmp.buf, &hdsz, &tlsz);
434 
435  while (chnksz>0) {
436  //
437  if (chnksz+hdsz+tlsz > tmp.vldsz) {
438  cc = recv_http_chunked_remain(sofd, &tmp, chnksz+hdsz+tlsz, tm);
439  if (cc<=0) {
440  sz = cc;
441  break;
442  }
443  }
444 
445  Buffer cat = tmp;
446  cat.buf = tmp.buf + hdsz;
447  cat.vldsz = chnksz;
448  cat_Buffer(&cat, buf);
449  //tmp.buf[tmp.vldsz] = '\0';
450 
451  // 次の chunk用にデータをつめる
452  for (i=0; i<tmp.vldsz-chnksz-hdsz-tlsz; i++) {
453  tmp.buf[i] = tmp.buf[chnksz + hdsz + tlsz + i];
454  }
455  tmp.vldsz = tmp.vldsz - chnksz - hdsz - tlsz;
456  //tmp.buf[tmp.vldsz] = '\0';
457 
458  if (tmp.vldsz==0) {
459  cc = tcp_recv_Buffer_wait(sofd, &tmp, tm);
460  if (cc<=0) {
461  sz = cc;
462  break;
463  }
464  }
465  chnksz = get_chunked_size((char*)tmp.buf, &hdsz, &tlsz);
466  sz += chnksz;
467  }
468 
469  if (fp!=NULL) fwrite(buf->buf, buf->vldsz, 1, fp);
470 
471  free_Buffer(&tmp);
472  return sz;
473 }
474 
475 
489 int recv_http_chunked_remain(int sofd, Buffer* buf, int chnksz, int tm)
490 {
491  int cc = 0;
492  int sz = buf->vldsz;
493  if (chnksz<=sz) return 0;
494 
496 
497  while (chnksz>sz) {
498  //memset(rcv.buf, 0, cc);
499  cc = tcp_recv_Buffer_wait(sofd, &rcv, tm);
500  if (cc<=0) {
501  sz = cc;
502  break;
503  }
504  cat_Buffer(&rcv, buf);
505  sz += cc;
506  }
507 
508  free_Buffer(&rcv);
509  return sz;
510 }
511 
512 
529 int recv_http_closed(int sofd, Buffer* buf, int tm, FILE* fp)
530 {
531  int cc, sz, tout;
532  Buffer rcv;
533 
534  sz = buf->vldsz;
535 
536  rcv = make_Buffer(RECVBUFSZ);
537  while ((tout=recv_wait(sofd, tm))){
538  cc = tcp_recv_Buffer(sofd, &rcv);
539  if (cc>0) {
540  if (fp!=NULL) fwrite(rcv.buf, cc, 1, fp);
541  cat_Buffer(&rcv, buf);
542  sz += cc;
543  }
544  else {
545  break;
546  }
547  //memset(rcv.buf, 0, cc);
548  }
549  free_Buffer(&rcv);
550 
551  if (!tout) return JBXL_NET_RECV_TIMEOUT;
552 
553  return sz;
554 }
555 
556 
577 int recv_http_Buffer(int sofd, tList** pl, Buffer* buf, int tsecond, int* hdonly, int* state, int nochunk)
578 {
579  int cc=0, hs, len;
580  int connect;
581  Buffer cnt;
582  tList* lp;
583 
584  if (buf==NULL || buf->buf==NULL) return JBXL_ARGS_ERROR;
585  if (hdonly!=NULL) *hdonly = FALSE;
586 
587  clear_Buffer(buf);
588 
589  // ヘッダの受信
590  hs = recv_http_header(sofd, &lp, &len, tsecond, NULL, &connect);
591  if (state!=NULL) *state = connect;
592  if (hs<=0) return hs; // エラー
593  if (len==0 || len==HTTP_HEADER_UNKNOWN_LEN) { // ヘッダのみ
594  if (hdonly!=NULL) *hdonly = TRUE;
595  if (pl!=NULL) *pl = lp;
596  else del_tList(&lp);
597  return hs;
598  }
599 
600  // ヘッダ中に紛れ込んだコンテンツの取り出し
601  cnt = search_protocol_header(lp, (char*)HDLIST_CONTENTS_KEY, 1);
602  if (cnt.buf!=NULL) {
603  cc = cnt.vldsz;
604  hs = hs - cc;
605  copy_Buffer(&cnt, buf);
606  free_Buffer(&cnt);
607  }
608 
609  if (lp!=NULL && lp->ldat.id==HTTP_UNKNOWN_METHOD) { // not HTTP
610  *pl = lp;
611  return cc;
612  }
613 
614  // コンテンツの受信
615  if (connect) {
616  if (len>0) {
617  cc = recv_http_content(sofd, buf, len, tsecond, NULL, &connect);
618  }
619  else if (len==HTTP_HEADER_CHUNKED) {
620  connect = HTTP_HEADER_CHUNKED;
621  if (!nochunk) {
622  cc = recv_http_chunked(sofd, buf, tsecond, NULL, &connect);
623  }
624  }
625  else { //if (len==HTTP_HEADER_CLOSED_SESSION) {
626  cc = recv_http_closed(sofd, buf, tsecond, NULL);
627  connect = FALSE;
628  }
629  }
630 
631  // for Chunked
632  if (!nochunk && is_http_header_field(lp, (char*)"Transfer-Encoding", (char*)"chunked", 1)) {
633  delete_protocol_header(&lp, (char*)"Transfer-Encoding", 0);
634  char* str = itostr_ts(cc);
635  add_protocol_header(lp, (char*)"Content-Length", str);
636  freeNull(str);
637  }
638 
639  if (pl!=NULL) *pl = lp;
640  else del_tList(&lp);
641  if (cc>0) cc = cc + hs;
642 
643  if (state!=NULL) *state = connect;
644  return cc;
645 }
646 
647 
648 
667 int recv_http_file(int sofd, tList** pl, const char* fname, const char* wdir, int tsecond, int* hdonly, int* state)
668 {
669  int cc=0, hs, len;
670  Buffer buf, cnt;
671  FILE* fp = NULL;
672  const char tmpd[] = "/tmp";
673  int connect;
674 
675  if (hdonly!=NULL) *hdonly = FALSE;
676 
677  // ヘッダの受信
678  hs = recv_http_header(sofd, pl, &len, tsecond, NULL, &connect);
679  if (state!=NULL) *state = connect;
680  if (hs<=0) return hs; // エラー
681  if (len==0 || len==HTTP_HEADER_UNKNOWN_LEN) { // ヘッダのみ
682  if (hdonly!=NULL) *hdonly = TRUE;
683  return hs;
684  }
685 
686  // ヘッダ中に紛れ込んだコンテンツの取り出し
688  cnt = search_protocol_header(*pl, (char*)HDLIST_CONTENTS_KEY, 1);
689  if (cnt.buf!=NULL) {
690  /*DEBUG_MODE {
691  if (len==HTTP_HEADER_CHUNKED) {
692  char* line = get_line((char*)cnt.buf, 1);
693  int chnksz = hexstr2i(line);
694  PRINT_MESG("RECV_HTTP_FILE: INFO: Chunk Size in Header = %d\n", chnksz);
695  freeNull(line);
696  }
697  }*/
698  cc = cnt.vldsz;
699  hs = hs - cc;
700  copy_Buffer(&cnt, &buf);
701  free_Buffer(&cnt);
702  }
703 
704  // コンテンツの受信
705  if (connect) {
706  if (len>0) {
707  cc = recv_http_content(sofd, &buf, len, tsecond, NULL, &connect);
708  }
709  else if (len==HTTP_HEADER_CHUNKED) {
710  cc = recv_http_chunked(sofd, &buf, tsecond, NULL, &connect);
711  }
712  else { //if (len==HTTP_HEADER_CLOSED_SESSION) {
713  cc = recv_http_closed(sofd, &buf, tsecond, NULL);
714  connect = FALSE;
715  }
716  }
717 
718  if (cc>0) {
719  // コンテンツをファイルへ保存
720  if (fname!=NULL) fp = fopen(fname, "wb");
721  if (fp!=NULL) {
722  fwrite(buf.buf, buf.vldsz, 1, fp);
723  fclose(fp);
724  }
725  free_Buffer(&buf);
726 
727  //
728  if (fname!=NULL) {
729  buf = search_protocol_header(*pl, (char*)"Content-Encoding", 1);
730 
731  // Encoding 処理
732  if (buf.buf!=NULL) {
733  // gzip or deflate
734  if (!strncasecmp((const char*)buf.buf, "gzip", 4) ||
735  !strncasecmp((const char*)buf.buf, "deflate", 7)) {
736  #ifdef DISABLE_ZLIB
737  DEBUG_MODE PRINT_MESG("RECV_HTTP_FILE: WARNING: Content-Encoding is [%s]. But zlib is not installed!!\n", buf.buf);
738  #else
739  if (wdir==NULL) wdir = tmpd;
740  cc = gz_decode_file_replace(fname, wdir);
741  delete_protocol_header(pl, (char*)"Content-Encoding", 0);
742 
743  // for chunked
744  if (is_http_header_field(*pl, (char*)"Transfer-Encoding", (char*)"chunked", 1)) {
745  delete_protocol_header(pl, (char*)"Transfer-Encoding", 0);
746  char* str = itostr_ts(cc);
747  add_protocol_header(*pl, (char*)"Content-Length", str);
748  freeNull(str);
749  }
750  #endif
751  }
752 
753  else {
754  DEBUG_MODE PRINT_MESG("RECV_HTTP_FILE: WARNING: unknown Content-Encoding [%s]\n", buf.buf);
755  }
756 
757  free_Buffer(&buf);
758  }
759 
760  // No Encofing
761  else {
762  // for chunked
763  if (is_http_header_field(*pl, (char*)"Transfer-Encoding", (char*)"chunked", 1)) {
764  delete_protocol_header(pl, (char*)"Transfer-Encoding", 0);
765  char* str = itostr_ts(cc);
766  add_protocol_header(*pl, (char*)"Content-Length", str);
767  freeNull(str);
768  }
769  }
770  }
771  cc = cc + hs;
772  }
773 
774  if (state!=NULL) *state = connect;
775  return cc;
776 }
777 
778 
797 int save_http_xml(int cofd, tList** pl, tXML** xml, char** recvfn, const char* wdir, int timeout, int* state)
798 {
799  int header;
800 
801  if (pl==NULL || recvfn==NULL) return 0;
802 
803  *pl = NULL;
804  if (xml!=NULL) *xml = NULL;
805  *recvfn = temp_filename(wdir, WORK_FILENAME_LEN);
806 
807  int cc = recv_http_file(cofd, pl, *recvfn, wdir, timeout, &header, state);
808  if (cc<=0 || *pl==NULL) {
809  free(*recvfn);
810  *recvfn = NULL;
811  if (cc==0) return 0;
812  return JBXL_NET_RECV_ERROR;
813  }
814 
815  if (header) {
816  free(*recvfn);
817  *recvfn = NULL;
818  }
819  else {
820  if (xml!=NULL && *pl!=NULL && *recvfn!=NULL && cc>0) {
821  Buffer buf = search_protocol_header(*pl, (char*)"Content-Type", 1);
822  *xml = xml_parse_file(*recvfn);
823  if (*xml!=NULL && (*xml)->state<0) del_all_xml(xml);
824  free_Buffer(&buf);
825  }
826  }
827 
828  return cc;
829 }
830 
831 
832 
834 // Tools
835 //
836 
837 int get_http_method(char* data)
838 {
839  if (ex_strcmp("GET ", data)) return HTTP_GET_METHOD;
840  else if (ex_strcmp("PUT ", data)) return HTTP_PUT_METHOD;
841  else if (ex_strcmp("POST ", data)) return HTTP_POST_METHOD;
842  else if (ex_strcmp("DELETE ", data)) return HTTP_DELETE_METHOD;
843  else if (ex_strcmp("OPTIONS ", data)) return HTTP_OPTIONS_METHOD;
844  else if (ex_strcmp("HEAD ", data)) return HTTP_HEAD_METHOD;
845  else if (ex_strcmp("TRACE ", data)) return HTTP_TRACE_METHOD;
846  else if (ex_strcmp("CONNECT ", data)) return HTTP_CONNECT_METHOD;
847  else if (ex_strcmp("PATCH ", data)) return HTTP_PATCH_METHOD;
848  else if (ex_strcmp("LINK ", data)) return HTTP_LINK_METHOD;
849  else if (ex_strcmp("UNLINK ", data)) return HTTP_UNLINK_METHOD;
850  else if (ex_strcmp("HTTP/", data)) return HTTP_RESPONSE_METHOD;
851  // WebDAV
852  else if (ex_strcmp("PROPFIND ", data)) return HTTP_PROPFIND_METHOD;
853  else if (ex_strcmp("PROPPATCH ", data)) return HTTP_PROPPATCH_METHOD;
854  else if (ex_strcmp("MKCOL ", data)) return HTTP_MKCOL_METHOD;
855  else if (ex_strcmp("COPY ", data)) return HTTP_COPY_METHOD;
856  else if (ex_strcmp("MOVE ", data)) return HTTP_MOVE_METHOD;
857  else if (ex_strcmp("LOCK ", data)) return HTTP_LOCK_METHOD;
858  else if (ex_strcmp("UNLOCK ", data)) return HTTP_UNLOCK_METHOD;
859 
860  return HTTP_UNKNOWN_METHOD;
861 }
862 
863 
877 int is_http_header_field(tList* pl, char* field, char* value, int n)
878 {
879  int ret = FALSE;
880 
881  Buffer hbuf = search_protocol_header(pl, field, n);
882  if (hbuf.buf!=NULL) {
883  if (!strcasecmp((char*)hbuf.buf, value)) {
884  ret = TRUE;
885  }
886  free_Buffer(&hbuf);
887  }
888 
889  return ret;
890 }
891 
892 
899 {
900  int ret = HTTP_UNKNOWN_METHOD;
901 
902  if (pl==NULL) return ret;
903 
905  if (hbuf.buf!=NULL) ret = get_http_method((char*)hbuf.buf);
906 
907  return ret;
908 }
909 
910 
917 void set_http_host_header(tList* pl, char* hname, unsigned short hport)
918 {
919  Buffer buf;
920  char num[LEN_INT];
921 
922  if (pl==NULL) return;
923 
924  buf = make_Buffer(LBUF);
925  snprintf(num, LEN_INT-1, "%d", hport);
926  copy_s2Buffer(hname, &buf);
927  cat_s2Buffer (":", &buf);
928  cat_s2Buffer (num, &buf);
929 
930  set_protocol_header(pl, (char*)"Host", (char*)buf.buf, 1, ON);
931 
932  free_Buffer(&buf);
933  return;
934 }
935 
936 
942 void dump_http_header(FILE* fp, tList* pp)
943 {
944  if (fp==NULL) fp = stderr;
945 
946  if (pp!=NULL) {
947  int image = FALSE;
948  while(pp!=NULL) {
949  tList_data ld = pp->ldat;
950  if (!strcasecmp((const char*)ld.key.buf, "Content-Type")) {
951  if (!strncasecmp((const char*)ld.val.buf, "image", 5)) image = TRUE;
952  //else if (!strncasecmp((unsigned char*)ld.val.buf, "xxxx", 5)) image = TRUE;
953  }
954 
955  if (!strcasecmp((const char*)ld.key.buf, HDLIST_CONTENTS_KEY) && image==TRUE) {
956  fprintf(fp, "[%d] [%d] [%s] [%d]\n", ld.id, ld.lv, ld.key.buf, ld.val.vldsz);
957  fdump(fp, (unsigned char*)ld.val.buf, ld.val.vldsz);
958  }
959  else {
960  fprintf(fp, "[%d] [%d] [%s] [%s]\n", ld.id, ld.lv, ld.key.buf, ld.val.buf);
961  }
962  pp = pp->next;
963  }
964  }
965  else {
966  fprintf(fp, "(List is NULL)\n");
967  }
968  return;
969 }
970 
971 
981 int get_chunked_size(char* ptr, int* hdsz, int* tlsz)
982 {
983  int ck = 0, hd = 0, tl = 0;
984  char hex[L_32];
985 
986  int i = 0;
987  while (ptr[i]!=0x0d && i<L_32) {
988  hex[i] = ptr[i];
989  i++;
990  }
991  if (i==L_32) {
992  if (hdsz!=NULL) *hdsz = 0;
993  if (tlsz!=NULL) *tlsz = 0;
994  return -1;
995  }
996 
997  if (ptr[i+1]==0x0a) hd = i + 2;
998  else hd = i + 1;
999  if (hdsz!=NULL) *hdsz = hd;
1000 
1001  hex[i] = '\0';
1002  ck = hexstr2i(hex);
1003 
1004  if (ptr[ck+hd]==0x0d) {
1005  tl++;
1006  if (ptr[ck+hd+tl]==0x0a) tl++;
1007  }
1008  if (tlsz!=NULL) *tlsz = tl;
1009 
1010  return ck;
1011 }
1012 
1013 
1014 // need free()
1015 char* get_http_header_date(time_t date)
1016 {
1017  char* buf = get_gmt_timestamp(date, "%a, %d %b %Y %H:%M:%S %Z");
1018 
1019  return buf;
1020 }
1021 
1022 
1023 
1025 // HTTP Simple Proxy
1026 //
1027 
1044 void simple_web_proxy(int bofd, char* myip, int tmout)
1045 {
1046  int wofd = 0;
1047  int len, nd, cc, state;
1048  int btm, wtm, keep;
1049  char* ipa;
1050  tList* pl;
1051 
1052  unsigned short sport = 0;
1053  Buffer server, com;
1054 
1055  fd_set mask;
1056  struct timeval timeout;
1057 
1058  //DEBUG_MODE PRINT_MESG("[%d] SIMPLE_WEB_PROXY: Start Simple WEB Proxy.\n", (int)getpid());
1059 
1060  //init_rand();
1061  if (tmout<0) tmout = HTTP_PROXY_TIMEOUT;
1062  btm = wtm = tmout;
1063  keep = TRUE;
1064 
1065  do {
1066  timeout.tv_sec = btm*10;
1067  timeout.tv_usec = 0;
1068  FD_ZERO(&mask);
1069  FD_SET(bofd, &mask);
1070  nd = select(bofd+1, &mask, NULL, NULL, &timeout);
1071  } while (nd<0);
1072 
1073  while (FD_ISSET(bofd, &mask) && keep) {
1074  cc = recv_http_header(bofd, &pl, &len, tmout, NULL, &state);
1075  if (cc<=0) break;
1076  if (pl==NULL) break;
1077 
1078  /*
1079  DEBUG_MODE {
1080  PRINT_MESG("[%d] --- Web Proxy Request ---\n", getpid());
1081  print_tList(stderr, pl);
1082  PRINT_MESG("\n");
1083  }*/
1084 
1085  com = http_proxy_header_analyze(pl, &server, &sport, &btm, &keep);
1086  if (btm==0) btm = tmout;
1087  else btm = Min(btm, 60);
1088 
1089  wofd = 0;
1090  if (server.buf!=NULL && sport!=0) {
1091  ipa = get_ipaddr_byname((char*)server.buf, AF_INET);
1092  if (ipa!=NULL && !strcmp(ipa, myip)) {
1093  free_Buffer(&server);
1094  server = make_Buffer_bystr("127.0.0.1");
1095  }
1096  freeNull(ipa);
1097 
1098  wofd = tcp_client_socket((char*)server.buf, sport);
1099  free_Buffer(&server);
1100  }
1101 
1102  if (wofd<=0) {
1103  free_Buffer(&com);
1104  del_tList(&pl);
1105  break;
1106  }
1107 
1108  // for HTTPS
1109  if (com.buf!=NULL && !strcasecmp((char*)com.buf, "CONNECT")) {
1110  cc = tcp_send(bofd, (char*)"HTTP/1.1 200 Connection established.\r\nProxy-Connection: close\r\n\r\n", 0);
1111  cc = tcp_relay(bofd, wofd, 5);
1112 
1113  del_tList(&pl);
1114  free_Buffer(&com);
1115  break;
1116  }
1117  free_Buffer(&com);
1118 
1119  cc = send_http_header(wofd, pl, ON);
1120  if (cc<len && state) {
1122  cc = recv_http_content(bofd, &buf, len-cc, wtm, NULL, &state);
1123  if (cc<=0) {
1124  del_tList(&pl);
1125  break;
1126  }
1127 
1128  tcp_send_Buffer(wofd, &buf);
1129  free_Buffer(&buf);
1130  }
1131  del_tList(&pl);
1132 
1133  cc = www2browser_relay(bofd, wofd, btm, wtm, keep);
1134  if (cc<=0) break;
1135 
1136  do {
1137  timeout.tv_sec = btm;
1138  timeout.tv_usec = 0;
1139  FD_ZERO(&mask);
1140  FD_SET(bofd, &mask);
1141  nd = select(bofd+1, &mask, NULL, NULL, &timeout);
1142  } while (nd<0);
1143  }
1144 
1145  socket_close(wofd);
1146 
1147  return;
1148 }
1149 
1150 
1164 Buffer http_proxy_header_analyze(tList* pl, Buffer* server, unsigned short* sport, int* timeout, int* keep)
1165 {
1166  tList* frst;
1167  tList* lst;
1168  Buffer cmnd, url, ptcl;
1169  Buffer srvdir, bufport;
1170 
1171  cmnd = init_Buffer();
1172  srvdir = init_Buffer();
1173  *server = init_Buffer();
1174  *sport = 0;
1175  *timeout = 0;
1176  *keep = FALSE;
1177 
1178  frst = strncasecmp_tList(pl, (char*)HDLIST_FIRST_LINE_KEY, 0, 1);
1179  if (frst!=NULL) {
1180  cmnd = cawk_Buffer(frst->ldat.val, ' ', 1);
1181  url = cawk_Buffer(frst->ldat.val, ' ', 2);
1182  ptcl = cawk_Buffer(frst->ldat.val, ' ', 3);
1183  decomp_url(url, NULL, NULL, server, sport, &srvdir);
1184  }
1185  else return cmnd;
1186 
1187  if (server->buf==NULL) {
1188  lst = strncasecmp_tList(pl, (char*)"Host", 0, 1);
1189  if (lst!=NULL) {
1190  *server = cawk_Buffer(lst->ldat.val, ':', 1);
1191  bufport = cawk_Buffer(lst->ldat.val, ':', 2);
1192  if (bufport.buf!=NULL) *sport = atoi((char*)bufport.buf);
1193  free_Buffer(&bufport);
1194  }
1195  }
1196  if (*sport==0) *sport = 80;
1197 
1198  lst = strncasecmp_tList(pl, (char*)"Keep-Alive", 0, 1);
1199  if (lst!=NULL) {
1200  if (lst->ldat.val.buf!=NULL) *timeout = atoi((char*)(lst->ldat.val.buf));
1201  del_tList_node(&lst);
1202  }
1203 
1204  lst = strncasecmp_tList(pl, (char*)"Proxy-Connection", 0, 1);
1205  if (lst!=NULL) {
1206  if (!strcasecmp((char*)(lst->ldat.val.buf), "keep-alive")) *keep = TRUE;
1207  del_tList_node(&lst);
1208  }
1209 
1210  free_Buffer(&(frst->ldat.val));
1211  copy_Buffer (&cmnd, &(frst->ldat.val));
1212  cat_s2Buffer(" ", &(frst->ldat.val));
1213  cat_Buffer (&srvdir, &(frst->ldat.val));
1214  cat_s2Buffer(" ", &(frst->ldat.val));
1215  cat_Buffer (&ptcl, &(frst->ldat.val));
1216 
1217  free_Buffer(&url);
1218  free_Buffer(&ptcl);
1219  free_Buffer(&srvdir);
1220 
1221  return cmnd;
1222 }
1223 
1224 
1240 int www2browser_relay(int bofd, int wofd, int btm, int wtm, int keep)
1241 {
1242  int len, cc, cx, sz, tout, state;
1243  Buffer buf;
1244  tList* pl;
1245  tList* lst;
1246 
1247  if (!recv_wait(wofd, wtm*10)) return JBXL_NET_RECV_TIMEOUT;
1248  cc = recv_http_header(wofd, &pl, &len, wtm, NULL, &state);
1249  if (cc<=0) {
1250  if (pl!=NULL) del_tList(&pl);
1251  return cc;
1252  }
1253  if (pl==NULL) return JBXL_NET_RECV_ERROR;
1254 
1255  /*
1256  DEBUG_MODE {
1257  PRINT_MESG("[%d] --- Web Proxy Response --\n", getpid());
1258  print_tList(stderr, pl);
1259  PRINT_MESG("\n");
1260  }*/
1261 
1262  lst = strncasecmp_tList(pl, (char*)HDLIST_END_KEY, 0, 1);
1263  if (lst!=NULL && lst->prev!=NULL) {
1264  if (keep) {
1265  char pxcn[48];
1266  snprintf(pxcn, 46, "keep-alive, timeout=%d", btm);
1267  add_tList_node_str(lst->prev, "Proxy-Connection", pxcn);
1268  }
1269  else {
1270  add_tList_node_str(lst->prev, "Proxy-Connection", "close");
1271  }
1272  }
1273 
1274  sz = cx = send_http_header(bofd, pl, ON);
1275  del_tList(&pl);
1276 
1277  if (len>0) {
1279  while(sz<len) {
1280  if (!recv_wait(wofd, wtm)) {
1281  free_Buffer(&buf);
1282  return JBXL_NET_RECV_TIMEOUT;
1283  }
1284  cc = tcp_recv_Buffer(wofd, &buf);
1285  if (cc>0) {
1286  sz += cc;
1287  cx = tcp_send_Buffer(bofd, &buf);
1288  if (cx<=0) break;
1289  }
1290  else break;
1291  }
1292 
1293  free_Buffer(&buf);
1294  if (cc<=0 || (cc>0&&cx<=0)) return 0;
1295  }
1296 
1299  while ((tout=recv_wait(wofd, 1))){
1300  cc = tcp_recv_Buffer(wofd, &buf);
1301  if (cc>0) {
1302  sz += cc;
1303  cx = tcp_send_Buffer(bofd, &buf);
1304  if (cx<=0) break;
1305  }
1306  else break;
1307  }
1308 
1309  free_Buffer(&buf);
1310  if (!tout) return JBXL_NET_RECV_TIMEOUT;
1311  return 0;
1312  }
1313 
1314  return sz;
1315 }
1316 
1317 
1318 
1320 // Alternative Tools
1321 //
1322 
1336 int tcp_relay(int sofd, int cofd, int tm)
1337 {
1338  int num, nd, cx, cc = JBXL_NET_RECV_TIMEOUT;
1339  Buffer buf;
1340  fd_set mask;
1341  struct timeval timeout;
1342 
1344  num = Max(sofd, cofd);
1345 
1346  do {
1347  timeout.tv_sec = tm;
1348  timeout.tv_usec = 0;
1349  FD_ZERO(&mask);
1350  FD_SET(sofd, &mask);
1351  FD_SET(cofd, &mask);
1352  nd = select(num+1, &mask, NULL, NULL, &timeout);
1353  } while (nd<0);
1354 
1355  //while (FD_ISSET(cofd, &mask) || FD_ISSET(sofd, &mask)) {
1356  while (nd>0 && (FD_ISSET(cofd, &mask) || FD_ISSET(sofd, &mask))) {
1357 
1358  if (FD_ISSET(cofd, &mask)) {
1359  cc = tcp_recv_Buffer(cofd, &buf);
1360  if (cc>0) {
1361  cx = tcp_send_Buffer(sofd, &buf);
1362  if (cx<=0) {
1363  cc = cx;
1364  break;
1365  }
1366  }
1367  else break;
1368  //memset(buf.buf, 0, cc);
1369  }
1370 
1371  if (FD_ISSET(sofd, &mask)) {
1372  cc = tcp_recv_Buffer(sofd, &buf);
1373  if (cc>0) {
1374  cx = tcp_send_Buffer(cofd, &buf);
1375  if (cx<=0) {
1376  cc = cx;
1377  break;
1378  }
1379  }
1380  else break;
1381  //memset(buf.buf, 0, cc);
1382  }
1383 
1384  do {
1385  timeout.tv_sec = tm;
1386  timeout.tv_usec = 0;
1387  FD_ZERO(&mask);
1388  FD_SET(sofd, &mask);
1389  FD_SET(cofd, &mask);
1390  nd = select(num+1, &mask, NULL, NULL, &timeout);
1391  } while (nd<0);
1392  }
1393 
1394  free_Buffer(&buf);
1395 
1396  if (!FD_ISSET(cofd, &mask) && !FD_ISSET(sofd, &mask)) return JBXL_NET_RECV_TIMEOUT;
1397  return cc;
1398 }
1399 
1400 
1402 {
1403  int pnum = 0;
1404 
1406  if (dat.buf!=NULL) {
1407  if (!strncasecmp((const char*)dat.buf, "HTTP/", 5)) {
1408  Buffer num = cawk_Buffer(dat, ' ', 2);
1409  if (num.buf!=NULL) {
1410  pnum = atoi((const char*)num.buf);
1411  free_Buffer(&num);
1412  }
1413  }
1414  free_Buffer(&dat);
1415  }
1416 
1417  return pnum;
1418 }
1419 
1420 
1422 {
1423  float ver = 0.0;
1424 
1426  if (dat.buf!=NULL) {
1427  if (!strncasecmp((const char*)dat.buf, "HTTP/", 5)) {
1428  Buffer num = cawk_Buffer(dat, ' ', 1);
1429  if (num.buf!=NULL) {
1430  ver = (float)atof((char*)&num.buf[5]);
1431  free_Buffer(&num);
1432  }
1433  }
1434  else {
1435  Buffer buf = cawk_Buffer(dat, ' ', 3);
1436  if (!strncasecmp((const char*)buf.buf, "HTTP/", 5)) {
1437  Buffer num = cawk_Buffer(buf, ' ', 1);
1438  if (num.buf!=NULL) {
1439  ver = (float)atof((char*)&num.buf[5]);
1440  free_Buffer(&num);
1441  }
1442  }
1443  free_Buffer(&buf);
1444  }
1445  free_Buffer(&dat);
1446  }
1447 
1448  return ver;
1449 }
1450 
1451 
1452 
1454 // Server Side Code (Junk)
1455 //
1456 
1457 int send_http_res_file(int sofd, char* fname, int mode)
1458 {
1459  int sz;
1460  FILE* fp;
1461  char buf[LBUF];
1462  char* html;
1463  size_t rs;
1464  UNUSED(rs);
1465 
1466  sz = file_size(fname);
1467  if (sz<=0) {
1468  sz = 0;
1469  mode = HTTP_CONNECTION_CLOSE;
1470  }
1471 
1472  tcp_send(sofd, (char*)"HTTP/1.1 200 OK\r\n", 0);
1473  tcp_send(sofd, (char*)"Accept-Ranges: bytes\r\n", 0);
1474  tcp_send(sofd, (char*)"Pragma: no-cache\r\n", 0);
1475  tcp_send(sofd, (char*)"Cache-Control: no-cache\r\n", 0);
1476  memset(buf, 0, LBUF);
1477  snprintf(buf, LBUF-2, "Content-Length: %d\r\n", sz);
1478  tcp_send(sofd, buf, 0);
1479  if (mode==HTTP_CONNECTION_CLOSE) tcp_send(sofd, (char*)"Connection: Close\r\n", 0);
1480  else {
1481  tcp_send(sofd, (char*)"Keep-Alive: timeout=1800, max=100\r\n", 0);
1482  tcp_send(sofd, (char*)"Connection: Keep-Alive\r\n", 0);
1483  }
1484  tcp_send(sofd, (char*)"\r\n", 0);
1485 
1486  if (sz!=0) fp = fopen(fname, "rb");
1487  else fp = NULL;
1488  if (fp==NULL) return JBXL_FILE_OPEN_ERROR;
1489 
1490  html = (char*)malloc(sz);
1491  if (html==NULL) {
1492  fclose(fp);
1493  return JBXL_MALLOC_ERROR;
1494  }
1495  memset(html, 0, sz);
1496 
1497  rs = fread(html, sz, 1, fp);
1498  tcp_send(sofd, html, sz);
1499  fclose(fp);
1500 
1501  free(html);
1502  return sz;
1503 }
1504 
1505 
1506 void send_http_passwd_req(int sofd)
1507 {
1508  tcp_send(sofd, (char*)"HTTP/1.1 401 Authorization Required\r\n", 0);
1509  tcp_send(sofd, (char*)"WWW-Authenticate: Basic realm=\"TTS\"\r\n", 0);
1510  tcp_send(sofd, (char*)"Pragma: no-cache\r\n", 0);
1511  tcp_send(sofd, (char*)"Cache-Control: no-cache\r\n", 0);
1512  tcp_send(sofd, (char*)"Connection: Close\r\n", 0);
1513  tcp_send(sofd, (char*)"Content-Length: 0\r\n", 0);
1514  tcp_send(sofd, (char*)"Content-Type: text/html\r\n\r\n", 0);
1515 
1516  return;
1517 }
1518 
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
Definition: buffer.c:71
int cat_b2Buffer(void *src, Buffer *dst, int len)
任意のバイナリデータsrcを Buffer型変数dstへ lenバイト catする.
Definition: buffer.c:585
void clear_Buffer(Buffer *str)
Buffer型変数 のバッファ部を 0クリアする.
Definition: buffer.c:272
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition: buffer.c:128
Buffer init_Buffer()
初期化したBuffer型変数を返す.
Definition: buffer.c:47
Buffer dup_Buffer(Buffer buf)
Buffer型変数のコピーをつくる.
Definition: buffer.c:211
int copy_i2Buffer(int src, Buffer *dst)
整数 srcを文字列に変換して,dstへ copyする.
Definition: buffer.c:664
int cat_Buffer(Buffer *src, Buffer *dst)
Buffer変数 srcから dstへバッファを catする.
Definition: buffer.c:384
int copy_Buffer(Buffer *src, Buffer *dst)
Buffer型変数 srcから dstへバッファをコピーする.
Definition: buffer.c:315
Buffer cawk_Buffer(Buffer str, char cc, int n)
Buffer文字列に対する(変形の)awk.
Definition: buffer.c:1094
#define copy_s2Buffer(src, dst)
copy_b2Buffer()
Definition: buffer.h:108
#define make_Buffer_str(str)
set_Buffer()
Definition: buffer.h:61
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
Definition: buffer.h:122
#define make_Buffer_bystr(str)
set_Buffer()
Definition: buffer.h:57
#define Min(x, y)
Definition: common.h:250
#define OFF
Definition: common.h:231
#define Loop
Definition: common.h:256
#define Max(x, y)
Definition: common.h:247
#define L_32
Definition: common.h:161
#define RECVBUFSZ
256K
Definition: common.h:134
#define UNUSED(x)
Definition: common.h:264
#define LBUF
Definition: common.h:146
#define TRUE
Definition: common.h:226
#define FALSE
Definition: common.h:223
#define LEN_INT
log 2^64 + '\0' + 1(予備)
Definition: common.h:171
#define WORK_FILENAME_LEN
Definition: common.h:179
#define ON
Definition: common.h:230
int gz_decode_file_replace(const char *fn, const char *tempdir)
ファイル名による ファイルの解凍.ファイルを置き換える.
Definition: gz_tool.c:358
int send_http_header(int sofd, tList *pp, int mode)
Definition: http_tool.c:56
Buffer rebuild_http_Buffer(tList *pl, Buffer *buf)
Definition: http_tool.c:74
int send_http_res_file(int sofd, char *fname, int mode)
Definition: http_tool.c:1457
int get_http_header_method(tList *pl)
Definition: http_tool.c:898
int get_chunked_size(char *ptr, int *hdsz, int *tlsz)
Definition: http_tool.c:981
int recv_http_chunked(int sofd, Buffer *buf, int tm, FILE *fp, int *state)
Definition: http_tool.c:410
int tcp_relay(int sofd, int cofd, int tm)
Definition: http_tool.c:1336
void dump_http_header(FILE *fp, tList *pp)
Definition: http_tool.c:942
void simple_web_proxy(int bofd, char *myip, int tmout)
Definition: http_tool.c:1044
int get_http_method(char *data)
Definition: http_tool.c:837
int recv_http_chunked_remain(int sofd, Buffer *buf, int chnksz, int tm)
Definition: http_tool.c:489
int save_http_xml(int cofd, tList **pl, tXML **xml, char **recvfn, const char *wdir, int timeout, int *state)
Definition: http_tool.c:797
int send_http_file(int sofd, tList *pl, const char *fname)
Definition: http_tool.c:163
int recv_http_header(int sofd, tList **pl, int *len, int tm, FILE *fp, int *state)
Definition: http_tool.c:240
int is_http_header_field(tList *pl, char *field, char *value, int n)
Definition: http_tool.c:877
Buffer http_proxy_header_analyze(tList *pl, Buffer *server, unsigned short *sport, int *timeout, int *keep)
Definition: http_tool.c:1164
int recv_http_content(int sofd, Buffer *buf, int len, int tm, FILE *fp, int *state)
Definition: http_tool.c:361
int send_http_Buffer(int sofd, tList *pl, Buffer *buf)
Definition: http_tool.c:116
float get_http_version_num(tList *pl)
Definition: http_tool.c:1421
int recv_http_closed(int sofd, Buffer *buf, int tm, FILE *fp)
Definition: http_tool.c:529
void set_http_host_header(tList *pl, char *hname, unsigned short hport)
Definition: http_tool.c:917
int recv_http_Buffer(int sofd, tList **pl, Buffer *buf, int tsecond, int *hdonly, int *state, int nochunk)
Definition: http_tool.c:577
int recv_http_file(int sofd, tList **pl, const char *fname, const char *wdir, int tsecond, int *hdonly, int *state)
Definition: http_tool.c:667
int get_http_status_num(tList *pl)
Definition: http_tool.c:1401
void send_http_passwd_req(int sofd)
Definition: http_tool.c:1506
char * get_http_header_date(time_t date)
Definition: http_tool.c:1015
int www2browser_relay(int bofd, int wofd, int btm, int wtm, int keep)
Definition: http_tool.c:1240
HTTP ツールライブラリ ヘッダ
#define HTTP_MOVE_METHOD
Definition: http_tool.h:51
#define HTTP_HEADER_CHUNKED
Definition: http_tool.h:26
#define HTTP_PROPFIND_METHOD
Definition: http_tool.h:47
#define HTTP_CONNECTION_CLOSE
Definition: http_tool.h:22
#define HTTP_OPTIONS_METHOD
Definition: http_tool.h:38
#define HTTP_POST_METHOD
Definition: http_tool.h:36
#define HTTP_RESPONSE_METHOD
Definition: http_tool.h:55
#define HTTP_LOCK_METHOD
Definition: http_tool.h:52
#define HTTP_HEADER_CLOSED_SESSION
Definition: http_tool.h:25
#define HTTP_PATCH_METHOD
Definition: http_tool.h:42
#define HTTP_MKCOL_METHOD
Definition: http_tool.h:49
#define HTTP_TRACE_METHOD
Definition: http_tool.h:40
#define HTTP_UNLOCK_METHOD
Definition: http_tool.h:53
#define HTTP_PUT_METHOD
Definition: http_tool.h:35
#define HTTP_PROXY_TIMEOUT
Definition: http_tool.h:59
#define HTTP_DELETE_METHOD
Definition: http_tool.h:37
#define HTTP_GET_METHOD
Definition: http_tool.h:34
#define HTTP_UNLINK_METHOD
Definition: http_tool.h:44
#define HTTP_UNKNOWN_METHOD
0 固定.これ以下はエラーとする.
Definition: http_tool.h:31
#define HTTP_HEAD_METHOD
Definition: http_tool.h:39
#define HTTP_CONNECT_METHOD
Definition: http_tool.h:41
#define HTTP_HEADER_NOT_HTTP
Definition: http_tool.h:24
#define HTTP_COPY_METHOD
Definition: http_tool.h:50
#define HTTP_LINK_METHOD
Definition: http_tool.h:43
#define HTTP_PROPPATCH_METHOD
Definition: http_tool.h:48
#define HTTP_HEADER_UNKNOWN_LEN
Definition: http_tool.h:27
#define JBXL_ARGS_ERROR
不正な引数(NULLなど)
Definition: jbxl_state.h:42
#define JBXL_NET_RECV_ERROR
データの受信エラー
Definition: jbxl_state.h:70
#define JBXL_MALLOC_ERROR
メモリ確保エラー
Definition: jbxl_state.h:41
#define JBXL_FILE_OPEN_ERROR
ファイルオープン エラー
Definition: jbxl_state.h:44
#define JBXL_NET_RECV_TIMEOUT
受信タイムアウト
Definition: jbxl_state.h:76
unsigned char ** buf
Definition: jpeg_tool.h:96
unsigned char unsigned long * len
Definition: jpeg_tool.h:96
int tcp_send(int sock, char *smsg, int size)
Definition: network.c:1252
int socket_close(int sofd)
call shutdown(), close()
Definition: network.c:1022
char * get_ipaddr_byname(const char *hostname, int family)
ホスト名 → IPv4/IPv6 アドレス(文字列)
Definition: network.c:1781
int recv_wait(int sock, int tm)
Definition: network.c:1443
#define tcp_client_socket(h, p)
Definition: network.h:130
Buffer search_protocol_header(tList *list, char *key, int no)
Definition: protocol.c:372
int set_protocol_header(tList *list, char *key, char *value, int no, int add_mode)
Definition: protocol.c:574
tList * get_protocol_header_list_seq(tList *lp, Buffer buf, char deli, int fstline, int rcntnt)
Definition: protocol.c:181
Buffer restore_protocol_header(tList *list, char *deli, int mode, int *hdsz)
Definition: protocol.c:55
#define delete_protocol_header(p, k, n)
Definition: protocol.h:54
#define HDLIST_CONTENTS_KEY
Definition: protocol.h:32
#define HDLIST_END_KEY
Definition: protocol.h:34
#define HDLIST_FIRST_LINE_KEY
Definition: protocol.h:31
#define add_protocol_header(p, k, v)
Definition: protocol.h:51
Definition: buffer.h:35
int vldsz
データの長さ.バイナリデータの場合も使用可能.文字列の場合は 0x00 を含まない.
Definition: buffer.h:37
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition: buffer.h:39
tList * strncasecmp_tList(tList *pl, const char *key, int len, int no)
char* 型変数によるノードのサーチ.大文字小文字を無視する
Definition: tlist.c:1094
tList * del_tList_node(tList **node)
リスト用のノードを削除.
Definition: tlist.c:270
tList * del_tList(tList **pp)
指定したリストノード以降のリストを削除.
Definition: tlist.c:735
tList * find_tList_top(tList *pl)
リストの最初のノードを探す.
Definition: tlist.c:1002
#define add_tList_node_Buffer(p, k, v)
add_tList_node_byBuffer()
Definition: tlist.h:144
#define add_tList_node_str(p, k, v)
add_tList_node_bystr()
Definition: tlist.h:142
unsigned long int file_size(const char *fn)
ファイルの大きさを返す.
Definition: tools.c:2309
void fdump(FILE *fp, unsigned char *mesg, int n)
16進ダンプを吐き出す
Definition: tools.c:4177
char * get_gmt_timestamp(time_t date, const char *format)
要 free()
Definition: tools.c:454
char * itostr_ts(int n)
int を文字に変換する.要 free()
Definition: tools.c:1532
char * temp_filename(const char *dir, int flen)
/dev/urandom を利用して作業用ファイルのランダムなファイル名を得る.
Definition: tools.c:2397
int hexstr2i(const char *str)
16進の文字列を整数に変換する.
Definition: tools.c:1706
#define ex_strcmp(a, b)
文字列 aの長さに合わせて比較する.大文字小文字を区別しない.一致するなら TRUE
Definition: tools.h:283
#define freeNull(p)
Definition: tools.h:201
#define PRINT_MESG
環境依存用の出力関数.print_message()
Definition: tools.h:475
#define DEBUG_MODE
Definition: tools.h:502
tXML * xml_parse_file(const char *fn)
ファイルから読み込んでパースする.
Definition: txml.c:94
#define del_all_xml(p)
XMLツリーの全ノードの削除.ポインタ ppのノードを含むXMLツリー全体を削除する.
Definition: txml.h:205
int tcp_send_Buffer(int sock, Buffer *str)
TCP経由でデータを送信する.
Definition: xtools.c:305
int tcp_recv_Buffer(int sock, Buffer *str)
TCP経由でデータを受信する.バッファリングなし.
Definition: xtools.c:276
int decomp_url(Buffer url, Buffer *srvurl, Buffer *protocol, Buffer *srvfqdn, unsigned short *sport, Buffer *srvdir)
URLを分解する.
Definition: xtools.c:807
int tcp_recv_Buffer_wait(int sock, Buffer *str, int tm)
TCP経由でデータを受信する.待ち時間(タイムアウト)を指定できる.
Definition: xtools.c:370