Changeset 33009

Show
Ignore:
Timestamp:
05/02/09 00:57:51 (4 years ago)
Author:
kawa0117
Message:

Tokyo Dystopia tdserver HEAD method updated

Location:
lang/c/tdserver/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/c/tdserver/trunk/Makefile

    r33007 r33009  
    11# tdserver 
    22 
     3TD=../tokyodystopia-0.9.11 
     4TT=../tokyotyrant-1.1.23 
     5TC=../tokyocabinet-1.4.17 
     6 
    37CC = gcc 
    4 LDENV = LD_RUN_PATH=../tokyodystopia-0.9.11:../tokyotyrant-1.1.23:../tokyocabinet-1.4.17 
    5 CPPFLAGS = -DNDEBUG -D_GNU_SOURCE=1 -I../tokyodystopia-0.9.11 -I../tokyotyrant-1.1.23 -I../tokyocabinet-1.4.17 
     8LDENV = LD_RUN_PATH=$(TD):$(TT):$(TC) 
     9CPPFLAGS = -DNDEBUG -D_GNU_SOURCE=1 -I$(TD) -I$(TT) -I$(TC) 
    610CFLAGS = -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.17 
     11LDFLAGS = -L$(TD) -L$(TT) -L$(TC) 
    812LIBS = -ltokyodystopia -ltokyotyrant -ltokyocabinet -lbz2 -lz -lpthread -lm -lc  
    913 
  • lang/c/tdserver/trunk/tdserver.c

    r33007 r33009  
    469469          int len = strlen(val); 
    470470          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"); 
    472472          tcxstrprintf(xstr, "Content-Length: %d\r\n", len); 
    473473          tcxstrprintf(xstr, "\r\n"); 
     
    500500          TCXSTR *bstr = tcxstrnew(); 
    501501          pthread_cleanup_push((void (*)(void *))tcxstrdel, bstr); 
    502           tcxstrprintf(bstr, "["); 
    503502          for(i = 0; i < rnum; i++){ 
    504503            if (i>0) tcxstrprintf(bstr, ","); 
    505504            tcxstrprintf(bstr, "%d", (int)result[i]); 
    506505          } 
    507           tcxstrprintf(bstr, "]\n"); 
     506          tcxstrprintf(bstr, "\n"); 
    508507          int len = tcxstrsize(bstr); 
    509508 
     
    566565    } 
    567566  } 
    568   if(*uri == '/') uri++; 
    569   int ksiz; 
    570   char *kbuf = tcurldecode(uri, &ksiz); 
    571   pthread_cleanup_push(free, kbuf); 
    572567  TCXSTR *xstr = tcxstrnew(); 
    573568  pthread_cleanup_push((void (*)(void *))tcxstrdel, xstr); 
     
    577572    ttservlog(g_serv, TTLOGINFO, "do_http_head: forbidden"); 
    578573  } 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"); 
    587586        tcxstrprintf(xstr, "\r\n"); 
    588587      } 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"); 
    590624        tcxstrprintf(xstr, "\r\n"); 
    591625      } 
    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 
    596627    } 
    597628  } 
     
    601632    ttservlog(g_serv, TTLOGINFO, "do_http_head: response failed"); 
    602633  } 
    603   pthread_cleanup_pop(1); 
    604   pthread_cleanup_pop(1); 
     634  pthread_cleanup_pop(1); // xstr 
    605635} 
    606636