Changeset 33009
- Timestamp:
- 05/02/09 00:57:51 (4 years ago)
- Location:
- lang/c/tdserver/trunk
- Files:
-
- 2 modified
-
Makefile (modified) (1 diff)
-
tdserver.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/tdserver/trunk/Makefile
r33007 r33009 1 1 # tdserver 2 2 3 TD=../tokyodystopia-0.9.11 4 TT=../tokyotyrant-1.1.23 5 TC=../tokyocabinet-1.4.17 6 3 7 CC = gcc 4 LDENV = LD_RUN_PATH= ../tokyodystopia-0.9.11:../tokyotyrant-1.1.23:../tokyocabinet-1.4.175 CPPFLAGS = -DNDEBUG -D_GNU_SOURCE=1 -I ../tokyodystopia-0.9.11 -I../tokyotyrant-1.1.23 -I../tokyocabinet-1.4.178 LDENV = LD_RUN_PATH=$(TD):$(TT):$(TC) 9 CPPFLAGS = -DNDEBUG -D_GNU_SOURCE=1 -I$(TD) -I$(TT) -I$(TC) 6 10 CFLAGS = -g -O2 -std=c99 -Wall -fPIC -fsigned-char -O2 7 LDFLAGS = -L ../tokyodystopia-0.9.11 -L../tokyotyrant-1.1.23 -L../tokyocabinet-1.4.1711 LDFLAGS = -L$(TD) -L$(TT) -L$(TC) 8 12 LIBS = -ltokyodystopia -ltokyotyrant -ltokyocabinet -lbz2 -lz -lpthread -lm -lc 9 13 -
lang/c/tdserver/trunk/tdserver.c
r33007 r33009 469 469 int len = strlen(val); 470 470 tcxstrprintf(xstr, "HTTP/1.1 200 OK\r\n"); 471 tcxstrprintf(xstr, "Content-Type: text/plain\r\n");471 tcxstrprintf(xstr, "Content-Type: application/octet-stream\r\n"); 472 472 tcxstrprintf(xstr, "Content-Length: %d\r\n", len); 473 473 tcxstrprintf(xstr, "\r\n"); … … 500 500 TCXSTR *bstr = tcxstrnew(); 501 501 pthread_cleanup_push((void (*)(void *))tcxstrdel, bstr); 502 tcxstrprintf(bstr, "[");503 502 for(i = 0; i < rnum; i++){ 504 503 if (i>0) tcxstrprintf(bstr, ","); 505 504 tcxstrprintf(bstr, "%d", (int)result[i]); 506 505 } 507 tcxstrprintf(bstr, " ]\n");506 tcxstrprintf(bstr, "\n"); 508 507 int len = tcxstrsize(bstr); 509 508 … … 566 565 } 567 566 } 568 if(*uri == '/') uri++;569 int ksiz;570 char *kbuf = tcurldecode(uri, &ksiz);571 pthread_cleanup_push(free, kbuf);572 567 TCXSTR *xstr = tcxstrnew(); 573 568 pthread_cleanup_push((void (*)(void *))tcxstrdel, xstr); … … 577 572 ttservlog(g_serv, TTLOGINFO, "do_http_head: forbidden"); 578 573 } else { 579 580 int rnum; 581 uint64_t *result = tcidbsearch2(idb, kbuf, &rnum); 582 583 if(result){ 584 if(rnum){ 585 tcxstrprintf(xstr, "HTTP/1.1 200 OK\r\n"); 586 tcxstrprintf(xstr, "Content-Type: application/octet-stream\r\n"); 574 if(*uri == '/') uri++; 575 char *query = strstr(uri, "?q="); 576 if(!query) query = strstr(uri, "&q="); 577 if(!query) { 578 579 int ksiz; 580 char *kbuf = tcurldecode(uri, &ksiz); 581 pthread_cleanup_push(free, kbuf); 582 int key = tcatoi(kbuf); 583 584 if(key < 1){ 585 tcxstrprintf(xstr, "HTTP/1.1 403 Forbidden\r\n"); 587 586 tcxstrprintf(xstr, "\r\n"); 588 587 } else { 589 tcxstrprintf(xstr, "HTTP/1.1 404 Not Found\r\n"); 588 char *val = tcidbget(idb, key); 589 if(val){ 590 tcxstrprintf(xstr, "HTTP/1.1 200 OK\r\n"); 591 tcxstrprintf(xstr, "Content-Type: application/octet-stream\r\n"); 592 tcxstrprintf(xstr, "\r\n"); 593 free(val); 594 } else { 595 tcxstrprintf(xstr, "HTTP/1.1 404 Not Found\r\n"); 596 tcxstrprintf(xstr, "\r\n"); 597 } 598 } 599 pthread_cleanup_pop(1); // kbuf 600 601 } else { 602 query += strlen("?q="); 603 char *qend = strchr(query, '&'); 604 if(qend) *qend = '\0'; 605 606 int ksiz; 607 char *kbuf = tcurldecode(query, &ksiz); 608 pthread_cleanup_push(free, kbuf); 609 int rnum; 610 uint64_t *result = tcidbsearch2(idb, kbuf, &rnum); 611 612 if(result){ 613 if(rnum){ 614 tcxstrprintf(xstr, "HTTP/1.1 200 OK\r\n"); 615 tcxstrprintf(xstr, "Content-Type: application/octet-stream\r\n"); 616 tcxstrprintf(xstr, "\r\n"); 617 } else { 618 tcxstrprintf(xstr, "HTTP/1.1 404 Not Found\r\n"); 619 tcxstrprintf(xstr, "\r\n"); 620 } 621 free(result); 622 } else { 623 tcxstrprintf(xstr, "HTTP/1.1 500 Internal Server Error\r\n"); 590 624 tcxstrprintf(xstr, "\r\n"); 591 625 } 592 free(result); 593 } else { 594 tcxstrprintf(xstr, "HTTP/1.1 500 Internal Server Error\r\n"); 595 tcxstrprintf(xstr, "\r\n"); 626 pthread_cleanup_pop(1); // kbuf 596 627 } 597 628 } … … 601 632 ttservlog(g_serv, TTLOGINFO, "do_http_head: response failed"); 602 633 } 603 pthread_cleanup_pop(1); 604 pthread_cleanup_pop(1); 634 pthread_cleanup_pop(1); // xstr 605 635 } 606 636
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)