Changeset 6193
- Timestamp:
- 05/31/10 14:45:13 (3 years ago)
- Location:
- luci2
- Files:
-
- 17 modified
-
cbi2/cbi.h (modified) (1 diff)
-
cbi2/luci_cli.c (modified) (2 diffs)
-
cbi2/Makefile (modified) (3 diffs)
-
cbi2/u_sock.c (modified) (3 diffs)
-
cbi2/widgets/luci/content.c (modified) (1 diff)
-
cbi2/widgets/luci/menu.c (modified) (2 diffs)
-
cbi2/widgets/luci/option.c (modified) (1 diff)
-
libubox/ulog.h (modified) (1 diff)
-
libubox/usock.c (modified) (3 diffs)
-
libubox/usock.h (modified) (1 diff)
-
libustream/core.c (modified) (2 diffs)
-
ubus/libubus.c (modified) (4 diffs)
-
ubus/ubus.h (modified) (1 diff)
-
ubus/ubus_core.c (modified) (2 diffs)
-
ubus/ubus_dispatch.c (modified) (1 diff)
-
ubus/ubus_msg.c (modified) (1 diff)
-
zhttpd/tcp.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
luci2/cbi2/cbi.h
r6006 r6193 12 12 #include <lmo.h> 13 13 #include "lang.h" 14 #include <libubox/hash.h> 14 15 15 16 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -
luci2/cbi2/luci_cli.c
r5791 r6193 6 6 #include <sys/types.h> 7 7 #include <sys/socket.h> 8 #include < sys/un.h>8 #include <libubox/usock.h> 9 9 10 10 #define SOCK_PATH "/tmp/luci2-socket" … … 16 16 #define MAX_SOCKET_DATA 512 17 17 int s, len; 18 struct sockaddr_un remote;19 18 char reply[4096]; 20 19 if(argc != 2) 21 20 return 1; 22 if((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) 23 { 24 perror("socket"); 25 exit(1); 26 } 21 27 22 printf("Trying to connect...\n"); 28 29 remote.sun_family = AF_UNIX; 30 strcpy(remote.sun_path, SOCK_PATH); 31 len = strlen(remote.sun_path) + sizeof(remote.sun_family); 32 if(connect(s, (struct sockaddr *)&remote, len) == -1) 23 if((s = usock(USOCK_UNIX | USOCK_TCP, SOCK_PATH, NULL)) == -1) 33 24 { 34 25 perror("connect"); -
luci2/cbi2/Makefile
r6187 r6193 3 3 CFLAGS+= --std=gnu99 -Wall -Werror -pedantic -I/usr/include/lua5.1/ 4 4 LDFLAGS?= 5 INCLUDES?=-I../libubox/ -Ilmo/ 5 INCLUDES?=-I../libubox/ -Ilmo/ -I../ 6 6 BINARY=libcbi.so luci luci_cli uvl uvlc libcbi.a luci_conf widgets/luci/_builtin.so widgets/config/_builtin.so sources/_builtin.so validator/_builtin.so 7 7 … … 30 30 31 31 luci: luci.c 32 $(CC) $(CFLAGS) $(LDFLAGS) -g -o $@ $^ -lcbi -I../libubox/ -Ilmo/-L.32 $(CC) $(CFLAGS) $(LDFLAGS) -g -o $@ $^ -lcbi $(INCLUDES) -L. 33 33 34 34 luci_conf: luci_conf.c 35 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lcbi -I../libubox/ -Ilmo/-L.35 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lcbi $(INCLUDES) -L. 36 36 37 37 libcbi.a: lucic.o parser.o json.o cbi_element.o cbi_dump.o cbi_core.o cbi_buffer.o cbi_uci.o source.o session.o u_sock.o validate.o uvl.o lang.o widget.o log.o handler.o … … 43 43 44 44 luci_cli: luci_cli.o 45 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ 45 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lubox 46 46 47 47 uvl: uvl.o uvl-cli.o -
luci2/cbi2/u_sock.c
r5816 r6193 8 8 #include <sys/types.h> 9 9 #include <sys/socket.h> 10 #include <libubox/usock.h> 10 11 11 12 #include "list.h" … … 46 47 void u_sock_init(struct cbi_ctx *ctx, const char *path) 47 48 { 48 int s, len; 49 struct sockaddr_un local; 50 49 int s; 51 50 INIT_LIST_HEAD(&ctx->sock_handlers); 52 51 53 if((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) 52 path = (path)?(path):(U_SOCK_PATH); 53 unlink(path); 54 if((s = usock(USOCK_TCP | USOCK_UNIX | USOCK_SERVER, path, NULL)) == -1) 54 55 { 55 56 perror("socket"); … … 57 58 } 58 59 59 local.sun_family = AF_UNIX;60 strcpy(local.sun_path, (path)?(path):(U_SOCK_PATH));61 unlink(local.sun_path);62 len = strlen(local.sun_path) + sizeof(local.sun_family);63 if(bind(s, (struct sockaddr *)&local, len) == -1)64 {65 close(s);66 perror("bind");67 exit(1);68 }69 70 if(listen(s, 5) == -1)71 {72 perror("listen");73 exit(1);74 }75 60 ctx->u_sock = s; 76 61 printf("Unix socket loaded %s\n", (path)?(path):(U_SOCK_PATH)); -
luci2/cbi2/widgets/luci/content.c
r6112 r6193 21 21 { 22 22 if(e->value) 23 e->lmo = sfh_hash(e->value, strlen(e->value));23 e->lmo = hash_murmur2(e->value, strlen(e->value)); 24 24 return 0; 25 25 } -
luci2/cbi2/widgets/luci/menu.c
r5781 r6193 13 13 if(!tag) 14 14 tag = cbi_prop_find(e, "id"); 15 e->lmo = sfh_hash(tag, strlen(tag));15 e->lmo = hash_murmur2(tag, strlen(tag)); 16 16 return 0; 17 17 } … … 54 54 return 1; 55 55 } 56 e->lmo = sfh_hash(e->value, strlen(e->value));56 e->lmo = hash_murmur2(e->value, strlen(e->value)); 57 57 return 0; 58 58 } -
luci2/cbi2/widgets/luci/option.c
r5780 r6193 10 10 { 11 11 if(e->value) 12 e->lmo = sfh_hash(e->value, strlen(e->value));12 e->lmo = hash_murmur2(e->value, strlen(e->value)); 13 13 return 0; 14 14 } -
luci2/libubox/ulog.h
r6190 r6193 26 26 #define LOG log_printf 27 27 #define log_start(name, daemon) \ 28 openlog(name, ( daemon) ? 0 : (LOG_PERROR | LOG_CONS), LOG_USER)29 #define log_printf(...) syslog( 10, __VA_ARGS__)28 openlog(name, (LOG_PERROR | LOG_CONS), LOG_USER) 29 #define log_printf(...) syslog(LOG_NOTICE, __VA_ARGS__) 30 30 31 31 #endif -
luci2/libubox/usock.c
r6192 r6193 14 14 int sock = -1; 15 15 16 if (service && !(type & USOCK_ FLAG_UNIX)) {16 if (service && !(type & USOCK_UNIX)) { 17 17 struct addrinfo *result, *rp; 18 18 19 19 struct addrinfo hints = { 20 .ai_family = (type & USOCK_ FLAG_IPV6ONLY) ? AF_INET6 :21 (type & USOCK_ FLAG_IPV4ONLY) ? AF_INET : AF_UNSPEC,20 .ai_family = (type & USOCK_IPV6ONLY) ? AF_INET6 : 21 (type & USOCK_IPV4ONLY) ? AF_INET : AF_UNSPEC, 22 22 .ai_socktype = ((type & 0xff) == USOCK_TCP) 23 23 ? SOCK_STREAM : SOCK_DGRAM, 24 24 .ai_flags = AI_ADDRCONFIG | 25 ((type & USOCK_ FLAG_SERVER) ? AI_PASSIVE : 0),25 ((type & USOCK_SERVER) ? AI_PASSIVE : 0), 26 26 }; 27 27 … … 36 36 } 37 37 38 if (!(type & USOCK_ FLAG_NOCLOEXEC)) {38 if (!(type & USOCK_NOCLOEXEC)) { 39 39 fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); 40 40 } 41 41 42 if (type & USOCK_ FLAG_NONBLOCK) {42 if (type & USOCK_NONBLOCK) { 43 43 fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK); 44 44 } 45 45 46 if (type & USOCK_ FLAG_SERVER) {46 if (type & USOCK_SERVER) { 47 47 const int one = 1; 48 48 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); … … 76 76 } 77 77 78 if (!(type & USOCK_ FLAG_NOCLOEXEC)) {78 if (!(type & USOCK_NOCLOEXEC)) { 79 79 fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); 80 80 } 81 81 82 if (type & USOCK_ FLAG_NONBLOCK) {82 if (type & USOCK_NONBLOCK) { 83 83 fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK); 84 84 } 85 85 86 if (type & USOCK_ FLAG_SERVER) {86 if (type & USOCK_SERVER) { 87 87 if (bind(sock, (struct sockaddr*)&sun, sizeof(sun)) || 88 88 ((type & 0xff) == USOCK_TCP && listen(sock, SOMAXCONN))) { -
luci2/libubox/usock.h
r6192 r6193 2 2 #define USOCK_H_ 3 3 4 #define USOCK_TCP 15 #define USOCK_UDP 24 #define USOCK_TCP 0 5 #define USOCK_UDP 1 6 6 7 #define USOCK_ FLAG_SERVER 0x01008 #define USOCK_ FLAG_NOCLOEXEC 0x02009 #define USOCK_ FLAG_NONBLOCK 0x040010 #define USOCK_ FLAG_IPV6ONLY 0x200011 #define USOCK_ FLAG_IPV4ONLY 0x400012 #define USOCK_ FLAG_UNIX 0x80007 #define USOCK_SERVER 0x0100 8 #define USOCK_NOCLOEXEC 0x0200 9 #define USOCK_NONBLOCK 0x0400 10 #define USOCK_IPV6ONLY 0x2000 11 #define USOCK_IPV4ONLY 0x4000 12 #define USOCK_UNIX 0x8000 13 13 14 14 int usock(int type, const char *host, const char *service); -
luci2/libustream/core.c
r6160 r6193 8 8 #include <stdlib.h> 9 9 #include <string.h> 10 #include <libubox/usock.h> 10 11 11 12 static int ustream_io_timeout = 60; … … 59 60 60 61 USTREAM_LOCAL int ustream_io_socket (const char *host, const char *service) { 61 struct addrinfo *result, *rp; 62 int sock = -1, clstat; 63 64 struct addrinfo hints = { 65 .ai_family = AF_UNSPEC, 66 .ai_socktype = SOCK_STREAM 67 }; 68 69 if (getaddrinfo(host, service, &hints, &result)) { 70 errno = ENXIO; 71 return -1; 72 } 73 74 for (rp = result; rp != NULL; rp = rp->ai_next) { 75 sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); 76 if (sock == -1) { 77 continue; 78 } 79 80 if (!connect(sock, rp->ai_addr, rp->ai_addrlen)) { 81 break; 82 } 83 84 clstat = close(sock); 85 sock = -1; 86 } 87 88 freeaddrinfo(result); 89 fcntl(sock, F_SETFD, fcntl(sock, F_GETFD) | FD_CLOEXEC); 62 int sock = usock(USOCK_TCP, host, service); 90 63 91 64 struct timeval t = {.tv_sec = ustream_io_timeout}; -
luci2/ubus/libubus.c
r6177 r6193 38 38 #include "ubus_constants.h" 39 39 #include "hash.h" 40 #include "usock.h" 40 41 41 42 struct ubus_ctx … … 258 259 int ubus_connect(struct ubus_ctx *ctx) 259 260 { 260 int s, len; 261 struct sockaddr_un remote; 261 int s; 262 262 struct pollfd p = {.fd = ctx->s, .events = POLLRDHUP | POLLHUP | POLLERR}; 263 263 if(ctx->s && !poll(&p, 1, 0)) … … 266 266 close(ctx->s); 267 267 268 if((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)268 if((s = usock(USOCK_UNIX | USOCK_TCP, UBUS_SOCK_PATH, NULL)) == -1) 269 269 { 270 270 perror("socket"); … … 272 272 } 273 273 274 remote.sun_family = AF_UNIX;275 strcpy(remote.sun_path, UBUS_SOCK_PATH);276 len = strlen(remote.sun_path) + sizeof(remote.sun_family);277 278 if(connect(s, (struct sockaddr *)&remote, len) == -1)279 {280 close(s);281 return -2;282 }283 274 ctx->s = s; 284 275 LOG("connected to ubus\n"); -
luci2/ubus/ubus.h
r5836 r6193 31 31 #include "ubus_msg.h" 32 32 #include "hash.h" 33 #include "usock.h" 33 34 34 35 struct ubus_client -
luci2/ubus/ubus_core.c
r6011 r6193 71 71 void ubus_init(const char *path) 72 72 { 73 int len,flags;73 int flags; 74 74 struct epoll_event ev; 75 struct sockaddr_un local;76 75 INIT_LIST_HEAD(&ubus_clients); 77 if((ubusfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) 76 path = (path)?(path):(UBUS_SOCK_PATH); 77 unlink(path); 78 if((ubusfd = usock(USOCK_TCP | USOCK_UNIX | USOCK_SERVER, path, NULL)) == -1) 78 79 { 79 80 perror("socket"); … … 81 82 } 82 83 83 local.sun_family = AF_UNIX;84 strcpy(local.sun_path, (path)?(path):(UBUS_SOCK_PATH));85 unlink(local.sun_path);86 len = strlen(local.sun_path) + sizeof(local.sun_family);87 if(bind(ubusfd, (struct sockaddr *)&local, len) == -1)88 {89 perror("bind");90 exit(1);91 }92 93 if(listen(ubusfd, 20) == -1)94 {95 perror("listen");96 exit(1);97 }98 84 ubus_epollfd = epoll_create(32); 99 85 flags = fcntl(ubusfd, F_GETFL, 0); -
luci2/ubus/ubus_dispatch.c
r6177 r6193 148 148 if(strcmp(ns, u->type)) 149 149 { 150 LOG("dropping, namespace mismatch\n" , u->type, ns);150 LOG("dropping, namespace mismatch\n"); //, u->type, ns); 151 151 return; 152 152 } -
luci2/ubus/ubus_msg.c
r5827 r6193 133 133 if(strlen(node) >= UBUS_MAX_NODE) 134 134 { 135 LOG("node too long %s (%d)\n", node, strlen(node));135 LOG("node too long %s (%d)\n", node, (int)strlen(node)); 136 136 return 1; 137 137 } -
luci2/zhttpd/tcp.c
r6139 r6193 33 33 #include <fcntl.h> 34 34 #include <arpa/inet.h> 35 #include <libubox/usock.h> 35 36 36 37 #include "zthread.h" … … 255 256 } 256 257 257 /* Create TCP socket */258 static int zhttpd_tcp_server_socket(const char *host, const char *service) {259 struct addrinfo *result, *rp;260 int sock = -1, clstat;261 262 struct addrinfo hints = {263 .ai_family = AF_UNSPEC,264 .ai_socktype = SOCK_STREAM,265 .ai_flags = AI_PASSIVE266 };267 268 if (getaddrinfo(host, service, &hints, &result)) {269 return -1;270 }271 272 for (rp = result; rp != NULL; rp = rp->ai_next) {273 sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);274 if (sock == -1) {275 continue;276 }277 278 int one = 1;279 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&one, sizeof(one));280 if (!bind(sock, rp->ai_addr, rp->ai_addrlen) && !listen(sock, 32)) {281 break;282 }283 284 clstat = close(sock);285 sock = -1;286 }287 288 freeaddrinfo(result);289 return sock;290 }291 292 258 293 259 /* Create and spawn listening server zthread */ 294 260 int zhttpd_tcp_server(const char *host, const char *service, 295 261 const char *tlskey, const char *tlscert, int pem) { 296 int socket = zhttpd_tcp_server_socket(host, service);262 int socket = usock(USOCK_TCP | USOCK_NONBLOCK, host, service); 297 263 if (socket == -1) { 298 264 return ZHTTPD_EIO; 299 265 } 300 fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);301 fcntl(socket, F_SETFD, fcntl(socket, F_GETFD) | FD_CLOEXEC);302 266 303 267 zhttpd_tcp_t *tcp = calloc(1, sizeof(zhttpd_tcp_t));
