Changeset 5830

Show
Ignore:
Timestamp:
03/15/10 22:01:46 (3 years ago)
Author:
Cyrus
Message:

zhttpd: More stuff, uhtbl: Qualifier change

Location:
luci2
Files:
2 added
1 removed
7 modified

Legend:

Unmodified
Added
Removed
  • luci2/libubox/uhtbl.c

    r5825 r5830  
    158158} 
    159159 
    160 UHTBL_API int uhtbl_unset(uhtbl_t *tbl, void *key, long len) { 
     160UHTBL_API int uhtbl_unset(uhtbl_t *tbl, const void *key, long len) { 
    161161    uhtbl_bucket_t *prev = NULL; 
    162162    uhtbl_bucket_t *bucket = _uhtbl_find(tbl, key, len, &prev, NULL); 
  • luci2/libubox/uhtbl.h

    r5825 r5830  
    282282 * Returns 0 on success or a negative error code if there was no matching bucket 
    283283 */ 
    284 UHTBL_API int uhtbl_unset(uhtbl_t *tbl, void *key, long len); 
     284UHTBL_API int uhtbl_unset(uhtbl_t *tbl, const void *key, long len); 
    285285 
    286286/** 
  • luci2/upsd/Makefile

    r5829 r5830  
    1515    LIBFLAGS+=-DUPSD_STANDALONE 
    1616else 
    17     LIBFLAGS+=-lubox 
     17    LIBFLAGS+=-lubox -luci 
    1818endif 
    1919 
  • luci2/zhttpd/Makefile

    r5793 r5830  
    33WFLAGS:=-Wall -Werror -pedantic 
    44LDFLAGS?= 
    5 LDFLAGS+= 
     5LDFLAGS+=-lmbox -luci 
    66BINARY:=zhttpd 
    7 LIBRsRY:=libupsd.so 
    87 
    98ifeq ($(ZHTTPD_TLS),cyassl) 
     
    1716all: $(BINARY) 
    1817 
    19 $(BINARY): *.c cbi2/*.c 
    20     $(CC) $(CFLAGS) $(SFLAGS) $(WFLAGS) $(LDFLAGS) -o $@ $+ 
     18$(BINARY): *.c 
     19    $(CC) $(CFLAGS) $(SFLAGS) $(WFLAGS) $(LDFLAGS) -I.. -o $@ $+ 
    2120 
    2221clean: 
  • luci2/zhttpd/tcp.c

    r5793 r5830  
    1313#include <arpa/inet.h> 
    1414 
    15 #include "cbi2/hmapx.h" 
    1615#include "zthread.h" 
    1716#include "zhttpd.h" 
    1817#include "tcp.h" 
     18#include "env.h" 
    1919 
    2020 
     
    4242 
    4343    zhttpd_request_t *req = calloc(1, sizeof(zhttpd_request_t)); 
    44     cbi2_hmap_t *env = cbi2_hmap_create(16); 
    45     if (!req || !env) { 
    46         goto error; 
    47     } 
    48     req->env = env; 
     44    if (!req || !zhttpd_env_init(&req->env, 16)) { 
     45        free(req); 
     46        close(client); 
     47        return ZTHREAD_BLOCKED; 
     48    } 
    4949    zhttpd_tcp_cloexec(client); 
    5050    zhttpd_tcp_blocking(client, 0); 
     
    7676    if (ia.sa.sa_family == AF_INET) { 
    7777        inet_ntop(AF_INET, &ia.sa_in.sin_addr, tmp, sizeof(tmp)); 
    78         cbi2_hmap_set_int(env, "REMOTE_PORT", ntohs(ia.sa_in.sin_port)); 
    79         cbi2_hmap_set_string(env, "REMOTE_ADDR", tmp); 
     78        zhttpd_env_set_int(&req->env, "REMOTE_PORT", ntohs(ia.sa_in.sin_port)); 
     79        zhttpd_env_set(&req->env, "REMOTE_ADDR", tmp, strlen(tmp)); 
    8080    } else if (ia.sa.sa_family == AF_INET6) { 
    8181        inet_ntop(AF_INET6, &ia.sa_in6.sin6_addr, tmp, sizeof(tmp)); 
    82         cbi2_hmap_set_int(env, "REMOTE_PORT", ntohs(ia.sa_in6.sin6_port)); 
    83         cbi2_hmap_set_string(env, "REMOTE_ADDR", tmp); 
     82        zhttpd_env_set_int(&req->env, "REMOTE_PORT",ntohs(ia.sa_in6.sin6_port)); 
     83        zhttpd_env_set(&req->env, "REMOTE_ADDR", tmp, strlen(tmp)); 
    8484    } 
    8585 
     
    8989    if (ia.sa.sa_family == AF_INET) { 
    9090        inet_ntop(AF_INET, &ia.sa_in.sin_addr, tmp, sizeof(tmp)); 
    91         cbi2_hmap_set_int(env, "SERVER_PORT", ntohs(ia.sa_in.sin_port)); 
    92         cbi2_hmap_set_string(env, "SERVER_ADDR", tmp); 
     91        zhttpd_env_set_int(&req->env, "SERVER_PORT", ntohs(ia.sa_in.sin_port)); 
     92        zhttpd_env_set(&req->env, "SERVER_ADDR", tmp, strlen(tmp)); 
    9393    } else if (ia.sa.sa_family == AF_INET6) { 
    9494        inet_ntop(AF_INET6, &ia.sa_in6.sin6_addr, tmp, sizeof(tmp)); 
    95         cbi2_hmap_set_int(env, "SERVER_PORT", ntohs(ia.sa_in6.sin6_port)); 
    96         cbi2_hmap_set_string(env, "SERVER_ADDR", tmp); 
     95        zhttpd_env_set_int(&req->env, "SERVER_PORT",ntohs(ia.sa_in6.sin6_port)); 
     96        zhttpd_env_set(&req->env, "SERVER_ADDR", tmp, strlen(tmp)); 
    9797    } 
    9898 
    9999    zthread_spawn(zhttpd.threadpool, state, zhttpd_tcp_shutdown, req); 
    100100    return ZTHREAD_BLOCKED; 
    101  
    102 error: 
    103     free(req); 
    104     if (env) { 
    105         cbi2_hmap_unreference(env); 
    106     } 
    107     close(client); 
    108     return ZTHREAD_BLOCKED; 
    109101} 
    110102 
    111103int zhttpd_tcp_shutdown(zthread_t *thread) { 
    112104    zhttpd_request_t *request = thread->context; 
    113     cbi2_hmap_unreference(request->env); 
     105    uhtbl_finalize(&request->env); 
    114106    if (request->handlergc) { 
    115107        request->handlergc(request->handlercontext); 
  • luci2/zhttpd/zhttpd.c

    r5793 r5830  
    33#include <string.h> 
    44#include <unistd.h> 
     5#include <stdio.h> 
    56#include <sys/epoll.h> 
    67#include <sys/types.h> 
     
    1516 
    1617static void daemonize() { 
    17     switch (fork()) { 
     18    pid_t pid; 
     19    FILE *fp; 
     20    switch ((pid = fork())) { 
    1821        case -1: 
    1922            exit(1); 
     
    2124            break; 
    2225        default: 
     26            fp = fopen(zhttpd.pidfile, "w"); 
     27            if (fp) { 
     28                fprintf(fp, "%i\n", (int)pid); 
     29                fclose(fp); 
     30            } 
    2331            exit(0); 
    2432    } 
     
    8593    sigaction(SIGPIPE, &action, NULL); 
    8694 
     95    zhttpd.pidfile = "/var/run/zhttpd.pid"; 
    8796    int firstrun = 1; 
    8897    do { 
  • luci2/zhttpd/zhttpd.h

    r5793 r5830  
    99#define ZHTTPD_H_ 
    1010 
     11#define _FILE_OFFSET_BITS 64 
     12 
     13#include <stdint.h> 
    1114#include <stdio.h> 
    1215#include "zthread.h" 
    13 #include "cbi2/hmapx.h" 
     16#include "libubox/uhtbl.h" 
     17#include "libubox/hash.h" 
    1418 
    1519#define ZHTTPD_OK       0 
     
    3438struct zhttpd_request { 
    3539    int flags; 
    36     cbi2_hmap_t *env; 
     40    uhtbl_t env; 
    3741    zhttpd_vfs_t *virtual; 
    3842    void *handlercontext; 
     
    6771    int threads; 
    6872    int daemonize; 
     73    char *pidfile; 
    6974}; 
    7075