Changeset 5830
- Timestamp:
- 03/15/10 22:01:46 (3 years ago)
- Location:
- luci2
- Files:
-
- 2 added
- 1 removed
- 7 modified
-
libubox/uhtbl.c (modified) (1 diff)
-
libubox/uhtbl.h (modified) (1 diff)
-
upsd/Makefile (modified) (1 diff)
-
zhttpd/cbi2 (deleted)
-
zhttpd/env.c (added)
-
zhttpd/env.h (added)
-
zhttpd/Makefile (modified) (2 diffs)
-
zhttpd/tcp.c (modified) (4 diffs)
-
zhttpd/zhttpd.c (modified) (4 diffs)
-
zhttpd/zhttpd.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
luci2/libubox/uhtbl.c
r5825 r5830 158 158 } 159 159 160 UHTBL_API int uhtbl_unset(uhtbl_t *tbl, void *key, long len) {160 UHTBL_API int uhtbl_unset(uhtbl_t *tbl, const void *key, long len) { 161 161 uhtbl_bucket_t *prev = NULL; 162 162 uhtbl_bucket_t *bucket = _uhtbl_find(tbl, key, len, &prev, NULL); -
luci2/libubox/uhtbl.h
r5825 r5830 282 282 * Returns 0 on success or a negative error code if there was no matching bucket 283 283 */ 284 UHTBL_API int uhtbl_unset(uhtbl_t *tbl, void *key, long len);284 UHTBL_API int uhtbl_unset(uhtbl_t *tbl, const void *key, long len); 285 285 286 286 /** -
luci2/upsd/Makefile
r5829 r5830 15 15 LIBFLAGS+=-DUPSD_STANDALONE 16 16 else 17 LIBFLAGS+=-lubox 17 LIBFLAGS+=-lubox -luci 18 18 endif 19 19 -
luci2/zhttpd/Makefile
r5793 r5830 3 3 WFLAGS:=-Wall -Werror -pedantic 4 4 LDFLAGS?= 5 LDFLAGS+= 5 LDFLAGS+=-lmbox -luci 6 6 BINARY:=zhttpd 7 LIBRsRY:=libupsd.so8 7 9 8 ifeq ($(ZHTTPD_TLS),cyassl) … … 17 16 all: $(BINARY) 18 17 19 $(BINARY): *.c cbi2/*.c20 $(CC) $(CFLAGS) $(SFLAGS) $(WFLAGS) $(LDFLAGS) - o $@ $+18 $(BINARY): *.c 19 $(CC) $(CFLAGS) $(SFLAGS) $(WFLAGS) $(LDFLAGS) -I.. -o $@ $+ 21 20 22 21 clean: -
luci2/zhttpd/tcp.c
r5793 r5830 13 13 #include <arpa/inet.h> 14 14 15 #include "cbi2/hmapx.h"16 15 #include "zthread.h" 17 16 #include "zhttpd.h" 18 17 #include "tcp.h" 18 #include "env.h" 19 19 20 20 … … 42 42 43 43 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 } 49 49 zhttpd_tcp_cloexec(client); 50 50 zhttpd_tcp_blocking(client, 0); … … 76 76 if (ia.sa.sa_family == AF_INET) { 77 77 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)); 80 80 } else if (ia.sa.sa_family == AF_INET6) { 81 81 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)); 84 84 } 85 85 … … 89 89 if (ia.sa.sa_family == AF_INET) { 90 90 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)); 93 93 } else if (ia.sa.sa_family == AF_INET6) { 94 94 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)); 97 97 } 98 98 99 99 zthread_spawn(zhttpd.threadpool, state, zhttpd_tcp_shutdown, req); 100 100 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;109 101 } 110 102 111 103 int zhttpd_tcp_shutdown(zthread_t *thread) { 112 104 zhttpd_request_t *request = thread->context; 113 cbi2_hmap_unreference(request->env);105 uhtbl_finalize(&request->env); 114 106 if (request->handlergc) { 115 107 request->handlergc(request->handlercontext); -
luci2/zhttpd/zhttpd.c
r5793 r5830 3 3 #include <string.h> 4 4 #include <unistd.h> 5 #include <stdio.h> 5 6 #include <sys/epoll.h> 6 7 #include <sys/types.h> … … 15 16 16 17 static void daemonize() { 17 switch (fork()) { 18 pid_t pid; 19 FILE *fp; 20 switch ((pid = fork())) { 18 21 case -1: 19 22 exit(1); … … 21 24 break; 22 25 default: 26 fp = fopen(zhttpd.pidfile, "w"); 27 if (fp) { 28 fprintf(fp, "%i\n", (int)pid); 29 fclose(fp); 30 } 23 31 exit(0); 24 32 } … … 85 93 sigaction(SIGPIPE, &action, NULL); 86 94 95 zhttpd.pidfile = "/var/run/zhttpd.pid"; 87 96 int firstrun = 1; 88 97 do { -
luci2/zhttpd/zhttpd.h
r5793 r5830 9 9 #define ZHTTPD_H_ 10 10 11 #define _FILE_OFFSET_BITS 64 12 13 #include <stdint.h> 11 14 #include <stdio.h> 12 15 #include "zthread.h" 13 #include "cbi2/hmapx.h" 16 #include "libubox/uhtbl.h" 17 #include "libubox/hash.h" 14 18 15 19 #define ZHTTPD_OK 0 … … 34 38 struct zhttpd_request { 35 39 int flags; 36 cbi2_hmap_t *env;40 uhtbl_t env; 37 41 zhttpd_vfs_t *virtual; 38 42 void *handlercontext; … … 67 71 int threads; 68 72 int daemonize; 73 char *pidfile; 69 74 }; 70 75
