1 /* uWSGI */ 2 3 /* indent -i8 -br -brs -brf -l0 -npsl -nip -npcs -npsl -di1 -il0 */ 4 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 #define UWSGI_PLUGIN_API 1 10 11 #define UWSGI_HAS_OFFLOAD_UBUFS 1 12 13 #define UMAX16 65536 14 #define UMAX8 256 15 16 #define UMAX64_STR "18446744073709551615" 17 #define MAX64_STR "-9223372036854775808" 18 19 #define UWSGI_END_OF_OPTIONS { NULL, 0, 0, NULL, NULL, NULL, 0}, 20 21 #define uwsgi_error(x) uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__); 22 #define uwsgi_error_realpath(x) uwsgi_log("realpath() of %s failed: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__); 23 #define uwsgi_log_safe(x) if (uwsgi.original_log_fd != 2) dup2(uwsgi.original_log_fd, 2) ; uwsgi_log(x); 24 #define uwsgi_error_safe(x) if (uwsgi.original_log_fd != 2) dup2(uwsgi.original_log_fd, 2) ; uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__); 25 #define uwsgi_log_initial if (!uwsgi.no_initial_output) uwsgi_log 26 #define uwsgi_log_alarm(x, ...) uwsgi_log("[uwsgi-alarm" x, __VA_ARGS__) 27 #define uwsgi_fatal_error(x) uwsgi_error(x); exit(1); 28 #define uwsgi_error_open(x) uwsgi_log("open(\"%s\"): %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__); 29 #define uwsgi_req_error(x) if (wsgi_req->uri_len > 0 && wsgi_req->method_len > 0 && wsgi_req->remote_addr_len > 0) uwsgi_log_verbose("%s: %s [%s line %d] during %.*s %.*s (%.*s)\n", x, strerror(errno), __FILE__, __LINE__,\ 30 wsgi_req->method_len, wsgi_req->method, wsgi_req->uri_len, wsgi_req->uri, wsgi_req->remote_addr_len, wsgi_req->remote_addr); else uwsgi_log_verbose("%s %s [%s line %d] \n",x, strerror(errno), __FILE__, __LINE__); 31 #define uwsgi_debug(x, ...) uwsgi_log("[uWSGI DEBUG] " x, __VA_ARGS__); 32 #define uwsgi_rawlog(x) if (write(2, x, strlen(x)) != strlen(x)) uwsgi_error("write()") 33 #define uwsgi_str(x) uwsgi_concat2(x, (char *)"") 34 35 #define uwsgi_notify(x) if (uwsgi.notify) uwsgi.notify(x) 36 #define uwsgi_notify_ready() uwsgi.shared->ready = 1 ; if (uwsgi.notify_ready) uwsgi.notify_ready() 37 38 #define uwsgi_apps uwsgi.workers[uwsgi.mywid].apps 39 #define uwsgi_apps_cnt uwsgi.workers[uwsgi.mywid].apps_cnt 40 41 #define wsgi_req_time ((wsgi_req->end_of_request-wsgi_req->start_of_request)/1000) 42 43 #define thunder_lock if (!uwsgi.is_et) {\ 44 if (uwsgi.use_thunder_lock) {\ 45 uwsgi_lock(uwsgi.the_thunder_lock);\ 46 }\ 47 else if (uwsgi.threads > 1) {\ 48 pthread_mutex_lock(&uwsgi.thunder_mutex);\ 49 }\ 50 } 51 52 #define thunder_unlock if (!uwsgi.is_et) {\ 53 if (uwsgi.use_thunder_lock) {\ 54 uwsgi_unlock(uwsgi.the_thunder_lock);\ 55 }\ 56 else if (uwsgi.threads > 1) {\ 57 pthread_mutex_unlock(&uwsgi.thunder_mutex);\ 58 }\ 59 } 60 61 62 #define uwsgi_n64(x) strtoul(x, NULL, 10) 63 64 #define ushared uwsgi.shared 65 66 #define UWSGI_OPT_IMMEDIATE (1 << 0) 67 #define UWSGI_OPT_MASTER (1 << 1) 68 #define UWSGI_OPT_LOG_MASTER (1 << 2) 69 #define UWSGI_OPT_THREADS (1 << 3) 70 #define UWSGI_OPT_CHEAPER (1 << 4) 71 #define UWSGI_OPT_VHOST (1 << 5) 72 #define UWSGI_OPT_MEMORY (1 << 6) 73 #define UWSGI_OPT_PROCNAME (1 << 7) 74 #define UWSGI_OPT_LAZY (1 << 8) 75 #define UWSGI_OPT_NO_INITIAL (1 << 9) 76 #define UWSGI_OPT_NO_SERVER (1 << 10) 77 #define UWSGI_OPT_POST_BUFFERING (1 << 11) 78 #define UWSGI_OPT_CLUSTER (1 << 12) 79 #define UWSGI_OPT_MIME (1 << 13) 80 #define UWSGI_OPT_REQ_LOG_MASTER (1 << 14) 81 #define UWSGI_OPT_METRICS (1 << 15) 82 83 #define MAX_GENERIC_PLUGINS 128 84 #define MAX_GATEWAYS 64 85 #define MAX_TIMERS 64 86 #define MAX_CRONS 64 87 88 #define UWSGI_VIA_SENDFILE 1 89 #define UWSGI_VIA_ROUTE 2 90 #define UWSGI_VIA_OFFLOAD 3 91 92 #ifndef UWSGI_LOAD_EMBEDDED_PLUGINS 93 #define UWSGI_LOAD_EMBEDDED_PLUGINS 94 #endif 95 96 #ifndef UWSGI_DECLARE_EMBEDDED_PLUGINS 97 #define UWSGI_DECLARE_EMBEDDED_PLUGINS 98 #endif 99 100 #ifdef UWSGI_EMBED_CONFIG 101 extern char UWSGI_EMBED_CONFIG; 102 extern char UWSGI_EMBED_CONFIG_END; 103 #endif 104 105 #define UDEP(pname) extern struct uwsgi_plugin pname##_plugin; 106 107 #define ULEP(pname)\ 108 if (pname##_plugin.request) {\ 109 uwsgi.p[pname##_plugin.modifier1] = &pname##_plugin;\ 110 if (uwsgi.p[pname##_plugin.modifier1]->on_load)\ 111 uwsgi.p[pname##_plugin.modifier1]->on_load();\ 112 }\ 113 else {\ 114 if (uwsgi.gp_cnt >= MAX_GENERIC_PLUGINS) {\ 115 uwsgi_log("you have embedded too much generic plugins !!!\n");\ 116 exit(1);\ 117 }\ 118 uwsgi.gp[uwsgi.gp_cnt] = &pname##_plugin;\ 119 if (uwsgi.gp[uwsgi.gp_cnt]->on_load)\ 120 uwsgi.gp[uwsgi.gp_cnt]->on_load();\ 121 uwsgi.gp_cnt++;\ 122 }\ 123 124 125 #define fill_plugin_table(x, up)\ 126 if (up->request) {\ 127 uwsgi.p[x] = up;\ 128 }\ 129 else {\ 130 if (uwsgi.gp_cnt >= MAX_GENERIC_PLUGINS) {\ 131 uwsgi_log("you have embedded too much generic plugins !!!\n");\ 132 exit(1);\ 133 }\ 134 uwsgi.gp[uwsgi.gp_cnt] = up;\ 135 uwsgi.gp_cnt++;\ 136 }\ 137 138 #define uwsgi_foreach(x, y) for(x=y;x;x = x->next) 139 140 #define uwsgi_foreach_token(x, y, z, w) for(z=strtok_r(x, y, &w);z;z = strtok_r(NULL, y, &w)) 141 142 143 #ifndef __need_IOV_MAX 144 #define __need_IOV_MAX 145 #endif 146 147 #ifdef __sun__ 148 #ifndef _XPG4_2 149 #define _XPG4_2 150 #endif 151 #ifndef __EXTENSIONS__ 152 #define __EXTENSIONS__ 153 #endif 154 #endif 155 156 #if defined(__linux__) || defined(__GNUC__) 157 #ifndef _GNU_SOURCE 158 #define _GNU_SOURCE 159 #endif 160 #ifndef __USE_GNU 161 #define __USE_GNU 162 #endif 163 #endif 164 165 #include <stdio.h> 166 #include <stdlib.h> 167 #include <stddef.h> 168 #include <signal.h> 169 #include <math.h> 170 171 #include <sys/types.h> 172 #include <sys/socket.h> 173 #include <net/if.h> 174 #ifdef __linux__ 175 #ifndef MSG_FASTOPEN 176 #define MSG_FASTOPEN 0x20000000 177 #endif 178 #endif 179 #include <netinet/in.h> 180 181 #include <termios.h> 182 183 #ifdef UWSGI_UUID 184 #include <uuid/uuid.h> 185 #endif 186 187 #include <string.h> 188 #include <sys/stat.h> 189 #include <netinet/tcp.h> 190 #ifdef __linux__ 191 #ifndef TCP_FASTOPEN 192 #define TCP_FASTOPEN 23 193 #endif 194 #endif 195 #include <netdb.h> 196 197 #if defined(__GNU_kFreeBSD__) 198 #include <bsd/unistd.h> 199 #endif 200 201 #if defined(__FreeBSD__) || defined(__GNU_kFreeBSD__) 202 #include <sys/sysctl.h> 203 #include <sys/param.h> 204 #include <sys/cpuset.h> 205 #include <sys/jail.h> 206 #ifdef UWSGI_HAS_FREEBSD_LIBJAIL 207 #include <jail.h> 208 #endif 209 #endif 210 211 #include <sys/ipc.h> 212 #include <sys/sem.h> 213 214 #include <stdarg.h> 215 #include <errno.h> 216 #ifndef __USE_ISOC99 217 #define __USE_ISOC99 218 #endif 219 #include <ctype.h> 220 #include <sys/time.h> 221 #include <unistd.h> 222 223 #ifdef UWSGI_HAS_IFADDRS 224 #include <ifaddrs.h> 225 #endif 226 227 228 #include <pwd.h> 229 #include <grp.h> 230 231 232 #include <sys/utsname.h> 233 234 235 #ifdef __linux__ 236 #include <sched.h> 237 #include <sys/prctl.h> 238 #include <linux/limits.h> 239 #endif 240 241 #if defined(__linux) || defined(__FreeBSD__) || defined(__GNU_kFreeBSD__) 242 #include <sys/mount.h> 243 #endif 244 245 #ifdef __linux__ 246 extern int pivot_root(const char *new_root, const char *put_old); 247 #endif 248 249 #include <limits.h> 250 251 #include <dirent.h> 252 253 #ifndef UWSGI_PLUGIN_BASE 254 #define UWSGI_PLUGIN_BASE "" 255 #endif 256 257 #include <arpa/inet.h> 258 #include <sys/mman.h> 259 #include <sys/file.h> 260 261 #include <stdint.h> 262 263 #include <sys/wait.h> 264 #ifndef WAIT_ANY 265 #define WAIT_ANY (-1) 266 #endif 267 268 #ifdef __APPLE__ 269 #ifndef MAC_OS_X_VERSION_MIN_REQUIRED 270 #define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4 271 #endif 272 #include <mach-o/dyld.h> 273 #endif 274 275 #include <dlfcn.h> 276 277 #include <poll.h> 278 #include <sys/uio.h> 279 #include <sys/un.h> 280 281 #include <fcntl.h> 282 #include <pthread.h> 283 284 #include <sys/resource.h> 285 286 #include <getopt.h> 287 288 #ifdef __APPLE__ 289 #include <libkern/OSAtomic.h> 290 #include <mach/task.h> 291 #include <mach/mach_init.h> 292 #endif 293 294 #ifdef _POSIX_C_SOURCE 295 #undef _POSIX_C_SOURCE 296 #endif 297 #if defined(__sun__) 298 #define WAIT_ANY (-1) 299 #include <sys/filio.h> 300 #define PRIO_MAX 20 301 #endif 302 303 #if defined(__HAIKU__) || defined(__CYGWIN__) 304 #ifndef WAIT_ANY 305 #define WAIT_ANY (-1) 306 #endif 307 #define PRIO_MAX 20 308 #endif 309 310 #include <sys/ioctl.h> 311 312 #ifdef __linux__ 313 #include <sys/sendfile.h> 314 #include <sys/epoll.h> 315 #elif defined(__GNU_kFreeBSD__) 316 #include <sys/sendfile.h> 317 #include <sys/event.h> 318 #elif defined(__sun__) 319 #include <sys/sendfile.h> 320 #include <sys/devpoll.h> 321 #elif defined(__HAIKU__) 322 #elif defined(__CYGWIN__) 323 #elif defined(__HURD__) 324 #else 325 #include <sys/event.h> 326 #endif 327 328 #ifdef UWSGI_CAP 329 #include <sys/capability.h> 330 #endif 331 332 #ifdef __HAIKU__ 333 #include <kernel/OS.h> 334 #endif 335 336 #undef _XOPEN_SOURCE 337 #ifdef __sun__ 338 #undef __EXTENSIONS__ 339 #endif 340 #ifdef _GNU_SOURCE 341 #undef _GNU_SOURCE 342 #endif 343 344 #define UWSGI_CACHE_FLAG_UNGETTABLE 0x01 345 #define UWSGI_CACHE_FLAG_UPDATE 1 << 1 346 #define UWSGI_CACHE_FLAG_LOCAL 1 << 2 347 #define UWSGI_CACHE_FLAG_ABSEXPIRE 1 << 3 348 #define UWSGI_CACHE_FLAG_MATH 1 << 4 349 #define UWSGI_CACHE_FLAG_INC 1 << 5 350 #define UWSGI_CACHE_FLAG_DEC 1 << 6 351 #define UWSGI_CACHE_FLAG_MUL 1 << 7 352 #define UWSGI_CACHE_FLAG_DIV 1 << 8 353 #define UWSGI_CACHE_FLAG_FIXEXPIRE 1 << 9 354 355 #ifdef UWSGI_SSL 356 #include <openssl/conf.h> 357 #include <openssl/ssl.h> 358 #include <openssl/err.h> 359 360 #if OPENSSL_VERSION_NUMBER < 0x10100000L 361 #define UWSGI_SSL_SESSION_CACHE 362 #endif 363 #endif 364 365 #include <glob.h> 366 367 #ifdef __CYGWIN__ 368 #define __WINCRYPT_H__ 369 #include <windows.h> 370 #ifdef UWSGI_UUID 371 #undef uuid_t 372 #endif 373 #undef CMSG_DATA 374 #define CMSG_DATA(cmsg) \ 375 ((unsigned char *) ((struct cmsghdr *)(cmsg) + 1)) 376 #endif 377 378 struct uwsgi_buffer { 379 char *buf; 380 size_t pos; 381 size_t len; 382 size_t limit; 383 #ifdef UWSGI_DEBUG_BUFFER 384 int freed; 385 #endif 386 }; 387 388 struct uwsgi_string_list { 389 char *value; 390 size_t len; 391 uint64_t custom; 392 uint64_t custom2; 393 void *custom_ptr; 394 struct uwsgi_string_list *next; 395 }; 396 397 struct uwsgi_custom_option { 398 char *name; 399 char *value; 400 int has_args; 401 struct uwsgi_custom_option *next; 402 }; 403 404 struct uwsgi_lock_item { 405 char *id; 406 void *lock_ptr; 407 int rw; 408 pid_t pid; 409 int can_deadlock; 410 struct uwsgi_lock_item *next; 411 }; 412 413 414 struct uwsgi_lock_ops { 415 struct uwsgi_lock_item *(*lock_init) (char *); 416 pid_t(*lock_check) (struct uwsgi_lock_item *); 417 void (*lock) (struct uwsgi_lock_item *); 418 void (*unlock) (struct uwsgi_lock_item *); 419 420 struct uwsgi_lock_item *(*rwlock_init) (char *); 421 pid_t(*rwlock_check) (struct uwsgi_lock_item *); 422 void (*rlock) (struct uwsgi_lock_item *); 423 void (*wlock) (struct uwsgi_lock_item *); 424 void (*rwunlock) (struct uwsgi_lock_item *); 425 }; 426 427 #define uwsgi_lock_init(x) uwsgi.lock_ops.lock_init(x) 428 #define uwsgi_lock_check(x) uwsgi.lock_ops.lock_check(x) 429 #define uwsgi_lock(x) uwsgi.lock_ops.lock(x) 430 #define uwsgi_unlock(x) uwsgi.lock_ops.unlock(x) 431 432 #define uwsgi_rwlock_init(x) uwsgi.lock_ops.rwlock_init(x) 433 #define uwsgi_rwlock_check(x) uwsgi.lock_ops.rwlock_check(x) 434 #define uwsgi_rlock(x) uwsgi.lock_ops.rlock(x) 435 #define uwsgi_wlock(x) uwsgi.lock_ops.wlock(x) 436 #define uwsgi_rwunlock(x) uwsgi.lock_ops.rwunlock(x) 437 438 #define uwsgi_wait_read_req(x) uwsgi.wait_read_hook(x->fd, uwsgi.socket_timeout) ; x->switches++ 439 #define uwsgi_wait_write_req(x) uwsgi.wait_write_hook(x->fd, uwsgi.socket_timeout) ; x->switches++ 440 441 #ifdef UWSGI_PCRE 442 #include <pcre.h> 443 #endif 444 445 struct uwsgi_dyn_dict { 446 447 char *key; 448 int keylen; 449 char *value; 450 int vallen; 451 452 uint64_t hits; 453 int status; 454 455 struct uwsgi_dyn_dict *prev; 456 struct uwsgi_dyn_dict *next; 457 458 #ifdef UWSGI_PCRE 459 pcre *pattern; 460 pcre_extra *pattern_extra; 461 #endif 462 463 }; 464 465 struct uwsgi_hook { 466 char *name; 467 int (*func)(char *); 468 struct uwsgi_hook *next; 469 }; 470 471 #ifdef UWSGI_PCRE 472 struct uwsgi_regexp_list { 473 474 pcre *pattern; 475 pcre_extra *pattern_extra; 476 477 uint64_t custom; 478 char *custom_str; 479 void *custom_ptr; 480 struct uwsgi_regexp_list *next; 481 }; 482 #endif 483 484 struct uwsgi_rbtree { 485 struct uwsgi_rb_timer *root; 486 struct uwsgi_rb_timer *sentinel; 487 }; 488 489 struct uwsgi_rb_timer { 490 uint8_t color; 491 struct uwsgi_rb_timer *parent; 492 struct uwsgi_rb_timer *left; 493 struct uwsgi_rb_timer *right; 494 uint64_t value; 495 void *data; 496 }; 497 498 struct uwsgi_rbtree *uwsgi_init_rb_timer(void); 499 struct uwsgi_rb_timer *uwsgi_min_rb_timer(struct uwsgi_rbtree *, struct uwsgi_rb_timer *); 500 struct uwsgi_rb_timer *uwsgi_add_rb_timer(struct uwsgi_rbtree *, uint64_t, void *); 501 void uwsgi_del_rb_timer(struct uwsgi_rbtree *, struct uwsgi_rb_timer *); 502 503 504 union uwsgi_sockaddr { 505 struct sockaddr sa; 506 struct sockaddr_in sa_in; 507 struct sockaddr_un sa_un; 508 #ifdef AF_INET6 509 struct sockaddr_in6 sa_in6; 510 #endif 511 }; 512 513 union uwsgi_sockaddr_ptr { 514 struct sockaddr *sa; 515 struct sockaddr_in *sa_in; 516 struct sockaddr_un *sa_un; 517 #ifdef AF_INET6 518 struct sockaddr_in6 *sa_in6; 519 #endif 520 }; 521 522 // Gateways are processes (managed by the master) that extends the 523 // server core features 524 // -- Gateways can prefork or spawn threads -- 525 526 struct uwsgi_gateway { 527 528 char *name; 529 char *fullname; 530 void (*loop) (int, void *); 531 pid_t pid; 532 int num; 533 int use_signals; 534 535 int internal_subscription_pipe[2]; 536 uint64_t respawns; 537 538 uid_t uid; 539 gid_t gid; 540 541 void *data; 542 }; 543 544 struct uwsgi_gateway_socket { 545 546 char *name; 547 size_t name_len; 548 int fd; 549 char *zerg; 550 551 char *port; 552 int port_len; 553 554 int no_defer; 555 556 void *data; 557 int subscription; 558 int shared; 559 560 char *owner; 561 struct uwsgi_gateway *gateway; 562 563 struct uwsgi_gateway_socket *next; 564 565 // could be useful for ssl 566 void *ctx; 567 // could be useful for plugins 568 int mode; 569 570 }; 571 572 573 // Daemons are external processes maintained by the master 574 575 struct uwsgi_daemon { 576 char *command; 577 pid_t pid; 578 uint64_t respawns; 579 time_t born; 580 time_t last_spawn; 581 int status; 582 int registered; 583 584 int has_daemonized; 585 586 char *pidfile; 587 int daemonize; 588 589 // this is incremented every time a pidfile is not found 590 uint64_t pidfile_checks; 591 // frequency of pidfile checks (default 10 secs) 592 int freq; 593 594 int control; 595 struct uwsgi_daemon *next; 596 597 int stop_signal; 598 int reload_signal; 599 600 uid_t uid; 601 uid_t gid; 602 603 int honour_stdin; 604 605 struct uwsgi_string_list *touch; 606 607 #ifdef UWSGI_SSL 608 char *legion; 609 #endif 610 611 int ns_pid; 612 int throttle; 613 614 char *chdir; 615 616 int max_throttle; 617 618 int notifypid; 619 }; 620 621 struct uwsgi_logger { 622 char *name; 623 char *id; 624 ssize_t(*func) (struct uwsgi_logger *, char *, size_t); 625 int configured; 626 int fd; 627 void *data; 628 union uwsgi_sockaddr addr; 629 socklen_t addr_len; 630 int count; 631 struct msghdr msg; 632 char *buf; 633 // used by choosen logger 634 char *arg; 635 struct uwsgi_logger *next; 636 }; 637 638 #ifdef UWSGI_SSL 639 struct uwsgi_legion_node { 640 char *name; 641 uint16_t name_len; 642 uint64_t valor; 643 char uuid[37]; 644 char *scroll; 645 uint16_t scroll_len; 646 uint64_t checksum; 647 uint64_t lord_valor; 648 char lord_uuid[36]; 649 time_t last_seen; 650 struct uwsgi_legion_node *prev; 651 struct uwsgi_legion_node *next; 652 }; 653 654 struct uwsgi_legion { 655 char *legion; 656 uint16_t legion_len; 657 uint64_t valor; 658 char *addr; 659 char *name; 660 uint16_t name_len; 661 pid_t pid; 662 char uuid[37]; 663 int socket; 664 665 int quorum; 666 int changed; 667 // if set the next packet will be a death-announce 668 int dead; 669 670 // set to 1 first time when quorum is reached 671 int joined; 672 673 uint64_t checksum; 674 675 char *scroll; 676 uint16_t scroll_len; 677 678 char *lord_scroll; 679 uint16_t lord_scroll_len; 680 uint16_t lord_scroll_size; 681 682 char lord_uuid[36]; 683 uint64_t lord_valor; 684 685 time_t i_am_the_lord; 686 687 time_t unix_check; 688 689 time_t last_warning; 690 691 struct uwsgi_lock_item *lock; 692 693 EVP_CIPHER_CTX *encrypt_ctx; 694 EVP_CIPHER_CTX *decrypt_ctx; 695 696 char *scrolls; 697 uint64_t scrolls_len; 698 uint64_t scrolls_max_size; 699 700 // found nodes dynamic lists 701 struct uwsgi_legion_node *nodes_head; 702 struct uwsgi_legion_node *nodes_tail; 703 704 // static list of nodes to send announces to 705 struct uwsgi_string_list *nodes; 706 struct uwsgi_string_list *lord_hooks; 707 struct uwsgi_string_list *unlord_hooks; 708 struct uwsgi_string_list *setup_hooks; 709 struct uwsgi_string_list *death_hooks; 710 struct uwsgi_string_list *join_hooks; 711 struct uwsgi_string_list *node_joined_hooks; 712 struct uwsgi_string_list *node_left_hooks; 713 714 time_t suspended_til; 715 struct uwsgi_legion *next; 716 }; 717 718 struct uwsgi_legion_action { 719 char *name; 720 int (*func) (struct uwsgi_legion *, char *); 721 char *log_msg; 722 struct uwsgi_legion_action *next; 723 }; 724 #endif 725 726 struct uwsgi_queue_header { 727 uint64_t pos; 728 uint64_t pull_pos; 729 }; 730 731 struct uwsgi_queue_item { 732 uint64_t size; 733 time_t ts; 734 }; 735 736 struct uwsgi_hash_algo { 737 char *name; 738 uint32_t(*func) (char *, uint64_t); 739 struct uwsgi_hash_algo *next; 740 }; 741 742 struct uwsgi_hash_algo *uwsgi_hash_algo_get(char *); 743 void uwsgi_hash_algo_register(char *, uint32_t(*)(char *, uint64_t)); 744 void uwsgi_hash_algo_register_all(void); 745 746 struct uwsgi_sharedarea { 747 int id; 748 int pages; 749 int fd; 750 struct uwsgi_lock_item *lock; 751 char *area; 752 uint64_t max_pos; 753 uint64_t updates; 754 uint64_t hits; 755 uint8_t honour_used; 756 uint64_t used; 757 void *obj; 758 }; 759 760 // maintain alignment here !!! 761 struct uwsgi_cache_item { 762 // item specific flags 763 uint64_t flags; 764 // size of the key 765 uint64_t keysize; 766 // hash of the key 767 uint64_t hash; 768 // size of the value (64bit) 769 uint64_t valsize; 770 // block position (in non-bitmap mode maps to the key index) 771 uint64_t first_block; 772 // 64bit expiration (0 for immortal) 773 uint64_t expires; 774 // 64bit hits 775 uint64_t hits; 776 // previous same-hash item 777 uint64_t prev; 778 // next same-hash item 779 uint64_t next; 780 // previous lru item 781 uint64_t lru_prev; 782 // next lru item 783 uint64_t lru_next; 784 // key characters follows... 785 char key[]; 786 } __attribute__ ((__packed__)); 787 788 struct uwsgi_cache { 789 char *name; 790 uint16_t name_len; 791 792 uint64_t keysize; 793 uint64_t blocks; 794 uint64_t blocksize; 795 796 struct uwsgi_hash_algo *hash; 797 uint64_t *hashtable; 798 uint32_t hashsize; 799 800 uint64_t first_available_block; 801 uint64_t *unused_blocks_stack; 802 uint64_t unused_blocks_stack_ptr; 803 804 uint8_t use_blocks_bitmap; 805 uint8_t *blocks_bitmap; 806 uint64_t blocks_bitmap_pos; 807 uint64_t blocks_bitmap_size; 808 809 uint64_t max_items; 810 uint64_t max_item_size; 811 uint64_t n_items; 812 struct uwsgi_cache_item *items; 813 814 uint8_t use_last_modified; 815 time_t last_modified_at; 816 817 void *data; 818 819 uint8_t no_expire; 820 uint64_t full; 821 uint64_t hits; 822 uint64_t miss; 823 824 char *store; 825 uint64_t filesize; 826 uint64_t store_sync; 827 828 int64_t math_initial; 829 830 struct uwsgi_string_list *nodes; 831 int udp_node_socket; 832 struct uwsgi_string_list *sync_nodes; 833 struct uwsgi_string_list *udp_servers; 834 835 struct uwsgi_lock_item *lock; 836 837 struct uwsgi_cache *next; 838 839 int ignore_full; 840 841 uint64_t next_scan; 842 int purge_lru; 843 uint64_t lru_head; 844 uint64_t lru_tail; 845 846 int store_delete; 847 int lazy_expire; 848 uint64_t sweep_on_full; 849 int clear_on_full; 850 }; 851 852 struct uwsgi_option { 853 char *name; 854 int type; 855 int shortcut; 856 char *help; 857 void (*func) (char *, char *, void *); 858 void *data; 859 uint64_t flags; 860 }; 861 862 struct uwsgi_opt { 863 char *key; 864 char *value; 865 int configured; 866 }; 867 868 #define UWSGI_OK 0 869 #define UWSGI_AGAIN 1 870 #define UWSGI_ACCEPTING 2 871 #define UWSGI_PAUSED 3 872 873 #ifdef __linux__ 874 #include <endian.h> 875 #if defined(__BYTE_ORDER__) 876 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 877 #define __BIG_ENDIAN__ 1 878 #endif 879 #endif 880 #elif defined(__sun__) 881 #include <sys/byteorder.h> 882 #ifdef _BIG_ENDIAN 883 #define __BIG_ENDIAN__ 1 884 #endif 885 #elif defined(__APPLE__) 886 #include <libkern/OSByteOrder.h> 887 #elif defined(__HAIKU__) 888 #elif defined(__HURD__) 889 #define PATH_MAX 8192 890 #define RTLD_DEFAULT ((void *) 0) 891 #else 892 #include <machine/endian.h> 893 #endif 894 895 #define UWSGI_SPOOLER_EXTERNAL 1 896 897 #define UWSGI_MODIFIER_ADMIN_REQUEST 10 898 #define UWSGI_MODIFIER_SPOOL_REQUEST 17 899 #define UWSGI_MODIFIER_EVAL 22 900 #define UWSGI_MODIFIER_FASTFUNC 26 901 #define UWSGI_MODIFIER_MANAGE_PATH_INFO 30 902 #define UWSGI_MODIFIER_MESSAGE 31 903 #define UWSGI_MODIFIER_MESSAGE_ARRAY 32 904 #define UWSGI_MODIFIER_MESSAGE_MARSHAL 33 905 #define UWSGI_MODIFIER_MULTICAST_ANNOUNCE 73 906 #define UWSGI_MODIFIER_MULTICAST 74 907 #define UWSGI_MODIFIER_PING 100 908 909 #define UWSGI_MODIFIER_RESPONSE 255 910 911 #define NL_SIZE 2 912 #define H_SEP_SIZE 2 913 914 #define UWSGI_RELOAD_CODE 17 915 #define UWSGI_END_CODE 30 916 #define UWSGI_EXILE_CODE 26 917 #define UWSGI_FAILED_APP_CODE 22 918 #define UWSGI_DE_HIJACKED_CODE 173 919 #define UWSGI_EXCEPTION_CODE 5 920 #define UWSGI_QUIET_CODE 29 921 #define UWSGI_BRUTAL_RELOAD_CODE 31 922 #define UWSGI_GO_CHEAP_CODE 15 923 924 #define MAX_VARS 64 925 926 struct uwsgi_loop { 927 char *name; 928 void (*loop) (void); 929 struct uwsgi_loop *next; 930 }; 931 932 struct wsgi_request; 933 934 struct uwsgi_socket { 935 int fd; 936 char *name; 937 int name_len; 938 int family; 939 int bound; 940 int arg; 941 void *ctx; 942 943 uint64_t queue; 944 uint64_t max_queue; 945 int no_defer; 946 947 int auto_port; 948 // true if connection must be initialized for each core 949 int per_core; 950 951 // this is the protocol internal name 952 char *proto_name; 953 954 // call that when a request is accepted 955 int (*proto_accept) (struct wsgi_request *, int); 956 // call that to parse the request (without the body) 957 int (*proto) (struct wsgi_request *); 958 // call that to write reponse 959 int (*proto_write) (struct wsgi_request *, char *, size_t); 960 // call that to write headers (if a special case is needed for them) 961 int (*proto_write_headers) (struct wsgi_request *, char *, size_t); 962 // call that when sendfile() is invoked 963 int (*proto_sendfile) (struct wsgi_request *, int, size_t, size_t); 964 // call that to read the body of a request (could map to a simple read()) 965 ssize_t(*proto_read_body) (struct wsgi_request *, char *, size_t); 966 // hook to call when a new series of response headers is created 967 struct uwsgi_buffer *(*proto_prepare_headers) (struct wsgi_request *, char *, uint16_t); 968 // hook to call when a header must be added 969 struct uwsgi_buffer *(*proto_add_header) (struct wsgi_request *, char *, uint16_t, char *, uint16_t); 970 // last function to call before sending headers to the client 971 int (*proto_fix_headers) (struct wsgi_request *); 972 // hook to call when a request is closed 973 void (*proto_close) (struct wsgi_request *); 974 // special hook to call (if needed) in multithread mode 975 void (*proto_thread_fixup) (struct uwsgi_socket *, int); 976 // optimization for vectors 977 int (*proto_writev) (struct wsgi_request *, struct iovec *, size_t *); 978 979 int edge_trigger; 980 int *retry; 981 982 int can_offload; 983 984 // this is a special map for having socket->thread mapping 985 int *fd_threads; 986 987 // generally used by zeromq handlers 988 char uuid[37]; 989 void *pub; 990 void *pull; 991 pthread_key_t key; 992 993 pthread_mutex_t lock; 994 995 char *receiver; 996 997 int disabled; 998 int recv_flag; 999 1000 struct uwsgi_socket *next; 1001 int lazy; 1002 int shared; 1003 int from_shared; 1004 1005 // used for avoiding vacuum mess 1006 ino_t inode; 1007 1008 #ifdef UWSGI_SSL 1009 SSL_CTX *ssl_ctx; 1010 #endif 1011 1012 }; 1013 1014 struct uwsgi_protocol { 1015 char *name; 1016 void (*func)(struct uwsgi_socket *); 1017 struct uwsgi_protocol *next; 1018 }; 1019 1020 struct uwsgi_server; 1021 struct uwsgi_instance; 1022 1023 struct uwsgi_plugin { 1024 1025 const char *name; 1026 const char *alias; 1027 uint8_t modifier1; 1028 void *data; 1029 void (*on_load) (void); 1030 int (*init) (void); 1031 void (*post_init) (void); 1032 void (*post_fork) (void); 1033 struct uwsgi_option *options; 1034 void (*enable_threads) (void); 1035 void (*init_thread) (int); 1036 int (*request) (struct wsgi_request *); 1037 void (*after_request) (struct wsgi_request *); 1038 void (*preinit_apps) (void); 1039 void (*init_apps) (void); 1040 void (*postinit_apps) (void); 1041 void (*fixup) (void); 1042 void (*master_fixup) (int); 1043 void (*master_cycle) (void); 1044 int (*mount_app) (char *, char *); 1045 int (*manage_udp) (char *, int, char *, int); 1046 void (*suspend) (struct wsgi_request *); 1047 void (*resume) (struct wsgi_request *); 1048 1049 void (*harakiri) (int); 1050 1051 void (*hijack_worker) (void); 1052 void (*spooler_init) (void); 1053 void (*atexit) (void); 1054 1055 int (*magic) (char *, char *); 1056 1057 void *(*encode_string) (char *); 1058 char *(*decode_string) (void *); 1059 int (*signal_handler) (uint8_t, void *); 1060 char *(*code_string) (char *, char *, char *, char *, uint16_t); 1061 1062 int (*spooler) (char *, char *, uint16_t, char *, size_t); 1063 1064 uint64_t(*rpc) (void *, uint8_t, char **, uint16_t *, char **); 1065 1066 void (*jail) (int (*)(void *), char **); 1067 void (*post_jail) (void); 1068 void (*before_privileges_drop) (void); 1069 1070 int (*mule) (char *); 1071 int (*mule_msg) (char *, size_t); 1072 1073 void (*master_cleanup) (void); 1074 1075 struct uwsgi_buffer* (*backtrace)(struct wsgi_request *); 1076 struct uwsgi_buffer* (*exception_class)(struct wsgi_request *); 1077 struct uwsgi_buffer* (*exception_msg)(struct wsgi_request *); 1078 struct uwsgi_buffer* (*exception_repr)(struct wsgi_request *); 1079 void (*exception_log)(struct wsgi_request *); 1080 1081 void (*vassal)(struct uwsgi_instance *); 1082 void (*vassal_before_exec)(struct uwsgi_instance *); 1083 1084 int (*worker)(void); 1085 1086 void (*early_post_jail) (void); 1087 }; 1088 1089 #ifdef UWSGI_PCRE 1090 int uwsgi_regexp_build(char *, pcre **, pcre_extra **); 1091 int uwsgi_regexp_match(pcre *, pcre_extra *, char *, int); 1092 int uwsgi_regexp_match_ovec(pcre *, pcre_extra *, char *, int, int *, int); 1093 int uwsgi_regexp_ovector(pcre *, pcre_extra *); 1094 char *uwsgi_regexp_apply_ovec(char *, int, char *, int, int *, int); 1095 1096 int uwsgi_regexp_match_pattern(char *pattern, char *str); 1097 #endif 1098 1099 1100 1101 struct uwsgi_app { 1102 1103 uint8_t modifier1; 1104 1105 char mountpoint[0xff]; 1106 uint8_t mountpoint_len; 1107 1108 void *interpreter; 1109 void *callable; 1110 1111 void **args; 1112 void **environ; 1113 1114 void *sendfile; 1115 void *input; 1116 void *error; 1117 void *stream; 1118 1119 // custom values you can use for internal purpose 1120 void *responder0; 1121 void *responder1; 1122 void *responder2; 1123 1124 void *eventfd_read; 1125 void *eventfd_write; 1126 1127 void *(*request_subhandler) (struct wsgi_request *, struct uwsgi_app *); 1128 int (*response_subhandler) (struct wsgi_request *); 1129 1130 int argc; 1131 uint64_t requests; 1132 uint64_t exceptions; 1133 1134 char chdir[0xff]; 1135 char touch_reload[0xff]; 1136 1137 time_t touch_reload_mtime; 1138 1139 void *gateway_version; 1140 void *uwsgi_version; 1141 void *uwsgi_node; 1142 1143 time_t started_at; 1144 time_t startup_time; 1145 1146 uint64_t avg_response_time; 1147 }; 1148 1149 struct uwsgi_spooler { 1150 1151 char dir[PATH_MAX]; 1152 pid_t pid; 1153 uint64_t respawned; 1154 uint64_t tasks; 1155 struct uwsgi_lock_item *lock; 1156 time_t harakiri; 1157 time_t user_harakiri; 1158 1159 int mode; 1160 1161 int running; 1162 1163 int signal_pipe[2]; 1164 1165 struct uwsgi_spooler *next; 1166 1167 time_t cursed_at; 1168 time_t no_mercy_at; 1169 }; 1170 1171 #ifdef UWSGI_ROUTING 1172 1173 // go to the next route 1174 #define UWSGI_ROUTE_NEXT 0 1175 // continue to the request handler 1176 #define UWSGI_ROUTE_CONTINUE 1 1177 // close the request 1178 #define UWSGI_ROUTE_BREAK 2 1179 1180 struct uwsgi_route { 1181 1182 pcre *pattern; 1183 pcre_extra *pattern_extra; 1184 1185 char *orig_route; 1186 1187 // one for each core 1188 int *ovn; 1189 int **ovector; 1190 struct uwsgi_buffer **condition_ub; 1191 1192 char *subject_str; 1193 size_t subject_str_len; 1194 size_t subject; 1195 size_t subject_len; 1196 1197 int (*if_func)(struct wsgi_request *, struct uwsgi_route *); 1198 int if_negate; 1199 int if_status; 1200 1201 int (*func) (struct wsgi_request *, struct uwsgi_route *); 1202 1203 void *data; 1204 size_t data_len; 1205 1206 void *data2; 1207 size_t data2_len; 1208 1209 void *data3; 1210 size_t data3_len; 1211 1212 void *data4; 1213 size_t data4_len; 1214 1215 // 64bit value for custom usage 1216 uint64_t custom; 1217 1218 uint64_t pos; 1219 char *label; 1220 size_t label_len; 1221 1222 char *regexp; 1223 char *action; 1224 1225 // this is used by virtual route to free resources 1226 void (*free)(struct uwsgi_route *); 1227 1228 struct uwsgi_route *next; 1229 1230 }; 1231 1232 struct uwsgi_route_condition { 1233 char *name; 1234 int (*func)(struct wsgi_request *, struct uwsgi_route *); 1235 struct uwsgi_route_condition *next; 1236 }; 1237 1238 struct uwsgi_route_var { 1239 char *name; 1240 uint16_t name_len; 1241 char *(*func)(struct wsgi_request *, char *, uint16_t, uint16_t *); 1242 int need_free; 1243 struct uwsgi_route_var *next; 1244 }; 1245 1246 struct uwsgi_router { 1247 char *name; 1248 int (*func) (struct uwsgi_route *, char *); 1249 struct uwsgi_router *next; 1250 }; 1251 1252 #endif 1253 1254 struct uwsgi_alarm; 1255 struct uwsgi_alarm_instance { 1256 char *name; 1257 char *arg; 1258 void *data_ptr; 1259 uint8_t data8; 1260 uint16_t data16; 1261 uint32_t data32; 1262 uint64_t data64; 1263 1264 time_t last_run; 1265 1266 char *last_msg; 1267 size_t last_msg_size; 1268 1269 struct uwsgi_alarm *alarm; 1270 struct uwsgi_alarm_instance *next; 1271 }; 1272 1273 struct uwsgi_alarm { 1274 char *name; 1275 void (*init) (struct uwsgi_alarm_instance *); 1276 void (*func) (struct uwsgi_alarm_instance *, char *, size_t); 1277 struct uwsgi_alarm *next; 1278 }; 1279 1280 struct uwsgi_alarm_fd { 1281 int fd; 1282 size_t buf_len; 1283 void *buf; 1284 char *msg; 1285 size_t msg_len; 1286 struct uwsgi_alarm_instance *alarm; 1287 struct uwsgi_alarm_fd *next; 1288 }; 1289 1290 struct uwsgi_alarm_fd *uwsgi_add_alarm_fd(int, char *, size_t, char *, size_t); 1291 1292 #ifdef UWSGI_PCRE 1293 struct uwsgi_alarm_ll { 1294 struct uwsgi_alarm_instance *alarm; 1295 struct uwsgi_alarm_ll *next; 1296 }; 1297 1298 struct uwsgi_alarm_log { 1299 pcre *pattern; 1300 pcre_extra *pattern_extra; 1301 int negate; 1302 struct uwsgi_alarm_ll *alarms; 1303 struct uwsgi_alarm_log *next; 1304 }; 1305 #endif 1306 1307 struct __attribute__ ((packed)) uwsgi_header { 1308 uint8_t modifier1; 1309 uint16_t pktsize; 1310 uint8_t modifier2; 1311 }; 1312 1313 struct uwsgi_async_fd { 1314 int fd; 1315 int event; 1316 struct uwsgi_async_fd *prev; 1317 struct uwsgi_async_fd *next; 1318 }; 1319 1320 struct uwsgi_logvar { 1321 char key[256]; 1322 uint8_t keylen; 1323 char val[256]; 1324 uint8_t vallen; 1325 struct uwsgi_logvar *next; 1326 }; 1327 1328 struct uwsgi_log_encoder { 1329 char *name; 1330 char *(*func)(struct uwsgi_log_encoder *, char *, size_t, size_t *); 1331 int configured; 1332 char *use_for; 1333 char *args; 1334 void *data; 1335 struct uwsgi_log_encoder *next; 1336 }; 1337 1338 struct uwsgi_transformation { 1339 int (*func)(struct wsgi_request *, struct uwsgi_transformation *); 1340 struct uwsgi_buffer *chunk; 1341 uint8_t can_stream; 1342 uint8_t is_final; 1343 uint8_t flushed; 1344 void *data; 1345 uint64_t round; 1346 int fd; 1347 struct uwsgi_buffer *ub; 1348 uint64_t len; 1349 uint64_t custom64; 1350 struct uwsgi_transformation *next; 1351 }; 1352 1353 enum uwsgi_range { 1354 UWSGI_RANGE_NOT_PARSED, 1355 UWSGI_RANGE_PARSED, 1356 UWSGI_RANGE_VALID, 1357 UWSGI_RANGE_INVALID, 1358 }; 1359 1360 struct wsgi_request { 1361 int fd; 1362 struct uwsgi_header *uh; 1363 1364 int app_id; 1365 int dynamic; 1366 int parsed; 1367 1368 char *appid; 1369 uint16_t appid_len; 1370 1371 // This structure should not be used any more 1372 // in favor of the union client_addr at the end 1373 struct sockaddr_un c_addr; 1374 int c_len; 1375 1376 //iovec 1377 struct iovec *hvec; 1378 1379 uint64_t start_of_request; 1380 uint64_t start_of_request_in_sec; 1381 uint64_t end_of_request; 1382 1383 char *uri; 1384 uint16_t uri_len; 1385 char *remote_addr; 1386 uint16_t remote_addr_len; 1387 char *remote_user; 1388 uint16_t remote_user_len; 1389 char *query_string; 1390 uint16_t query_string_len; 1391 char *protocol; 1392 uint16_t protocol_len; 1393 char *method; 1394 uint16_t method_len; 1395 char *scheme; 1396 uint16_t scheme_len; 1397 char *https; 1398 uint16_t https_len; 1399 char *script_name; 1400 uint16_t script_name_len; 1401 int script_name_pos; 1402 1403 char *host; 1404 uint16_t host_len; 1405 1406 char *content_type; 1407 uint16_t content_type_len; 1408 1409 char *document_root; 1410 uint16_t document_root_len; 1411 1412 char *user_agent; 1413 uint16_t user_agent_len; 1414 1415 char *encoding; 1416 uint16_t encoding_len; 1417 1418 char *referer; 1419 uint16_t referer_len; 1420 1421 char *cookie; 1422 uint16_t cookie_len; 1423 1424 char *path_info; 1425 uint16_t path_info_len; 1426 int path_info_pos; 1427 1428 char *authorization; 1429 uint16_t authorization_len; 1430 1431 uint16_t via; 1432 1433 char *script; 1434 uint16_t script_len; 1435 char *module; 1436 uint16_t module_len; 1437 char *callable; 1438 uint16_t callable_len; 1439 char *home; 1440 uint16_t home_len; 1441 1442 char *file; 1443 uint16_t file_len; 1444 1445 char *paste; 1446 uint16_t paste_len; 1447 1448 char *chdir; 1449 uint16_t chdir_len; 1450 1451 char *touch_reload; 1452 uint16_t touch_reload_len; 1453 1454 char *cache_get; 1455 uint16_t cache_get_len; 1456 1457 char *if_modified_since; 1458 uint16_t if_modified_since_len; 1459 1460 int fd_closed; 1461 1462 int sendfile_fd; 1463 size_t sendfile_fd_chunk; 1464 size_t sendfile_fd_size; 1465 off_t sendfile_fd_pos; 1466 void *sendfile_obj; 1467 1468 uint16_t var_cnt; 1469 uint16_t header_cnt; 1470 1471 int do_not_log; 1472 1473 int do_not_add_to_async_queue; 1474 1475 int do_not_account; 1476 1477 int status; 1478 struct uwsgi_buffer *headers; 1479 1480 size_t response_size; 1481 size_t headers_size; 1482 1483 int async_id; 1484 int async_status; 1485 1486 int switches; 1487 size_t write_pos; 1488 1489 int async_timed_out; 1490 int async_ready_fd; 1491 int async_last_ready_fd; 1492 struct uwsgi_rb_timer *async_timeout; 1493 struct uwsgi_async_fd *waiting_fds; 1494 1495 void *async_app; 1496 void *async_result; 1497 void *async_placeholder; 1498 void *async_args; 1499 void *async_environ; 1500 void *async_input; 1501 void *async_sendfile; 1502 1503 int async_force_again; 1504 1505 int async_plagued; 1506 1507 int suspended; 1508 uint64_t write_errors; 1509 uint64_t read_errors; 1510 1511 int *ovector; 1512 size_t post_cl; 1513 size_t post_pos; 1514 size_t post_readline_size; 1515 size_t post_readline_pos; 1516 size_t post_readline_watermark; 1517 FILE *post_file; 1518 char *post_readline_buf; 1519 // this is used when no post buffering is in place 1520 char *post_read_buf; 1521 size_t post_read_buf_size; 1522 char *post_buffering_buf; 1523 // when set, do not send warnings about bad behaviours 1524 int post_warning; 1525 1526 // deprecated fields: size_t is 32bit on 32bit platform 1527 size_t __range_from; 1528 size_t __range_to; 1529 1530 // current socket mapped to request 1531 struct uwsgi_socket *socket; 1532 1533 // check if headers are already sent 1534 int headers_sent; 1535 int headers_hvec; 1536 1537 uint64_t proto_parser_pos; 1538 uint64_t proto_parser_move; 1539 int64_t proto_parser_status; 1540 void *proto_parser_buf; 1541 uint64_t proto_parser_buf_size; 1542 void *proto_parser_remains_buf; 1543 size_t proto_parser_remains; 1544 1545 char *buffer; 1546 1547 int log_this; 1548 1549 int sigwait; 1550 int signal_received; 1551 1552 struct uwsgi_logvar *logvars; 1553 struct uwsgi_string_list *additional_headers; 1554 struct uwsgi_string_list *remove_headers; 1555 1556 struct uwsgi_buffer *websocket_buf; 1557 struct uwsgi_buffer *websocket_send_buf; 1558 size_t websocket_need; 1559 int websocket_phase; 1560 uint8_t websocket_opcode; 1561 size_t websocket_has_mask; 1562 size_t websocket_size; 1563 size_t websocket_pktsize; 1564 time_t websocket_last_ping; 1565 time_t websocket_last_pong; 1566 int websocket_closed; 1567 // websocket specific headers 1568 char *http_sec_websocket_key; 1569 uint16_t http_sec_websocket_key_len; 1570 char *http_origin; 1571 uint16_t http_origin_len; 1572 char *http_sec_websocket_protocol; 1573 uint16_t http_sec_websocket_protocol_len; 1574 1575 1576 struct uwsgi_buffer *chunked_input_buf; 1577 uint8_t chunked_input_parser_status; 1578 ssize_t chunked_input_chunk_len; 1579 size_t chunked_input_need; 1580 uint8_t chunked_input_complete; 1581 size_t chunked_input_decapitate; 1582 1583 uint64_t stream_id; 1584 1585 // avoid routing loops 1586 int is_routing; 1587 int is_final_routing; 1588 int is_error_routing; 1589 int is_response_routing; 1590 int routes_applied; 1591 int response_routes_applied; 1592 // internal routing vm program counter 1593 uint32_t route_pc; 1594 uint32_t error_route_pc; 1595 uint32_t response_route_pc; 1596 uint32_t final_route_pc; 1597 // internal routing goto instruction 1598 uint32_t route_goto; 1599 uint32_t error_route_goto; 1600 uint32_t response_route_goto; 1601 uint32_t final_route_goto; 1602 1603 int ignore_body; 1604 1605 struct uwsgi_transformation *transformations; 1606 char *transformed_chunk; 1607 size_t transformed_chunk_len; 1608 1609 int is_raw; 1610 1611 #ifdef UWSGI_SSL 1612 SSL *ssl; 1613 #endif 1614 1615 // do not update avg_rt after request 1616 int do_not_account_avg_rt; 1617 // used for protocol parsers requiring EOF signaling 1618 int proto_parser_eof; 1619 1620 // 64bit range, deprecates size_t __range_from, __range_to 1621 enum uwsgi_range range_parsed; 1622 int64_t range_from; 1623 int64_t range_to; 1624 1625 char * if_range; 1626 uint16_t if_range_len; 1627 1628 // client address in a type-safe fashion; always use this over 1629 // c_addr (which only exists to maintain binary compatibility in this 1630 // struct) 1631 union address { 1632 struct sockaddr_in sin; 1633 struct sockaddr_in6 sin6; 1634 struct sockaddr_un sun; 1635 } client_addr; 1636 1637 uint8_t websocket_is_fin; 1638 }; 1639 1640 1641 struct uwsgi_fmon { 1642 char filename[0xff]; 1643 int fd; 1644 int id; 1645 int registered; 1646 uint8_t sig; 1647 }; 1648 1649 struct uwsgi_timer { 1650 int value; 1651 int fd; 1652 int id; 1653 int registered; 1654 uint8_t sig; 1655 }; 1656 1657 struct uwsgi_signal_rb_timer { 1658 int value; 1659 int registered; 1660 int iterations; 1661 int iterations_done; 1662 uint8_t sig; 1663 struct uwsgi_rb_timer *uwsgi_rb_timer; 1664 }; 1665 1666 struct uwsgi_cheaper_algo { 1667 1668 char *name; 1669 int (*func) (int); 1670 struct uwsgi_cheaper_algo *next; 1671 }; 1672 1673 struct uwsgi_emperor_scanner; 1674 1675 struct uwsgi_imperial_monitor { 1676 char *scheme; 1677 void (*init) (struct uwsgi_emperor_scanner *); 1678 void (*func) (struct uwsgi_emperor_scanner *); 1679 struct uwsgi_imperial_monitor *next; 1680 }; 1681 1682 struct uwsgi_clock { 1683 char *name; 1684 time_t(*seconds) (void); 1685 uint64_t(*microseconds) (void); 1686 struct uwsgi_clock *next; 1687 }; 1688 1689 struct uwsgi_subscribe_slot; 1690 struct uwsgi_stats_pusher; 1691 struct uwsgi_stats_pusher_instance; 1692 1693 #define UWSGI_PROTO_MIN_CHECK 4 1694 #define UWSGI_PROTO_MAX_CHECK 28 1695 1696 struct uwsgi_offload_engine; 1697 1698 // these are the possible states of an instance 1699 struct uwsgi_instance_status { 1700 int gracefully_reloading; 1701 int brutally_reloading; 1702 int gracefully_destroying; 1703 int brutally_destroying; 1704 int chain_reloading; 1705 int workers_reloading; 1706 int is_cheap; 1707 int is_cleaning; 1708 int dying_for_need_app; 1709 }; 1710 1711 struct uwsgi_configurator { 1712 char *name; 1713 void (*func)(char *, char **); 1714 struct uwsgi_configurator *next; 1715 }; 1716 struct uwsgi_configurator *uwsgi_register_configurator(char *, void (*)(char *, char **)); 1717 void uwsgi_opt_load_config(char *, char *, void *); 1718 1719 #define uwsgi_instance_is_dying (uwsgi.status.gracefully_destroying || uwsgi.status.brutally_destroying) 1720 #define uwsgi_instance_is_reloading (uwsgi.status.gracefully_reloading || uwsgi.status.brutally_reloading) 1721 1722 #define exit(x) uwsgi_exit(x) 1723 1724 struct uwsgi_metric; 1725 1726 struct uwsgi_logging_options { 1727 int enabled; 1728 int memory_report; 1729 int zero; 1730 int _4xx; 1731 int _5xx; 1732 int sendfile; 1733 int ioerror; 1734 uint32_t slow; 1735 uint64_t big; 1736 int log_x_forwarded_for; 1737 }; 1738 1739 struct uwsgi_harakiri_options { 1740 int workers; 1741 int spoolers; 1742 int mules; 1743 }; 1744 1745 struct uwsgi_fsmon { 1746 char *path; 1747 int fd; 1748 int id; 1749 void *data; 1750 void (*func)(struct uwsgi_fsmon *); 1751 struct uwsgi_fsmon *next; 1752 }; 1753 1754 struct uwsgi_server { 1755 1756 // store the machine hostname 1757 char hostname[256]; 1758 int hostname_len; 1759 1760 // used to store the exit code for atexit hooks 1761 int last_exit_code; 1762 1763 int (*proto_hooks[UWSGI_PROTO_MAX_CHECK]) (struct wsgi_request *, char *, char *, uint16_t); 1764 struct uwsgi_configurator *configurators; 1765 1766 char **orig_argv; 1767 char **argv; 1768 int argc; 1769 int max_procname; 1770 int auto_procname; 1771 char **environ; 1772 char *procname_prefix; 1773 char *procname_append; 1774 char *procname_master; 1775 char *procname; 1776 1777 struct uwsgi_logging_options logging_options; 1778 struct uwsgi_harakiri_options harakiri_options; 1779 int socket_timeout; 1780 int reaper; 1781 int cgi_mode; 1782 uint64_t max_requests; 1783 uint64_t min_worker_lifetime; 1784 uint64_t max_worker_lifetime; 1785 1786 // daemontools-like envdir 1787 struct uwsgi_string_list *envdirs; 1788 1789 char *requested_clock; 1790 struct uwsgi_clock *clocks; 1791 struct uwsgi_clock *clock; 1792 1793 char *empty; 1794 1795 // quiet startup 1796 int no_initial_output; 1797 1798 struct uwsgi_instance_status status; 1799 1800 struct uwsgi_string_list *get_list; 1801 1802 // enable threads 1803 int has_threads; 1804 int no_threads_wait; 1805 1806 // default app id 1807 int default_app; 1808 1809 char *logto2; 1810 char *logformat; 1811 int logformat_strftime; 1812 int logformat_vectors; 1813 struct uwsgi_logchunk *logchunks; 1814 struct uwsgi_logchunk *registered_logchunks; 1815 void (*logit) (struct wsgi_request *); 1816 struct iovec **logvectors; 1817 1818 // autoload plugins 1819 int autoload; 1820 struct uwsgi_string_list *plugins_dir; 1821 struct uwsgi_string_list *blacklist; 1822 struct uwsgi_string_list *whitelist; 1823 char *blacklist_context; 1824 char *whitelist_context; 1825 1826 unsigned int reloads; 1827 1828 // leave master running as root 1829 int master_as_root; 1830 // postpone privileges drop 1831 int drop_after_init; 1832 int drop_after_apps; 1833 1834 int master_is_reforked; 1835 1836 struct uwsgi_string_list *master_fifo; 1837 int master_fifo_fd; 1838 int master_fifo_slot; 1839 1840 1841 // kill the stack on SIGTERM (instead of brutal reloading) 1842 int die_on_term; 1843 1844 // force the first gateway without a master 1845 int force_gateway; 1846 1847 // disable fd passing on unix socket 1848 int no_fd_passing; 1849 1850 // store the current time 1851 time_t current_time; 1852 1853 uint64_t master_cycles; 1854 1855 int reuse_port; 1856 int tcp_fast_open; 1857 int tcp_fast_open_client; 1858 1859 int enable_proxy_protocol; 1860 1861 uint64_t fastcgi_modifier1; 1862 uint64_t fastcgi_modifier2; 1863 uint64_t http_modifier1; 1864 uint64_t http_modifier2; 1865 uint64_t https_modifier1; 1866 uint64_t https_modifier2; 1867 uint64_t scgi_modifier1; 1868 uint64_t scgi_modifier2; 1869 uint64_t raw_modifier1; 1870 uint64_t raw_modifier2; 1871 1872 // enable lazy mode 1873 int lazy; 1874 // enable lazy-apps mode 1875 int lazy_apps; 1876 // enable cheaper mode 1877 int cheaper; 1878 char *requested_cheaper_algo; 1879 struct uwsgi_cheaper_algo *cheaper_algos; 1880 int (*cheaper_algo) (int); 1881 int cheaper_step; 1882 uint64_t cheaper_overload; 1883 // minimal number of running workers in cheaper mode 1884 int cheaper_count; 1885 int cheaper_initial; 1886 // enable idle mode 1887 int idle; 1888 1889 // cheaper mode memory usage limits 1890 uint64_t cheaper_rss_limit_soft; 1891 uint64_t cheaper_rss_limit_hard; 1892 1893 int cheaper_fifo_delta; 1894 1895 // destroy the stack when idle 1896 int die_on_idle; 1897 1898 // store the screen session 1899 char *screen_session; 1900 1901 // true if run under the emperor 1902 int has_emperor; 1903 char *emperor_procname; 1904 char *emperor_proxy; 1905 int emperor_fd; 1906 int emperor_fd_proxy; 1907 int emperor_queue; 1908 int emperor_nofollow; 1909 int emperor_tyrant; 1910 int emperor_tyrant_nofollow; 1911 int emperor_fd_config; 1912 int early_emperor; 1913 int emperor_throttle; 1914 int emperor_freq; 1915 int emperor_max_throttle; 1916 int emperor_magic_exec; 1917 int emperor_heartbeat; 1918 int emperor_curse_tolerance; 1919 struct uwsgi_string_list *emperor_extra_extension; 1920 // search for a file with the specified extension at the same level of the vassal file 1921 char *emperor_on_demand_extension; 1922 // bind to a unix socket on the specified directory named directory/vassal.socket 1923 char *emperor_on_demand_directory; 1924 // run a shell script passing the vassal as the only argument, the stdout is used as the socket 1925 char *emperor_on_demand_exec; 1926 1927 int disable_nuclear_blast; 1928 1929 time_t next_heartbeat; 1930 int heartbeat; 1931 struct uwsgi_string_list *emperor; 1932 struct uwsgi_imperial_monitor *emperor_monitors; 1933 char *emperor_absolute_dir; 1934 char *emperor_pidfile; 1935 pid_t emperor_pid; 1936 int emperor_broodlord; 1937 int emperor_broodlord_count; 1938 uint64_t emperor_broodlord_num; 1939 char *emperor_stats; 1940 int emperor_stats_fd; 1941 struct uwsgi_string_list *vassals_templates; 1942 struct uwsgi_string_list *vassals_includes; 1943 struct uwsgi_string_list *vassals_templates_before; 1944 struct uwsgi_string_list *vassals_includes_before; 1945 struct uwsgi_string_list *vassals_set; 1946 // true if loyal to the emperor 1947 int loyal; 1948 1949 // emperor hook (still in development) 1950 char *vassals_start_hook; 1951 char *vassals_stop_hook; 1952 1953 struct uwsgi_string_list *additional_headers; 1954 struct uwsgi_string_list *remove_headers; 1955 struct uwsgi_string_list *collect_headers; 1956 1957 // set cpu affinity 1958 int cpu_affinity; 1959 1960 int reload_mercy; 1961 int worker_reload_mercy; 1962 // map reloads to death 1963 int exit_on_reload; 1964 1965 // store options 1966 int dirty_config; 1967 int option_index; 1968 int (*logic_opt) (char *, char *); 1969 char *logic_opt_arg; 1970 char *logic_opt_data; 1971 int logic_opt_running; 1972 int logic_opt_cycles; 1973 struct uwsgi_option *options; 1974 struct option *long_options; 1975 char *short_options; 1976 struct uwsgi_opt **exported_opts; 1977 int exported_opts_cnt; 1978 struct uwsgi_custom_option *custom_options; 1979 1980 // dump the whole set of options 1981 int dump_options; 1982 // show ini representation of the current config 1983 int show_config; 1984 // enable strict mode (only registered options can be used) 1985 int strict; 1986 1987 // list loaded features 1988 int cheaper_algo_list; 1989 #ifdef UWSGI_ROUTING 1990 int router_list; 1991 #endif 1992 int imperial_monitor_list; 1993 int plugins_list; 1994 int loggers_list; 1995 int loop_list; 1996 int clock_list; 1997 int alarms_list; 1998 1999 struct wsgi_request *wsgi_req; 2000 2001 char *remap_modifier; 2002 2003 // enable zerg mode 2004 int *zerg; 2005 char *zerg_server; 2006 struct uwsgi_string_list *zerg_node; 2007 int zerg_fallback; 2008 int zerg_server_fd; 2009 2010 // security 2011 char *chroot; 2012 gid_t gid; 2013 uid_t uid; 2014 char *uidname; 2015 char *gidname; 2016 int no_initgroups; 2017 struct uwsgi_string_list *additional_gids; 2018 2019 #ifdef UWSGI_CAP 2020 cap_value_t *cap; 2021 int cap_count; 2022 cap_value_t *emperor_cap; 2023 int emperor_cap_count; 2024 #endif 2025 2026 #ifdef __linux__ 2027 int unshare; 2028 int unshare2; 2029 int emperor_clone; 2030 char *pivot_root; 2031 char *setns_socket; 2032 struct uwsgi_string_list *setns_socket_skip; 2033 char *setns; 2034 int setns_socket_fd; 2035 int setns_preopen; 2036 int setns_fds[64]; 2037 int setns_fds_count; 2038 #endif 2039 char *emperor_wrapper; 2040 2041 int jailed; 2042 #if defined(__FreeBSD__) || defined(__GNU_kFreeBSD__) 2043 char *jail; 2044 struct uwsgi_string_list *jail_ip4; 2045 #ifdef AF_INET6 2046 struct uwsgi_string_list *jail_ip6; 2047 #endif 2048 struct uwsgi_string_list *jail2; 2049 char *jidfile; 2050 char *jail_attach; 2051 #endif 2052 int refork; 2053 int refork_as_root; 2054 int refork_post_jail; 2055 2056 int ignore_sigpipe; 2057 int ignore_write_errors; 2058 uint64_t write_errors_tolerance; 2059 int write_errors_exception_only; 2060 int disable_write_exception; 2061 2062 // still working on it 2063 char *profiler; 2064 2065 // the weight of the instance, used by various cluster/lb components 2066 uint64_t weight; 2067 int auto_weight; 2068 2069 // mostly useless 2070 char *mode; 2071 2072 // binary patch the worker image 2073 char *worker_exec; 2074 char *worker_exec2; 2075 2076 // this must be UN-shared 2077 struct uwsgi_gateway_socket *gateway_sockets; 2078 2079 2080 int ignore_script_name; 2081 int manage_script_name; 2082 int reload_on_exception; 2083 int catch_exceptions; 2084 struct uwsgi_string_list *reload_on_exception_type; 2085 struct uwsgi_string_list *reload_on_exception_value; 2086 struct uwsgi_string_list *reload_on_exception_repr; 2087 2088 struct uwsgi_exception_handler *exception_handlers; 2089 struct uwsgi_string_list *exception_handlers_instance; 2090 struct uwsgi_thread *exception_handler_thread; 2091 uint64_t exception_handler_msg_size; 2092 2093 2094 int no_default_app; 2095 // exit if no-app is loaded 2096 int need_app; 2097 2098 int forkbomb_delay; 2099 2100 int logdate; 2101 int log_micros; 2102 char *log_strftime; 2103 2104 int honour_stdin; 2105 struct termios termios; 2106 int restore_tc; 2107 2108 // honour the HTTP Range header 2109 int honour_range; 2110 2111 // route all of the logs to the master process 2112 int req_log_master; 2113 int log_master; 2114 char *log_master_buf; 2115 size_t log_master_bufsize; 2116 int log_master_stream; 2117 int log_master_req_stream; 2118 2119 int log_reopen; 2120 int log_truncate; 2121 uint64_t log_maxsize; 2122 char *log_backupname; 2123 2124 int original_log_fd; 2125 int req_log_fd; 2126 2127 // static file serving 2128 int file_serve_mode; 2129 int build_mime_dict; 2130 2131 struct uwsgi_string_list *mime_file; 2132 2133 struct uwsgi_hook *hooks; 2134 2135 struct uwsgi_string_list *hook_touch; 2136 2137 struct uwsgi_string_list *hook_asap; 2138 struct uwsgi_string_list *hook_pre_jail; 2139 struct uwsgi_string_list *hook_post_jail; 2140 struct uwsgi_string_list *hook_in_jail; 2141 struct uwsgi_string_list *hook_as_root; 2142 struct uwsgi_string_list *hook_as_user; 2143 struct uwsgi_string_list *hook_as_user_atexit; 2144 struct uwsgi_string_list *hook_pre_app; 2145 struct uwsgi_string_list *hook_post_app; 2146 struct uwsgi_string_list *hook_accepting; 2147 struct uwsgi_string_list *hook_accepting1; 2148 struct uwsgi_string_list *hook_accepting_once; 2149 struct uwsgi_string_list *hook_accepting1_once; 2150 2151 struct uwsgi_string_list *hook_emperor_start; 2152 struct uwsgi_string_list *hook_master_start; 2153 2154 struct uwsgi_string_list *hook_emperor_stop; 2155 struct uwsgi_string_list *hook_emperor_reload; 2156 struct uwsgi_string_list *hook_emperor_lost; 2157 2158 struct uwsgi_string_list *hook_as_vassal; 2159 struct uwsgi_string_list *hook_as_emperor; 2160 struct uwsgi_string_list *hook_as_mule; 2161 struct uwsgi_string_list *hook_as_gateway; 2162 2163 2164 struct uwsgi_string_list *exec_asap; 2165 struct uwsgi_string_list *exec_pre_jail; 2166 struct uwsgi_string_list *exec_post_jail; 2167 struct uwsgi_string_list *exec_in_jail; 2168 struct uwsgi_string_list *exec_as_root; 2169 struct uwsgi_string_list *exec_as_user; 2170 struct uwsgi_string_list *exec_as_user_atexit; 2171 struct uwsgi_string_list *exec_pre_app; 2172 struct uwsgi_string_list *exec_post_app; 2173 2174 struct uwsgi_string_list *exec_as_vassal; 2175 struct uwsgi_string_list *exec_as_emperor; 2176 2177 struct uwsgi_string_list *call_asap; 2178 struct uwsgi_string_list *call_pre_jail; 2179 struct uwsgi_string_list *call_post_jail; 2180 struct uwsgi_string_list *call_in_jail; 2181 struct uwsgi_string_list *call_as_root; 2182 struct uwsgi_string_list *call_as_user; 2183 struct uwsgi_string_list *call_as_user_atexit; 2184 struct uwsgi_string_list *call_pre_app; 2185 struct uwsgi_string_list *call_post_app; 2186 2187 struct uwsgi_string_list *call_as_vassal; 2188 struct uwsgi_string_list *call_as_vassal1; 2189 struct uwsgi_string_list *call_as_vassal3; 2190 2191 struct uwsgi_string_list *call_as_emperor; 2192 struct uwsgi_string_list *call_as_emperor1; 2193 struct uwsgi_string_list *call_as_emperor2; 2194 struct uwsgi_string_list *call_as_emperor4; 2195 2196 struct uwsgi_string_list *mount_asap; 2197 struct uwsgi_string_list *mount_pre_jail; 2198 struct uwsgi_string_list *mount_post_jail; 2199 struct uwsgi_string_list *mount_in_jail; 2200 struct uwsgi_string_list *mount_as_root; 2201 2202 struct uwsgi_string_list *mount_as_vassal; 2203 struct uwsgi_string_list *mount_as_emperor; 2204 2205 struct uwsgi_string_list *umount_asap; 2206 struct uwsgi_string_list *umount_pre_jail; 2207 struct uwsgi_string_list *umount_post_jail; 2208 struct uwsgi_string_list *umount_in_jail; 2209 struct uwsgi_string_list *umount_as_root; 2210 2211 struct uwsgi_string_list *umount_as_vassal; 2212 struct uwsgi_string_list *umount_as_emperor; 2213 2214 struct uwsgi_string_list *after_request_hooks; 2215 2216 struct uwsgi_string_list *wait_for_interface; 2217 int wait_for_interface_timeout; 2218 2219 char *privileged_binary_patch; 2220 char *unprivileged_binary_patch; 2221 char *privileged_binary_patch_arg; 2222 char *unprivileged_binary_patch_arg; 2223 2224 struct uwsgi_logger *loggers; 2225 struct uwsgi_logger *choosen_logger; 2226 struct uwsgi_logger *choosen_req_logger; 2227 struct uwsgi_string_list *requested_logger; 2228 struct uwsgi_string_list *requested_req_logger; 2229 2230 struct uwsgi_log_encoder *log_encoders; 2231 struct uwsgi_string_list *requested_log_encoders; 2232 struct uwsgi_string_list *requested_log_req_encoders; 2233 2234 #ifdef UWSGI_PCRE 2235 int pcre_jit; 2236 struct uwsgi_regexp_list *log_drain_rules; 2237 struct uwsgi_regexp_list *log_filter_rules; 2238 struct uwsgi_regexp_list *log_route; 2239 struct uwsgi_regexp_list *log_req_route; 2240 #endif 2241 2242 int use_abort; 2243 2244 int alarm_freq; 2245 uint64_t alarm_msg_size; 2246 struct uwsgi_string_list *alarm_list; 2247 struct uwsgi_string_list *alarm_logs_list; 2248 struct uwsgi_alarm_fd *alarm_fds; 2249 struct uwsgi_string_list *alarm_fd_list; 2250 struct uwsgi_string_list *alarm_segfault; 2251 struct uwsgi_string_list *alarm_backlog; 2252 struct uwsgi_alarm *alarms; 2253 struct uwsgi_alarm_instance *alarm_instances; 2254 struct uwsgi_alarm_log *alarm_logs; 2255 struct uwsgi_thread *alarm_thread; 2256 2257 int threaded_logger; 2258 pthread_mutex_t threaded_logger_lock; 2259 2260 int *safe_fds; 2261 int safe_fds_cnt; 2262 2263 int daemons_honour_stdin; 2264 struct uwsgi_daemon *daemons; 2265 int daemons_cnt; 2266 2267 #ifdef UWSGI_SSL 2268 char *subscriptions_sign_check_dir; 2269 int subscriptions_sign_check_tolerance; 2270 const EVP_MD *subscriptions_sign_check_md; 2271 struct uwsgi_string_list *subscriptions_sign_skip_uid; 2272 #endif 2273 2274 struct uwsgi_string_list *subscriptions_credentials_check_dir; 2275 int subscriptions_use_credentials; 2276 2277 struct uwsgi_dyn_dict *static_maps; 2278 struct uwsgi_dyn_dict *static_maps2; 2279 struct uwsgi_dyn_dict *check_static; 2280 struct uwsgi_dyn_dict *mimetypes; 2281 struct uwsgi_string_list *static_skip_ext; 2282 struct uwsgi_string_list *static_index; 2283 struct uwsgi_string_list *static_safe; 2284 2285 struct uwsgi_hash_algo *hash_algos; 2286 int use_static_cache_paths; 2287 char *static_cache_paths_name; 2288 struct uwsgi_cache *static_cache_paths; 2289 int cache_expire_freq; 2290 int cache_report_freed_items; 2291 int cache_no_expire; 2292 uint64_t cache_max_items; 2293 uint64_t cache_blocksize; 2294 char *cache_store; 2295 int cache_store_sync; 2296 struct uwsgi_string_list *cache2; 2297 int cache_setup; 2298 int locking_setup; 2299 int cache_use_last_modified; 2300 2301 struct uwsgi_dyn_dict *static_expires_type; 2302 struct uwsgi_dyn_dict *static_expires_type_mtime; 2303 2304 struct uwsgi_dyn_dict *static_expires; 2305 struct uwsgi_dyn_dict *static_expires_mtime; 2306 2307 struct uwsgi_dyn_dict *static_expires_uri; 2308 struct uwsgi_dyn_dict *static_expires_uri_mtime; 2309 2310 struct uwsgi_dyn_dict *static_expires_path_info; 2311 struct uwsgi_dyn_dict *static_expires_path_info_mtime; 2312 2313 int static_gzip_all; 2314 struct uwsgi_string_list *static_gzip_dir; 2315 struct uwsgi_string_list *static_gzip_ext; 2316 #ifdef UWSGI_PCRE 2317 struct uwsgi_regexp_list *static_gzip; 2318 #endif 2319 2320 struct uwsgi_offload_engine *offload_engines; 2321 struct uwsgi_offload_engine *offload_engine_sendfile; 2322 struct uwsgi_offload_engine *offload_engine_transfer; 2323 struct uwsgi_offload_engine *offload_engine_memory; 2324 struct uwsgi_offload_engine *offload_engine_pipe; 2325 int offload_threads; 2326 int offload_threads_events; 2327 struct uwsgi_thread **offload_thread; 2328 2329 int check_static_docroot; 2330 int disable_sendfile; 2331 2332 char *daemonize; 2333 char *daemonize2; 2334 int do_not_change_umask; 2335 char *logfile; 2336 int logfile_chown; 2337 2338 // enable vhost mode 2339 int vhost; 2340 int vhost_host; 2341 2342 // async commodity 2343 struct wsgi_request **async_waiting_fd_table; 2344 struct wsgi_request **async_proto_fd_table; 2345 struct uwsgi_async_request *async_runqueue; 2346 struct uwsgi_async_request *async_runqueue_last; 2347 2348 struct uwsgi_rbtree *rb_async_timeouts; 2349 2350 int async_queue_unused_ptr; 2351 struct wsgi_request **async_queue_unused; 2352 2353 2354 // store rlimit 2355 struct rlimit rl; 2356 struct rlimit rl_nproc; 2357 size_t limit_post; 2358 2359 // set process priority 2360 int prio; 2361 2362 // funny reload systems 2363 int force_get_memusage; 2364 rlim_t reload_on_as; 2365 rlim_t reload_on_rss; 2366 rlim_t evil_reload_on_as; 2367 rlim_t evil_reload_on_rss; 2368 2369 struct uwsgi_string_list *reload_on_fd; 2370 struct uwsgi_string_list *brutal_reload_on_fd; 2371 2372 struct uwsgi_string_list *touch_reload; 2373 struct uwsgi_string_list *touch_chain_reload; 2374 struct uwsgi_string_list *touch_workers_reload; 2375 struct uwsgi_string_list *touch_gracefully_stop; 2376 struct uwsgi_string_list *touch_logrotate; 2377 struct uwsgi_string_list *touch_logreopen; 2378 struct uwsgi_string_list *touch_exec; 2379 struct uwsgi_string_list *touch_signal; 2380 2381 struct uwsgi_string_list *fs_reload; 2382 struct uwsgi_string_list *fs_brutal_reload; 2383 struct uwsgi_string_list *fs_signal; 2384 2385 struct uwsgi_fsmon *fsmon; 2386 2387 struct uwsgi_string_list *signal_timers; 2388 struct uwsgi_string_list *rb_signal_timers; 2389 2390 struct uwsgi_string_list *mountpoints_check; 2391 2392 int propagate_touch; 2393 2394 // enable grunt mode 2395 int grunt; 2396 2397 // store the binary path 2398 char *binary_path; 2399 2400 int is_a_reload; 2401 2402 2403 char *udp_socket; 2404 2405 int multicast_ttl; 2406 int multicast_loop; 2407 char *multicast_group; 2408 2409 struct uwsgi_spooler *spoolers; 2410 int spooler_numproc; 2411 struct uwsgi_spooler *i_am_a_spooler; 2412 char *spooler_chdir; 2413 int spooler_max_tasks; 2414 int spooler_ordered; 2415 int spooler_quiet; 2416 int spooler_frequency; 2417 2418 int snmp; 2419 char *snmp_addr; 2420 char *snmp_community; 2421 struct uwsgi_lock_item *snmp_lock; 2422 int snmp_fd; 2423 2424 int udp_fd; 2425 2426 uint16_t buffer_size; 2427 int signal_bufsize; 2428 2429 // post buffering 2430 size_t post_buffering; 2431 int post_buffering_harakiri; 2432 size_t post_buffering_bufsize; 2433 size_t body_read_warning; 2434 2435 int master_process; 2436 int master_queue; 2437 int master_interval; 2438 2439 // mainly iseful for broodlord mode 2440 int vassal_sos_backlog; 2441 2442 int no_defer_accept; 2443 int so_keepalive; 2444 int so_send_timeout; 2445 uint64_t so_sndbuf; 2446 uint64_t so_rcvbuf; 2447 2448 int page_size; 2449 int cpus; 2450 2451 char *pidfile; 2452 char *pidfile2; 2453 2454 char *flock2; 2455 char *flock_wait2; 2456 2457 int backtrace_depth; 2458 2459 int harakiri_verbose; 2460 int harakiri_no_arh; 2461 2462 int magic_table_first_round; 2463 char *magic_table[256]; 2464 2465 int numproc; 2466 int async; 2467 int async_running; 2468 int async_queue; 2469 int async_nevents; 2470 2471 time_t async_queue_is_full; 2472 2473 int max_vars; 2474 int vec_size; 2475 2476 // shared area 2477 struct uwsgi_string_list *sharedareas_list; 2478 int sharedareas_cnt; 2479 struct uwsgi_sharedarea **sharedareas; 2480 2481 // avoid thundering herd in threaded modes 2482 pthread_mutex_t thunder_mutex; 2483 pthread_mutex_t six_feet_under_lock; 2484 pthread_mutex_t lock_static; 2485 2486 int use_thunder_lock; 2487 struct uwsgi_lock_item *the_thunder_lock; 2488 2489 /* the list of workers */ 2490 struct uwsgi_worker *workers; 2491 int max_apps; 2492 2493 /* the list of mules */ 2494 struct uwsgi_string_list *mules_patches; 2495 struct uwsgi_mule *mules; 2496 struct uwsgi_string_list *farms_list; 2497 struct uwsgi_farm *farms; 2498 int mule_msg_size; 2499 2500 pid_t mypid; 2501 int mywid; 2502 2503 int muleid; 2504 int mules_cnt; 2505 int farms_cnt; 2506 2507 rlim_t requested_max_fd; 2508 rlim_t max_fd; 2509 2510 struct timeval start_tv; 2511 2512 int abstract_socket; 2513 #ifdef __linux__ 2514 int freebind; 2515 #endif 2516 2517 int chmod_socket; 2518 char *chown_socket; 2519 mode_t chmod_socket_value; 2520 mode_t chmod_logfile_value; 2521 int listen_queue; 2522 2523 char *fallback_config; 2524 2525 #ifdef UWSGI_ROUTING 2526 struct uwsgi_router *routers; 2527 struct uwsgi_route *routes; 2528 struct uwsgi_route *final_routes; 2529 struct uwsgi_route *error_routes; 2530 struct uwsgi_route *response_routes; 2531 struct uwsgi_route_condition *route_conditions; 2532 struct uwsgi_route_var *route_vars; 2533 #endif 2534 2535 struct uwsgi_string_list *error_page_403; 2536 struct uwsgi_string_list *error_page_404; 2537 struct uwsgi_string_list *error_page_500; 2538 2539 int single_interpreter; 2540 2541 struct uwsgi_shared *shared; 2542 2543 2544 int no_orphans; 2545 int skip_zero; 2546 int skip_atexit; 2547 2548 char *force_cwd; 2549 char *chdir; 2550 char *chdir2; 2551 struct uwsgi_string_list *binsh; 2552 2553 int vacuum; 2554 int no_server; 2555 int command_mode; 2556 2557 int xml_round2; 2558 2559 char *cwd; 2560 2561 // conditional logging 2562 int log_slow_requests; 2563 int log_zero_headers; 2564 int log_empty_body; 2565 int log_high_memory; 2566 2567 #ifdef __linux__ 2568 struct uwsgi_string_list *cgroup; 2569 struct uwsgi_string_list *cgroup_opt; 2570 char *cgroup_dir_mode; 2571 char *ns; 2572 char *ns_net; 2573 struct uwsgi_string_list *ns_keep_mount; 2574 #endif 2575 struct uwsgi_string_list *file_write_list; 2576 2577 char *protocol; 2578 2579 int signal_socket; 2580 int my_signal_socket; 2581 2582 struct uwsgi_protocol *protocols; 2583 struct uwsgi_socket *sockets; 2584 struct uwsgi_socket *shared_sockets; 2585 int is_et; 2586 2587 struct uwsgi_string_list *map_socket; 2588 2589 struct uwsgi_cron *crons; 2590 time_t cron_harakiri; 2591 2592 time_t respawn_delta; 2593 2594 struct uwsgi_string_list *mounts; 2595 2596 int cores; 2597 2598 int threads; 2599 pthread_attr_t threads_attr; 2600 size_t threads_stacksize; 2601 2602 //this key old the u_request structure per core / thread 2603 pthread_key_t tur_key; 2604 2605 2606 struct wsgi_request *(*current_wsgi_req) (void); 2607 2608 void (*notify) (char *); 2609 void (*notify_ready) (void); 2610 int notification_fd; 2611 void *notification_object; 2612 2613 // usedby suspend/resume loops 2614 void (*schedule_to_main) (struct wsgi_request *); 2615 void (*schedule_to_req) (void); 2616 void (*schedule_fix) (struct wsgi_request *); 2617 2618 void (*gbcw_hook) (void); 2619 2620 int close_on_exec; 2621 int close_on_exec2; 2622 2623 int tcp_nodelay; 2624 2625 char *loop; 2626 struct uwsgi_loop *loops; 2627 2628 struct uwsgi_plugin *p[256]; 2629 struct uwsgi_plugin *gp[MAX_GENERIC_PLUGINS]; 2630 int gp_cnt; 2631 2632 char *allowed_modifiers; 2633 2634 char *upload_progress; 2635 2636 struct uwsgi_lock_item *registered_locks; 2637 struct uwsgi_lock_ops lock_ops; 2638 char *lock_engine; 2639 char *ftok; 2640 char *lock_id; 2641 size_t lock_size; 2642 size_t rwlock_size; 2643 2644 struct uwsgi_string_list *add_cache_item; 2645 struct uwsgi_string_list *load_file_in_cache; 2646 #ifdef UWSGI_ZLIB 2647 struct uwsgi_string_list *load_file_in_cache_gzip; 2648 #endif 2649 char *use_check_cache; 2650 struct uwsgi_cache *check_cache; 2651 struct uwsgi_cache *caches; 2652 2653 struct uwsgi_string_list *cache_udp_server; 2654 struct uwsgi_string_list *cache_udp_node; 2655 2656 char *cache_sync; 2657 2658 // the stats server 2659 char *stats; 2660 int stats_fd; 2661 int stats_http; 2662 int stats_minified; 2663 struct uwsgi_string_list *requested_stats_pushers; 2664 struct uwsgi_stats_pusher *stats_pushers; 2665 struct uwsgi_stats_pusher_instance *stats_pusher_instances; 2666 int stats_pusher_default_freq; 2667 2668 uint64_t queue_size; 2669 uint64_t queue_blocksize; 2670 void *queue; 2671 struct uwsgi_queue_header *queue_header; 2672 char *queue_store; 2673 size_t queue_filesize; 2674 int queue_store_sync; 2675 2676 2677 int locks; 2678 int persistent_ipcsem; 2679 2680 struct uwsgi_lock_item *queue_lock; 2681 struct uwsgi_lock_item **user_lock; 2682 struct uwsgi_lock_item *signal_table_lock; 2683 struct uwsgi_lock_item *fmon_table_lock; 2684 struct uwsgi_lock_item *timer_table_lock; 2685 struct uwsgi_lock_item *rb_timer_table_lock; 2686 struct uwsgi_lock_item *cron_table_lock; 2687 struct uwsgi_lock_item *rpc_table_lock; 2688 struct uwsgi_lock_item *sa_lock; 2689 struct uwsgi_lock_item *metrics_lock; 2690 2691 // rpc 2692 uint64_t rpc_max; 2693 struct uwsgi_rpc *rpc_table; 2694 2695 // subscription client 2696 int subscriptions_blocked; 2697 int subscribe_freq; 2698 int subscription_tolerance; 2699 int unsubscribe_on_graceful_reload; 2700 struct uwsgi_string_list *subscriptions; 2701 struct uwsgi_string_list *subscriptions2; 2702 2703 struct uwsgi_subscribe_node *(*subscription_algo) (struct uwsgi_subscribe_slot *, struct uwsgi_subscribe_node *); 2704 int subscription_dotsplit; 2705 2706 int never_swap; 2707 2708 #ifdef UWSGI_SSL 2709 int ssl_initialized; 2710 int ssl_verbose; 2711 char *ssl_sessions_use_cache; 2712 int ssl_sessions_timeout; 2713 struct uwsgi_cache *ssl_sessions_cache; 2714 char *ssl_tmp_dir; 2715 #ifdef UWSGI_PCRE 2716 struct uwsgi_regexp_list *sni_regexp; 2717 #endif 2718 struct uwsgi_string_list *sni; 2719 char *sni_dir; 2720 char *sni_dir_ciphers; 2721 #endif 2722 2723 #ifdef UWSGI_SSL 2724 struct uwsgi_legion *legions; 2725 struct uwsgi_legion_action *legion_actions; 2726 int legion_queue; 2727 int legion_freq; 2728 int legion_tolerance; 2729 int legion_skew_tolerance; 2730 uint16_t legion_scroll_max_size; 2731 uint64_t legion_scroll_list_max_size; 2732 int legion_death_on_lord_error; 2733 #endif 2734 2735 #ifdef __linux__ 2736 #ifdef MADV_MERGEABLE 2737 int linux_ksm; 2738 int ksm_buffer_size; 2739 char *ksm_mappings_last; 2740 char *ksm_mappings_current; 2741 size_t ksm_mappings_last_size; 2742 size_t ksm_mappings_current_size; 2743 #endif 2744 #endif 2745 2746 struct uwsgi_buffer *websockets_ping; 2747 struct uwsgi_buffer *websockets_pong; 2748 struct uwsgi_buffer *websockets_close; 2749 int websockets_ping_freq; 2750 int websockets_pong_tolerance; 2751 uint64_t websockets_max_size; 2752 2753 int chunked_input_timeout; 2754 uint64_t chunked_input_limit; 2755 2756 struct uwsgi_metric *metrics; 2757 struct uwsgi_metric_collector *metric_collectors; 2758 int has_metrics; 2759 char *metrics_dir; 2760 int metrics_dir_restore; 2761 uint64_t metrics_cnt; 2762 struct uwsgi_string_list *additional_metrics; 2763 struct uwsgi_string_list *metrics_threshold; 2764 2765 int (*wait_write_hook) (int, int); 2766 int (*wait_read_hook) (int, int); 2767 int (*wait_milliseconds_hook) (int); 2768 int (*wait_read2_hook) (int, int, int, int *); 2769 2770 struct uwsgi_string_list *schemes; 2771 2772 // inject text files (useful for advanced templating) 2773 struct uwsgi_string_list *inject_before; 2774 struct uwsgi_string_list *inject_after; 2775 2776 // this is a unix socket receiving external notifications (like subscription replies) 2777 char *notify_socket; 2778 int notify_socket_fd; 2779 char *subscription_notify_socket; 2780 2781 //uWSGI 2.0.5 2782 2783 int mule_reload_mercy; 2784 int alarm_cheap; 2785 2786 int emperor_no_blacklist; 2787 int metrics_no_cores; 2788 int stats_no_cores; 2789 int stats_no_metrics; 2790 2791 // uWSGI 2.0.7 2792 int vassal_sos; 2793 2794 // uWSGI 2.0.8 2795 struct uwsgi_string_list *wait_for_fs; 2796 struct uwsgi_string_list *wait_for_dir; 2797 struct uwsgi_string_list *wait_for_file; 2798 int wait_for_fs_timeout; 2799 struct uwsgi_string_list *wait_for_mountpoint; 2800 #ifdef UWSGI_SSL 2801 int sslv3; 2802 struct uwsgi_string_list *ssl_options; 2803 #endif 2804 struct uwsgi_string_list *hook_post_fork; 2805 2806 // uWSGI 2.0.9 2807 char *subscribe_with_modifier1; 2808 struct uwsgi_string_list *pull_headers; 2809 2810 // uWSGI 2.0.10 2811 struct uwsgi_string_list *emperor_wrapper_override; 2812 struct uwsgi_string_list *emperor_wrapper_fallback; 2813 2814 // uWSGI 2.0.11 2815 struct uwsgi_string_list *wait_for_socket; 2816 int wait_for_socket_timeout; 2817 int mem_collector_freq; 2818 2819 // uWSGI 2.0.14 2820 struct uwsgi_string_list *touch_mules_reload; 2821 struct uwsgi_string_list *touch_spoolers_reload; 2822 int spooler_reload_mercy; 2823 2824 int skip_atexit_teardown; 2825 2826 // uWSGI 2.1 backport 2827 int new_argc; 2828 char **new_argv; 2829 2830 // uWSGI 2.0.16 2831 #ifdef UWSGI_SSL 2832 int ssl_verify_depth; 2833 #endif 2834 2835 size_t response_header_limit; 2836 char *safe_pidfile; 2837 char *safe_pidfile2; 2838 2839 // uWSGI 2.0.17 2840 int shutdown_sockets; 2841 2842 #ifdef UWSGI_SSL 2843 int tlsv1; 2844 #endif 2845 2846 // uWSGI 2.0.19 2847 int emperor_graceful_shutdown; 2848 int is_chrooted; 2849 struct uwsgi_buffer *websockets_continuation_buffer; 2850 2851 uint64_t max_worker_lifetime_delta; 2852 }; 2853 2854 struct uwsgi_rpc { 2855 char name[UMAX8]; 2856 void *func; 2857 uint8_t args; 2858 uint8_t shared; 2859 struct uwsgi_plugin *plugin; 2860 }; 2861 2862 struct uwsgi_signal_entry { 2863 int wid; 2864 uint8_t modifier1; 2865 char receiver[64]; 2866 void *handler; 2867 }; 2868 2869 /* 2870 they are here for backwards compatibility 2871 */ 2872 #define SNMP_COUNTER32 0x41 2873 #define SNMP_GAUGE 0x42 2874 #define SNMP_COUNTER64 0x46 2875 2876 struct uwsgi_snmp_custom_value { 2877 uint8_t type; 2878 uint64_t val; 2879 }; 2880 2881 int uwsgi_setup_snmp(void); 2882 2883 struct uwsgi_snmp_server_value { 2884 uint8_t type; 2885 uint64_t *val; 2886 }; 2887 2888 struct uwsgi_cron { 2889 2890 int minute; 2891 int hour; 2892 int day; 2893 int month; 2894 int week; 2895 2896 time_t last_job; 2897 uint8_t sig; 2898 2899 char *command; 2900 void (*func)(struct uwsgi_cron *, time_t); 2901 2902 time_t started_at; 2903 2904 // next harakiri timestamp 2905 time_t harakiri; 2906 // number of seconds to wait before calling harakiri on cron 2907 int mercy; 2908 2909 uint8_t unique; 2910 pid_t pid; 2911 2912 struct uwsgi_cron *next; 2913 2914 #ifdef UWSGI_SSL 2915 char *legion; 2916 #endif 2917 }; 2918 2919 struct uwsgi_shared { 2920 2921 //vga 80 x25 specific ! 2922 char warning_message[81]; 2923 2924 off_t logsize; 2925 2926 char snmp_community[72 + 1]; 2927 struct uwsgi_snmp_server_value snmp_gvalue[100]; 2928 struct uwsgi_snmp_custom_value snmp_value[100]; 2929 2930 int worker_signal_pipe[2]; 2931 int spooler_frequency; 2932 int spooler_signal_pipe[2]; 2933 int mule_signal_pipe[2]; 2934 int mule_queue_pipe[2]; 2935 2936 // 256 items * (uwsgi.numproc + 1) 2937 struct uwsgi_signal_entry *signal_table; 2938 2939 struct uwsgi_fmon files_monitored[64]; 2940 int files_monitored_cnt; 2941 2942 struct uwsgi_timer timers[MAX_TIMERS]; 2943 int timers_cnt; 2944 2945 struct uwsgi_signal_rb_timer rb_timers[MAX_TIMERS]; 2946 int rb_timers_cnt; 2947 2948 uint64_t *rpc_count; 2949 2950 int worker_log_pipe[2]; 2951 // used for request logging 2952 int worker_req_log_pipe[2]; 2953 2954 uint64_t load; 2955 uint64_t max_load; 2956 struct uwsgi_cron cron[MAX_CRONS]; 2957 int cron_cnt; 2958 2959 uint64_t backlog; 2960 uint64_t backlog_errors; 2961 2962 // gateways 2963 struct uwsgi_gateway gateways[MAX_GATEWAYS]; 2964 int gateways_cnt; 2965 time_t gateways_harakiri[MAX_GATEWAYS]; 2966 2967 uint64_t routed_signals; 2968 uint64_t unrouted_signals; 2969 2970 uint64_t busy_workers; 2971 uint64_t idle_workers; 2972 uint64_t overloaded; 2973 2974 int ready; 2975 }; 2976 2977 struct uwsgi_core { 2978 2979 //time_t harakiri; 2980 2981 uint64_t requests; 2982 uint64_t failed_requests; 2983 uint64_t static_requests; 2984 uint64_t routed_requests; 2985 uint64_t offloaded_requests; 2986 2987 uint64_t write_errors; 2988 uint64_t read_errors; 2989 uint64_t exceptions; 2990 2991 pthread_t thread_id; 2992 2993 int offload_rr; 2994 2995 // one ts-perapp 2996 void **ts; 2997 2998 int in_request; 2999 3000 char *buffer; 3001 struct iovec *hvec; 3002 char *post_buf; 3003 3004 struct wsgi_request req; 3005 }; 3006 3007 struct uwsgi_worker { 3008 int id; 3009 pid_t pid; 3010 3011 uint64_t status; 3012 3013 time_t last_spawn; 3014 uint64_t respawn_count; 3015 3016 uint64_t requests; 3017 uint64_t delta_requests; 3018 uint64_t failed_requests; 3019 3020 time_t harakiri; 3021 time_t user_harakiri; 3022 uint64_t harakiri_count; 3023 int pending_harakiri; 3024 3025 uint64_t vsz_size; 3026 uint64_t rss_size; 3027 3028 uint64_t running_time; 3029 3030 int manage_next_request; 3031 3032 int destroy; 3033 3034 int apps_cnt; 3035 struct uwsgi_app *apps; 3036 3037 uint64_t tx; 3038 3039 int hijacked; 3040 uint64_t hijacked_count; 3041 int cheaped; 3042 int suspended; 3043 int sig; 3044 uint8_t signum; 3045 3046 time_t cursed_at; 3047 time_t no_mercy_at; 3048 3049 // signals managed by this worker 3050 uint64_t signals; 3051 3052 int signal_pipe[2]; 3053 3054 uint64_t avg_response_time; 3055 3056 struct uwsgi_core *cores; 3057 3058 int accepting; 3059 3060 char name[0xff]; 3061 3062 int shutdown_sockets; 3063 }; 3064 3065 3066 struct uwsgi_mule { 3067 int id; 3068 pid_t pid; 3069 3070 int signal_pipe[2]; 3071 int queue_pipe[2]; 3072 3073 time_t last_spawn; 3074 uint64_t respawn_count; 3075 3076 char *patch; 3077 3078 // signals managed by this mule 3079 uint64_t signals; 3080 int sig; 3081 uint8_t signum; 3082 3083 time_t harakiri; 3084 time_t user_harakiri; 3085 3086 char name[0xff]; 3087 3088 time_t cursed_at; 3089 time_t no_mercy_at; 3090 }; 3091 3092 struct uwsgi_mule_farm { 3093 struct uwsgi_mule *mule; 3094 struct uwsgi_mule_farm *next; 3095 }; 3096 3097 struct uwsgi_farm { 3098 int id; 3099 char name[0xff]; 3100 3101 int signal_pipe[2]; 3102 int queue_pipe[2]; 3103 3104 struct uwsgi_mule_farm *mules; 3105 3106 }; 3107 3108 3109 3110 char *uwsgi_get_cwd(void); 3111 3112 void warn_pipe(void); 3113 void what_i_am_doing(void); 3114 void goodbye_cruel_world(void); 3115 void gracefully_kill(int); 3116 void reap_them_all(int); 3117 void kill_them_all(int); 3118 void grace_them_all(int); 3119 void end_me(int); 3120 int bind_to_unix(char *, int, int, int); 3121 int bind_to_tcp(char *, int, char *); 3122 int bind_to_udp(char *, int, int); 3123 int bind_to_unix_dgram(char *); 3124 int timed_connect(struct pollfd *, const struct sockaddr *, int, int, int); 3125 int uwsgi_connect(char *, int, int); 3126 int uwsgi_connect_udp(char *); 3127 int uwsgi_connectn(char *, uint16_t, int, int); 3128 3129 void daemonize(char *); 3130 void logto(char *); 3131 3132 void log_request(struct wsgi_request *); 3133 void get_memusage(uint64_t *, uint64_t *); 3134 void harakiri(void); 3135 3136 void stats(int); 3137 3138 #ifdef UWSGI_XML 3139 void uwsgi_xml_config(char *, struct wsgi_request *, char *[]); 3140 #endif 3141 3142 void uwsgi_500(struct wsgi_request *); 3143 void uwsgi_403(struct wsgi_request *); 3144 void uwsgi_404(struct wsgi_request *); 3145 void uwsgi_405(struct wsgi_request *); 3146 void uwsgi_redirect_to_slash(struct wsgi_request *); 3147 3148 void manage_snmp(int, uint8_t *, int, struct sockaddr_in *); 3149 void snmp_init(void); 3150 3151 void uwsgi_master_manage_snmp(int); 3152 3153 char *uwsgi_spool_request(struct wsgi_request *, char *, size_t, char *, size_t); 3154 void spooler(struct uwsgi_spooler *); 3155 pid_t spooler_start(struct uwsgi_spooler *); 3156 3157 int uwsgi_spooler_read_header(char *, int, struct uwsgi_header *); 3158 int uwsgi_spooler_read_content(int, char *, char **, size_t *, struct uwsgi_header *, struct stat *); 3159 3160 #if defined(_GNU_SOURCE) || defined(__UCLIBC__) 3161 #define uwsgi_versionsort versionsort 3162 #else 3163 int uwsgi_versionsort(const struct dirent **da, const struct dirent **db); 3164 #endif 3165 3166 void uwsgi_curse(int, int); 3167 void uwsgi_curse_mule(int, int); 3168 void uwsgi_destroy_processes(void); 3169 3170 void set_harakiri(int); 3171 void set_user_harakiri(int); 3172 void set_mule_harakiri(int); 3173 void set_spooler_harakiri(int); 3174 void inc_harakiri(int); 3175 3176 #ifdef __BIG_ENDIAN__ 3177 uint16_t uwsgi_swap16(uint16_t); 3178 uint32_t uwsgi_swap32(uint32_t); 3179 uint64_t uwsgi_swap64(uint64_t); 3180 #endif 3181 3182 int uwsgi_parse_request(int, struct wsgi_request *, int); 3183 int uwsgi_parse_vars(struct wsgi_request *); 3184 3185 int uwsgi_enqueue_message(char *, int, uint8_t, uint8_t, char *, int, int); 3186 3187 void manage_opt(int, char *); 3188 3189 int uwsgi_ping_node(int, struct wsgi_request *); 3190 3191 void uwsgi_async_init(void); 3192 void async_loop(); 3193 struct wsgi_request *find_first_available_wsgi_req(void); 3194 struct wsgi_request *find_first_accepting_wsgi_req(void); 3195 struct wsgi_request *find_wsgi_req_by_fd(int); 3196 struct wsgi_request *find_wsgi_req_by_id(int); 3197 void async_schedule_to_req_green(void); 3198 void async_schedule_to_req(void); 3199 3200 int async_add_fd_write(struct wsgi_request *, int, int); 3201 int async_add_fd_read(struct wsgi_request *, int, int); 3202 void async_reset_request(struct wsgi_request *); 3203 3204 struct wsgi_request *next_wsgi_req(struct wsgi_request *); 3205 3206 3207 void async_add_timeout(struct wsgi_request *, int); 3208 3209 void uwsgi_as_root(void); 3210 3211 void uwsgi_close_request(struct wsgi_request *); 3212 3213 void wsgi_req_setup(struct wsgi_request *, int, struct uwsgi_socket *); 3214 int wsgi_req_recv(int, struct wsgi_request *); 3215 int wsgi_req_async_recv(struct wsgi_request *); 3216 int wsgi_req_accept(int, struct wsgi_request *); 3217 int wsgi_req_simple_accept(struct wsgi_request *, int); 3218 3219 #define current_wsgi_req() (*uwsgi.current_wsgi_req)() 3220 3221 void sanitize_args(void); 3222 3223 void env_to_arg(char *, char *); 3224 void parse_sys_envs(char **); 3225 3226 void uwsgi_log(const char *, ...); 3227 void uwsgi_log_verbose(const char *, ...); 3228 void uwsgi_logfile_write(const char *, ...); 3229 3230 3231 void *uwsgi_load_plugin(int, char *, char *); 3232 3233 int unconfigured_hook(struct wsgi_request *); 3234 3235 void uwsgi_ini_config(char *, char *[]); 3236 3237 #ifdef UWSGI_YAML 3238 void uwsgi_yaml_config(char *, char *[]); 3239 #endif 3240 3241 #ifdef UWSGI_JSON 3242 void uwsgi_json_config(char *, char *[]); 3243 #endif 3244 3245 int uwsgi_strncmp(char *, int, char *, int); 3246 int uwsgi_strnicmp(char *, int, char *, int); 3247 int uwsgi_startswith(char *, char *, int); 3248 3249 3250 char *uwsgi_concat(int, ...); 3251 char *uwsgi_concatn(int, ...); 3252 char *uwsgi_concat2(char *, char *); 3253 char *uwsgi_concat2n(char *, int, char *, int); 3254 char *uwsgi_concat2nn(char *, int, char *, int, int *); 3255 char *uwsgi_concat3(char *, char *, char *); 3256 char *uwsgi_concat3n(char *, int, char *, int, char *, int); 3257 char *uwsgi_concat4(char *, char *, char *, char *); 3258 char *uwsgi_concat4n(char *, int, char *, int, char *, int, char *, int); 3259 3260 3261 int uwsgi_get_app_id(struct wsgi_request *, char *, uint16_t, int); 3262 char *uwsgi_strncopy(char *, int); 3263 3264 int master_loop(char **, char **); 3265 3266 int find_worker_id(pid_t); 3267 3268 3269 void simple_loop(); 3270 void *simple_loop_run(void *); 3271 3272 int uwsgi_count_options(struct uwsgi_option *); 3273 3274 struct wsgi_request *simple_current_wsgi_req(void); 3275 struct wsgi_request *threaded_current_wsgi_req(void); 3276 3277 void build_options(void); 3278 3279 int uwsgi_postbuffer_do_in_disk(struct wsgi_request *); 3280 int uwsgi_postbuffer_do_in_mem(struct wsgi_request *); 3281 3282 void uwsgi_register_loop(char *, void (*)(void)); 3283 void *uwsgi_get_loop(char *); 3284 3285 void add_exported_option(char *, char *, int); 3286 void add_exported_option_do(char *, char *, int, int); 3287 3288 ssize_t uwsgi_send_empty_pkt(int, char *, uint8_t, uint8_t); 3289 3290 int uwsgi_waitfd_event(int, int, int); 3291 #define uwsgi_waitfd(a, b) uwsgi_waitfd_event(a, b, POLLIN) 3292 #define uwsgi_waitfd_write(a, b) uwsgi_waitfd_event(a, b, POLLOUT) 3293 3294 int uwsgi_hooked_parse_dict_dgram(int, char *, size_t, uint8_t, uint8_t, void (*)(char *, uint16_t, char *, uint16_t, void *), void *); 3295 int uwsgi_hooked_parse(char *, size_t, void (*)(char *, uint16_t, char *, uint16_t, void *), void *); 3296 int uwsgi_hooked_parse_array(char *, size_t, void (*) (uint16_t, char *, uint16_t, void *), void *); 3297 3298 int uwsgi_get_dgram(int, struct wsgi_request *); 3299 3300 int uwsgi_string_sendto(int, uint8_t, uint8_t, struct sockaddr *, socklen_t, char *, size_t); 3301 3302 void uwsgi_stdin_sendto(char *, uint8_t, uint8_t); 3303 3304 char *generate_socket_name(char *); 3305 3306 #define UMIN(a,b) ((a)>(b)?(b):(a)) 3307 #define UMAX(a,b) ((a)<(b)?(b):(a)) 3308 3309 ssize_t uwsgi_send_message(int, uint8_t, uint8_t, char *, uint16_t, int, ssize_t, int); 3310 3311 int uwsgi_cache_set2(struct uwsgi_cache *, char *, uint16_t, char *, uint64_t, uint64_t, uint64_t); 3312 int uwsgi_cache_del2(struct uwsgi_cache *, char *, uint16_t, uint64_t, uint16_t); 3313 char *uwsgi_cache_get2(struct uwsgi_cache *, char *, uint16_t, uint64_t *); 3314 char *uwsgi_cache_get3(struct uwsgi_cache *, char *, uint16_t, uint64_t *, uint64_t *); 3315 char *uwsgi_cache_get4(struct uwsgi_cache *, char *, uint16_t, uint64_t *, uint64_t *); 3316 uint32_t uwsgi_cache_exists2(struct uwsgi_cache *, char *, uint16_t); 3317 struct uwsgi_cache *uwsgi_cache_create(char *); 3318 struct uwsgi_cache *uwsgi_cache_by_name(char *); 3319 struct uwsgi_cache *uwsgi_cache_by_namelen(char *, uint16_t); 3320 void uwsgi_cache_create_all(void); 3321 void uwsgi_cache_sync_from_nodes(struct uwsgi_cache *); 3322 void uwsgi_cache_setup_nodes(struct uwsgi_cache *); 3323 int64_t uwsgi_cache_num2(struct uwsgi_cache *, char *, uint16_t); 3324 3325 void uwsgi_cache_sync_all(void); 3326 void uwsgi_cache_start_sweepers(void); 3327 void uwsgi_cache_start_sync_servers(void); 3328 3329 3330 void *uwsgi_malloc(size_t); 3331 void *uwsgi_calloc(size_t); 3332 3333 3334 int event_queue_init(void); 3335 void *event_queue_alloc(int); 3336 int event_queue_add_fd_read(int, int); 3337 int event_queue_add_fd_write(int, int); 3338 int event_queue_del_fd(int, int, int); 3339 int event_queue_wait(int, int, int *); 3340 int event_queue_wait_multi(int, int, void *, int); 3341 int event_queue_interesting_fd(void *, int); 3342 int event_queue_interesting_fd_has_error(void *, int); 3343 int event_queue_fd_write_to_read(int, int); 3344 int event_queue_fd_read_to_write(int, int); 3345 int event_queue_fd_readwrite_to_read(int, int); 3346 int event_queue_fd_readwrite_to_write(int, int); 3347 int event_queue_fd_read_to_readwrite(int, int); 3348 int event_queue_fd_write_to_readwrite(int, int); 3349 int event_queue_interesting_fd_is_read(void *, int); 3350 int event_queue_interesting_fd_is_write(void *, int); 3351 3352 int event_queue_add_timer(int, int *, int); 3353 struct uwsgi_timer *event_queue_ack_timer(int); 3354 3355 int event_queue_add_file_monitor(int, char *, int *); 3356 struct uwsgi_fmon *event_queue_ack_file_monitor(int, int); 3357 3358 3359 int uwsgi_register_signal(uint8_t, char *, void *, uint8_t); 3360 int uwsgi_add_file_monitor(uint8_t, char *); 3361 int uwsgi_add_timer(uint8_t, int); 3362 int uwsgi_signal_add_rb_timer(uint8_t, int, int); 3363 int uwsgi_signal_handler(uint8_t); 3364 3365 void uwsgi_route_signal(uint8_t); 3366 3367 int uwsgi_start(void *); 3368 3369 int uwsgi_register_rpc(char *, struct uwsgi_plugin *, uint8_t, void *); 3370 uint64_t uwsgi_rpc(char *, uint8_t, char **, uint16_t *, char **); 3371 char *uwsgi_do_rpc(char *, char *, uint8_t, char **, uint16_t *, uint64_t *); 3372 void uwsgi_rpc_init(void); 3373 3374 char *uwsgi_cheap_string(char *, int); 3375 3376 int uwsgi_parse_array(char *, uint16_t, char **, uint16_t *, uint8_t *); 3377 3378 3379 struct uwsgi_gateway *register_gateway(char *, void (*)(int, void *), void *); 3380 void gateway_respawn(int); 3381 3382 void uwsgi_gateway_go_cheap(char *, int, int *); 3383 3384 char *uwsgi_open_and_read(char *, size_t *, int, char *[]); 3385 char *uwsgi_get_last_char(char *, char); 3386 char *uwsgi_get_last_charn(char *, size_t, char); 3387 3388 void uwsgi_spawn_daemon(struct uwsgi_daemon *); 3389 void uwsgi_detach_daemons(); 3390 3391 void emperor_loop(void); 3392 char *uwsgi_num2str(int); 3393 char *uwsgi_float2str(float); 3394 char *uwsgi_64bit2str(int64_t); 3395 char *uwsgi_size2str(size_t); 3396 3397 char *magic_sub(char *, size_t, size_t *, char *[]); 3398 void init_magic_table(char *[]); 3399 3400 char *uwsgi_req_append(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 3401 int uwsgi_req_append_path_info_with_index(struct wsgi_request *, char *, uint16_t); 3402 int is_unix(char *, int); 3403 int is_a_number(char *); 3404 3405 char *uwsgi_resolve_ip(char *); 3406 3407 void uwsgi_init_queue(void); 3408 char *uwsgi_queue_get(uint64_t, uint64_t *); 3409 char *uwsgi_queue_pull(uint64_t *); 3410 int uwsgi_queue_push(char *, uint64_t); 3411 char *uwsgi_queue_pop(uint64_t *); 3412 int uwsgi_queue_set(uint64_t, char *, uint64_t); 3413 3414 3415 struct uwsgi_subscribe_req { 3416 char *key; 3417 uint16_t keylen; 3418 3419 char *address; 3420 uint16_t address_len; 3421 3422 char *auth; 3423 uint16_t auth_len; 3424 3425 uint8_t modifier1; 3426 uint8_t modifier2; 3427 3428 uint64_t cores; 3429 uint64_t load; 3430 uint64_t weight; 3431 char *sign; 3432 uint16_t sign_len; 3433 3434 time_t unix_check; 3435 3436 char *base; 3437 uint16_t base_len; 3438 3439 char *sni_key; 3440 uint16_t sni_key_len; 3441 3442 char *sni_crt; 3443 uint16_t sni_crt_len; 3444 3445 char *sni_ca; 3446 uint16_t sni_ca_len; 3447 3448 pid_t pid; 3449 uid_t uid; 3450 gid_t gid; 3451 3452 char *notify; 3453 uint16_t notify_len; 3454 }; 3455 3456 void uwsgi_nuclear_blast(); 3457 3458 void uwsgi_unix_signal(int, void (*)(int)); 3459 3460 char *uwsgi_get_exported_opt(char *); 3461 char *uwsgi_manage_placeholder(char *); 3462 3463 int uwsgi_signal_add_cron(uint8_t, int, int, int, int, int); 3464 int uwsgi_cron_task_needs_execution(struct tm *, int, int, int, int, int); 3465 3466 char *uwsgi_get_optname_by_index(int); 3467 3468 int uwsgi_list_has_num(char *, int); 3469 3470 int uwsgi_list_has_str(char *, char *); 3471 3472 void uwsgi_cache_fix(struct uwsgi_cache *); 3473 3474 struct uwsgi_async_request { 3475 3476 struct wsgi_request *wsgi_req; 3477 struct uwsgi_async_request *prev; 3478 struct uwsgi_async_request *next; 3479 }; 3480 3481 int event_queue_read(void); 3482 int event_queue_write(void); 3483 3484 void uwsgi_help(char *, char *, void *); 3485 void uwsgi_print_sym(char *, char *, void *); 3486 3487 int uwsgi_str2_num(char *); 3488 int uwsgi_str3_num(char *); 3489 int uwsgi_str4_num(char *); 3490 3491 #ifdef __linux__ 3492 #if !defined(__ia64__) 3493 void linux_namespace_start(void *); 3494 void linux_namespace_jail(void); 3495 #endif 3496 void uwsgi_master_manage_setns(int); 3497 void uwsgi_setns(char *); 3498 void uwsgi_setns_preopen(void); 3499 #endif 3500 3501 3502 int uwsgi_amqp_consume_queue(int, char *, char *, char *, char *, char *, char *); 3503 char *uwsgi_amqp_consume(int, uint64_t *, char **); 3504 3505 int uwsgi_file_serve(struct wsgi_request *, char *, uint16_t, char *, uint16_t, int); 3506 int uwsgi_starts_with(char *, int, char *, int); 3507 int uwsgi_static_want_gzip(struct wsgi_request *, char *, size_t *, struct stat *); 3508 3509 #ifdef __sun__ 3510 time_t timegm(struct tm *); 3511 #endif 3512 3513 uint64_t uwsgi_str_num(char *, int); 3514 size_t uwsgi_str_occurence(char *, size_t, char); 3515 3516 int uwsgi_proto_base_write(struct wsgi_request *, char *, size_t); 3517 int uwsgi_proto_base_writev(struct wsgi_request *, struct iovec *, size_t *); 3518 #ifdef UWSGI_SSL 3519 int uwsgi_proto_ssl_write(struct wsgi_request *, char *, size_t); 3520 #endif 3521 int uwsgi_proto_base_write_header(struct wsgi_request *, char *, size_t); 3522 ssize_t uwsgi_proto_base_read_body(struct wsgi_request *, char *, size_t); 3523 ssize_t uwsgi_proto_noop_read_body(struct wsgi_request *, char *, size_t); 3524 #ifdef UWSGI_SSL 3525 ssize_t uwsgi_proto_ssl_read_body(struct wsgi_request *, char *, size_t); 3526 #endif 3527 3528 3529 int uwsgi_proto_base_accept(struct wsgi_request *, int); 3530 void uwsgi_proto_base_close(struct wsgi_request *); 3531 #ifdef UWSGI_SSL 3532 int uwsgi_proto_ssl_accept(struct wsgi_request *, int); 3533 void uwsgi_proto_ssl_close(struct wsgi_request *); 3534 #endif 3535 uint16_t proto_base_add_uwsgi_header(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 3536 uint16_t proto_base_add_uwsgi_var(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 3537 3538 // protocols 3539 void uwsgi_proto_uwsgi_setup(struct uwsgi_socket *); 3540 void uwsgi_proto_puwsgi_setup(struct uwsgi_socket *); 3541 void uwsgi_proto_raw_setup(struct uwsgi_socket *); 3542 void uwsgi_proto_http_setup(struct uwsgi_socket *); 3543 void uwsgi_proto_http11_setup(struct uwsgi_socket *); 3544 #ifdef UWSGI_SSL 3545 void uwsgi_proto_https_setup(struct uwsgi_socket *); 3546 void uwsgi_proto_suwsgi_setup(struct uwsgi_socket *); 3547 #endif 3548 #ifdef UWSGI_ZEROMQ 3549 void uwsgi_proto_zmq_setup(struct uwsgi_socket *); 3550 #endif 3551 void uwsgi_proto_fastcgi_setup(struct uwsgi_socket *); 3552 void uwsgi_proto_fastcgi_nph_setup(struct uwsgi_socket *); 3553 3554 void uwsgi_proto_scgi_setup(struct uwsgi_socket *); 3555 void uwsgi_proto_scgi_nph_setup(struct uwsgi_socket *); 3556 3557 int uwsgi_num2str2(int, char *); 3558 3559 3560 void uwsgi_add_socket_from_fd(struct uwsgi_socket *, int); 3561 3562 3563 char *uwsgi_split3(char *, size_t, char, char **, size_t *, char **, size_t *, char **, size_t *); 3564 char *uwsgi_split4(char *, size_t, char, char **, size_t *, char **, size_t *, char **, size_t *, char **, size_t *); 3565 char *uwsgi_netstring(char *, size_t, char **, size_t *); 3566 3567 char *uwsgi_str_split_nget(char *, size_t, char, size_t, size_t *); 3568 3569 int uwsgi_get_socket_num(struct uwsgi_socket *); 3570 struct uwsgi_socket *uwsgi_new_socket(char *); 3571 struct uwsgi_socket *uwsgi_new_shared_socket(char *); 3572 struct uwsgi_socket *uwsgi_del_socket(struct uwsgi_socket *); 3573 3574 void uwsgi_close_all_sockets(void); 3575 void uwsgi_shutdown_all_sockets(void); 3576 void uwsgi_close_all_unshared_sockets(void); 3577 3578 struct uwsgi_string_list *uwsgi_string_new_list(struct uwsgi_string_list **, char *); 3579 #ifdef UWSGI_PCRE 3580 struct uwsgi_regexp_list *uwsgi_regexp_custom_new_list(struct uwsgi_regexp_list **, char *, char *); 3581 #define uwsgi_regexp_new_list(x, y) uwsgi_regexp_custom_new_list(x, y, NULL); 3582 #endif 3583 3584 void uwsgi_string_del_list(struct uwsgi_string_list **, struct uwsgi_string_list *); 3585 3586 void uwsgi_init_all_apps(void); 3587 void uwsgi_init_worker_mount_apps(void); 3588 void uwsgi_socket_nb(int); 3589 void uwsgi_socket_b(int); 3590 int uwsgi_write_nb(int, char *, size_t, int); 3591 int uwsgi_read_nb(int, char *, size_t, int); 3592 ssize_t uwsgi_read_true_nb(int, char *, size_t, int); 3593 int uwsgi_read_whole_true_nb(int, char *, size_t, int); 3594 int uwsgi_read_uh(int fd, struct uwsgi_header *, int); 3595 int uwsgi_proxy_nb(struct wsgi_request *, char *, struct uwsgi_buffer *, size_t, int); 3596 3597 int uwsgi_read_with_realloc(int, char **, size_t *, int, uint8_t *, uint8_t *); 3598 int uwsgi_write_true_nb(int, char *, size_t, int); 3599 3600 void uwsgi_destroy_request(struct wsgi_request *); 3601 3602 void uwsgi_systemd_init(char *); 3603 3604 void uwsgi_sig_pause(void); 3605 3606 void uwsgi_ignition(void); 3607 3608 int uwsgi_respawn_worker(int); 3609 3610 socklen_t socket_to_in_addr(char *, char *, int, struct sockaddr_in *); 3611 socklen_t socket_to_un_addr(char *, struct sockaddr_un *); 3612 socklen_t socket_to_in_addr6(char *, char *, int, struct sockaddr_in6 *); 3613 3614 int uwsgi_get_shared_socket_fd_by_num(int); 3615 struct uwsgi_socket *uwsgi_get_shared_socket_by_num(int); 3616 3617 struct uwsgi_socket *uwsgi_get_socket_by_num(int); 3618 3619 int uwsgi_get_shared_socket_num(struct uwsgi_socket *); 3620 3621 #ifdef __linux__ 3622 void uwsgi_set_cgroup(void); 3623 long uwsgi_num_from_file(char *, int); 3624 #endif 3625 3626 void uwsgi_add_sockets_to_queue(int, int); 3627 void uwsgi_del_sockets_from_queue(int); 3628 3629 int uwsgi_run_command_and_wait(char *, char *); 3630 int uwsgi_run_command_putenv_and_wait(char *, char *, char **, unsigned int); 3631 int uwsgi_call_symbol(char *); 3632 3633 void uwsgi_manage_signal_cron(time_t); 3634 pid_t uwsgi_run_command(char *, int *, int); 3635 3636 void uwsgi_manage_command_cron(time_t); 3637 3638 int *uwsgi_attach_fd(int, int *, char *, size_t); 3639 3640 int uwsgi_count_sockets(struct uwsgi_socket *); 3641 int uwsgi_file_exists(char *); 3642 3643 int uwsgi_signal_registered(uint8_t); 3644 3645 int uwsgi_endswith(char *, char *); 3646 3647 3648 void uwsgi_chown(char *, char *); 3649 3650 char *uwsgi_get_binary_path(char *); 3651 3652 char *uwsgi_lower(char *, size_t); 3653 int uwsgi_num2str2n(int, char *, int); 3654 void create_logpipe(void); 3655 3656 char *uwsgi_str_contains(char *, int, char); 3657 3658 int uwsgi_simple_parse_vars(struct wsgi_request *, char *, char *); 3659 3660 void uwsgi_build_mime_dict(char *); 3661 struct uwsgi_dyn_dict *uwsgi_dyn_dict_new(struct uwsgi_dyn_dict **, char *, int, char *, int); 3662 void uwsgi_dyn_dict_del(struct uwsgi_dyn_dict *); 3663 3664 3665 void uwsgi_apply_config_pass(char symbol, char *(*)(char *)); 3666 3667 void uwsgi_mule(int); 3668 3669 char *uwsgi_string_get_list(struct uwsgi_string_list **, int, size_t *); 3670 3671 void uwsgi_fixup_fds(int, int, struct uwsgi_gateway *); 3672 3673 void uwsgi_set_processname(char *); 3674 3675 void http_url_decode(char *, uint16_t *, char *); 3676 void http_url_encode(char *, uint16_t *, char *); 3677 3678 pid_t uwsgi_fork(char *); 3679 3680 struct uwsgi_mule *get_mule_by_id(int); 3681 struct uwsgi_mule_farm *uwsgi_mule_farm_new(struct uwsgi_mule_farm **, struct uwsgi_mule *); 3682 3683 int uwsgi_farm_has_mule(struct uwsgi_farm *, int); 3684 struct uwsgi_farm *get_farm_by_name(char *); 3685 3686 3687 struct uwsgi_subscribe_node { 3688 3689 char name[0xff]; 3690 uint16_t len; 3691 uint8_t modifier1; 3692 uint8_t modifier2; 3693 3694 time_t last_check; 3695 3696 // absolute number of requests 3697 uint64_t requests; 3698 // number of requests since last subscription ping 3699 uint64_t last_requests; 3700 3701 uint64_t tx; 3702 uint64_t rx; 3703 3704 int death_mark; 3705 uint64_t reference; 3706 uint64_t cores; 3707 uint64_t load; 3708 uint64_t failcnt; 3709 3710 uint64_t weight; 3711 uint64_t wrr; 3712 3713 time_t unix_check; 3714 3715 // used by unix credentials 3716 pid_t pid; 3717 uid_t uid; 3718 gid_t gid; 3719 3720 char notify[102]; 3721 3722 struct uwsgi_subscribe_slot *slot; 3723 3724 struct uwsgi_subscribe_node *next; 3725 }; 3726 3727 struct uwsgi_subscribe_slot { 3728 3729 char key[0xff]; 3730 uint16_t keylen; 3731 3732 uint32_t hash; 3733 3734 uint64_t hits; 3735 3736 struct uwsgi_subscribe_node *nodes; 3737 3738 struct uwsgi_subscribe_slot *prev; 3739 struct uwsgi_subscribe_slot *next; 3740 3741 #ifdef UWSGI_SSL 3742 EVP_PKEY *sign_public_key; 3743 EVP_MD_CTX *sign_ctx; 3744 uint8_t sni_enabled; 3745 #endif 3746 3747 }; 3748 3749 int mule_send_msg(int, char *, size_t); 3750 3751 uint32_t djb33x_hash(char *, uint64_t); 3752 void create_signal_pipe(int *); 3753 void create_msg_pipe(int *, int); 3754 struct uwsgi_subscribe_slot *uwsgi_get_subscribe_slot(struct uwsgi_subscribe_slot **, char *, uint16_t); 3755 struct uwsgi_subscribe_node *uwsgi_get_subscribe_node_by_name(struct uwsgi_subscribe_slot **, char *, uint16_t, char *, uint16_t); 3756 struct uwsgi_subscribe_node *uwsgi_get_subscribe_node(struct uwsgi_subscribe_slot **, char *, uint16_t); 3757 int uwsgi_remove_subscribe_node(struct uwsgi_subscribe_slot **, struct uwsgi_subscribe_node *); 3758 struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slot **, struct uwsgi_subscribe_req *); 3759 3760 ssize_t uwsgi_mule_get_msg(int, int, char *, size_t, int); 3761 3762 int uwsgi_signal_wait(int); 3763 struct uwsgi_app *uwsgi_add_app(int, uint8_t, char *, int, void *, void *); 3764 int uwsgi_signal_send(int, uint8_t); 3765 int uwsgi_remote_signal_send(char *, uint8_t); 3766 3767 void uwsgi_configure(); 3768 3769 int uwsgi_read_response(int, struct uwsgi_header *, int, char **); 3770 char *uwsgi_simple_file_read(char *); 3771 3772 void uwsgi_send_subscription(char *, char *, size_t, uint8_t, uint8_t, uint8_t, char *, char *, char *, char *, char *); 3773 void uwsgi_send_subscription_from_fd(int, char *, char *, size_t, uint8_t, uint8_t, uint8_t, char *, char *, char *, char *, char *); 3774 3775 void uwsgi_subscribe(char *, uint8_t); 3776 void uwsgi_subscribe2(char *, uint8_t); 3777 3778 int uwsgi_is_bad_connection(int); 3779 int uwsgi_long2str2n(unsigned long long, char *, int); 3780 3781 #ifdef __linux__ 3782 void uwsgi_build_unshare(char *, int *); 3783 #ifdef MADV_MERGEABLE 3784 void uwsgi_linux_ksm_map(void); 3785 #endif 3786 #endif 3787 3788 #ifdef UWSGI_CAP 3789 int uwsgi_build_cap(char *, cap_value_t **); 3790 void uwsgi_apply_cap(cap_value_t *, int); 3791 #endif 3792 3793 void uwsgi_register_logger(char *, ssize_t(*func) (struct uwsgi_logger *, char *, size_t)); 3794 void uwsgi_append_logger(struct uwsgi_logger *); 3795 void uwsgi_append_req_logger(struct uwsgi_logger *); 3796 struct uwsgi_logger *uwsgi_get_logger(char *); 3797 struct uwsgi_logger *uwsgi_get_logger_from_id(char *); 3798 3799 char *uwsgi_getsockname(int); 3800 char *uwsgi_get_var(struct wsgi_request *, char *, uint16_t, uint16_t *); 3801 3802 struct uwsgi_gateway_socket *uwsgi_new_gateway_socket(char *, char *); 3803 struct uwsgi_gateway_socket *uwsgi_new_gateway_socket_from_fd(int, char *); 3804 3805 void escape_shell_arg(char *, size_t, char *); 3806 void escape_json(char *, size_t, char *); 3807 3808 void *uwsgi_malloc_shared(size_t); 3809 void *uwsgi_calloc_shared(size_t); 3810 3811 struct uwsgi_spooler *uwsgi_new_spooler(char *); 3812 3813 struct uwsgi_spooler *uwsgi_get_spooler_by_name(char *, size_t); 3814 3815 int uwsgi_zerg_attach(char *); 3816 3817 int uwsgi_manage_opt(char *, char *); 3818 3819 void uwsgi_opt_print(char *, char *, void *); 3820 void uwsgi_opt_true(char *, char *, void *); 3821 void uwsgi_opt_false(char *, char *, void *); 3822 void uwsgi_opt_set_str(char *, char *, void *); 3823 void uwsgi_opt_custom(char *, char *, void *); 3824 void uwsgi_opt_set_null(char *, char *, void *); 3825 void uwsgi_opt_set_logger(char *, char *, void *); 3826 void uwsgi_opt_set_req_logger(char *, char *, void *); 3827 void uwsgi_opt_set_str_spaced(char *, char *, void *); 3828 void uwsgi_opt_add_string_list(char *, char *, void *); 3829 void uwsgi_opt_add_addr_list(char *, char *, void *); 3830 void uwsgi_opt_add_string_list_custom(char *, char *, void *); 3831 void uwsgi_opt_add_dyn_dict(char *, char *, void *); 3832 void uwsgi_opt_binary_append_data(char *, char *, void *); 3833 #ifdef UWSGI_PCRE 3834 void uwsgi_opt_pcre_jit(char *, char *, void *); 3835 void uwsgi_opt_add_regexp_dyn_dict(char *, char *, void *); 3836 void uwsgi_opt_add_regexp_list(char *, char *, void *); 3837 void uwsgi_opt_add_regexp_custom_list(char *, char *, void *); 3838 #endif 3839 void uwsgi_opt_set_int(char *, char *, void *); 3840 void uwsgi_opt_uid(char *, char *, void *); 3841 void uwsgi_opt_gid(char *, char *, void *); 3842 void uwsgi_opt_set_rawint(char *, char *, void *); 3843 void uwsgi_opt_set_16bit(char *, char *, void *); 3844 void uwsgi_opt_set_64bit(char *, char *, void *); 3845 void uwsgi_opt_set_megabytes(char *, char *, void *); 3846 void uwsgi_opt_set_dyn(char *, char *, void *); 3847 void uwsgi_opt_set_placeholder(char *, char *, void *); 3848 void uwsgi_opt_add_shared_socket(char *, char *, void *); 3849 void uwsgi_opt_add_socket(char *, char *, void *); 3850 #ifdef UWSGI_SSL 3851 void uwsgi_opt_add_ssl_socket(char *, char *, void *); 3852 #endif 3853 void uwsgi_opt_add_socket_no_defer(char *, char *, void *); 3854 void uwsgi_opt_add_lazy_socket(char *, char *, void *); 3855 void uwsgi_opt_add_cron(char *, char *, void *); 3856 void uwsgi_opt_add_cron2(char *, char *, void *); 3857 void uwsgi_opt_add_unique_cron(char *, char *, void *); 3858 void uwsgi_opt_load_plugin(char *, char *, void *); 3859 void uwsgi_opt_load_dl(char *, char *, void *); 3860 void uwsgi_opt_load(char *, char *, void *); 3861 void uwsgi_opt_safe_fd(char *, char *, void *); 3862 #ifdef UWSGI_SSL 3863 void uwsgi_opt_add_legion_cron(char *, char *, void *); 3864 void uwsgi_opt_add_unique_legion_cron(char *, char *, void *); 3865 void uwsgi_opt_sni(char *, char *, void *); 3866 struct uwsgi_string_list *uwsgi_ssl_add_sni_item(char *, char *, char *, char *, char *); 3867 void uwsgi_ssl_del_sni_item(char *, uint16_t); 3868 char *uwsgi_write_pem_to_file(char *, char *, size_t, char *); 3869 #endif 3870 void uwsgi_opt_flock(char *, char *, void *); 3871 void uwsgi_opt_flock_wait(char *, char *, void *); 3872 void uwsgi_opt_load_ini(char *, char *, void *); 3873 #ifdef UWSGI_XML 3874 void uwsgi_opt_load_xml(char *, char *, void *); 3875 #endif 3876 #ifdef UWSGI_YAML 3877 void uwsgi_opt_load_yml(char *, char *, void *); 3878 #endif 3879 #ifdef UWSGI_JSON 3880 void uwsgi_opt_load_json(char *, char *, void *); 3881 #endif 3882 3883 void uwsgi_opt_set_umask(char *, char *, void *); 3884 void uwsgi_opt_add_spooler(char *, char *, void *); 3885 void uwsgi_opt_add_daemon(char *, char *, void *); 3886 void uwsgi_opt_add_daemon2(char *, char *, void *); 3887 void uwsgi_opt_set_uid(char *, char *, void *); 3888 void uwsgi_opt_set_gid(char *, char *, void *); 3889 void uwsgi_opt_set_immediate_uid(char *, char *, void *); 3890 void uwsgi_opt_set_immediate_gid(char *, char *, void *); 3891 void uwsgi_opt_set_env(char *, char *, void *); 3892 void uwsgi_opt_unset_env(char *, char *, void *); 3893 void uwsgi_opt_pidfile_signal(char *, char *, void *); 3894 3895 void uwsgi_opt_check_static(char *, char *, void *); 3896 void uwsgi_opt_fileserve_mode(char *, char *, void *); 3897 void uwsgi_opt_static_map(char *, char *, void *); 3898 3899 void uwsgi_opt_add_mule(char *, char *, void *); 3900 void uwsgi_opt_add_mules(char *, char *, void *); 3901 void uwsgi_opt_add_farm(char *, char *, void *); 3902 3903 void uwsgi_opt_signal(char *, char *, void *); 3904 3905 void uwsgi_opt_snmp(char *, char *, void *); 3906 void uwsgi_opt_snmp_community(char *, char *, void *); 3907 3908 void uwsgi_opt_logfile_chmod(char *, char *, void *); 3909 3910 void uwsgi_opt_log_date(char *, char *, void *); 3911 void uwsgi_opt_chmod_socket(char *, char *, void *); 3912 3913 void uwsgi_opt_max_vars(char *, char *, void *); 3914 void uwsgi_opt_deprecated(char *, char *, void *); 3915 3916 void uwsgi_opt_noop(char *, char *, void *); 3917 3918 void uwsgi_opt_logic(char *, char *, void *); 3919 int uwsgi_logic_opt_for(char *, char *); 3920 int uwsgi_logic_opt_for_glob(char *, char *); 3921 int uwsgi_logic_opt_for_times(char *, char *); 3922 int uwsgi_logic_opt_for_readline(char *, char *); 3923 int uwsgi_logic_opt_if_env(char *, char *); 3924 int uwsgi_logic_opt_if_not_env(char *, char *); 3925 int uwsgi_logic_opt_if_opt(char *, char *); 3926 int uwsgi_logic_opt_if_not_opt(char *, char *); 3927 int uwsgi_logic_opt_if_exists(char *, char *); 3928 int uwsgi_logic_opt_if_not_exists(char *, char *); 3929 int uwsgi_logic_opt_if_file(char *, char *); 3930 int uwsgi_logic_opt_if_not_file(char *, char *); 3931 int uwsgi_logic_opt_if_dir(char *, char *); 3932 int uwsgi_logic_opt_if_not_dir(char *, char *); 3933 int uwsgi_logic_opt_if_reload(char *, char *); 3934 int uwsgi_logic_opt_if_not_reload(char *, char *); 3935 int uwsgi_logic_opt_if_plugin(char *, char *); 3936 int uwsgi_logic_opt_if_not_plugin(char *, char *); 3937 int uwsgi_logic_opt_if_hostname(char *, char *); 3938 int uwsgi_logic_opt_if_not_hostname(char *, char *); 3939 int uwsgi_logic_opt_if_hostname_match(char *, char *); 3940 int uwsgi_logic_opt_if_not_hostname_match(char *, char *); 3941 3942 3943 void uwsgi_opt_resolve(char *, char *, void *); 3944 3945 #ifdef UWSGI_CAP 3946 void uwsgi_opt_set_cap(char *, char *, void *); 3947 void uwsgi_opt_set_emperor_cap(char *, char *, void *); 3948 #endif 3949 #ifdef __linux__ 3950 void uwsgi_opt_set_unshare(char *, char *, void *); 3951 #endif 3952 3953 int uwsgi_tmpfd(); 3954 FILE *uwsgi_tmpfile(); 3955 3956 #ifdef UWSGI_ROUTING 3957 struct uwsgi_router *uwsgi_register_router(char *, int (*)(struct uwsgi_route *, char *)); 3958 void uwsgi_opt_add_route(char *, char *, void *); 3959 int uwsgi_apply_routes(struct wsgi_request *); 3960 void uwsgi_apply_final_routes(struct wsgi_request *); 3961 int uwsgi_apply_error_routes(struct wsgi_request *); 3962 int uwsgi_apply_response_routes(struct wsgi_request *); 3963 int uwsgi_apply_routes_do(struct uwsgi_route *, struct wsgi_request *, char *, uint16_t); 3964 void uwsgi_register_embedded_routers(void); 3965 void uwsgi_routing_dump(); 3966 struct uwsgi_buffer *uwsgi_routing_translate(struct wsgi_request *, struct uwsgi_route *, char *, uint16_t, char *, size_t); 3967 int uwsgi_route_api_func(struct wsgi_request *, char *, char *); 3968 struct uwsgi_route_condition *uwsgi_register_route_condition(char *, int (*) (struct wsgi_request *, struct uwsgi_route *)); 3969 void uwsgi_fixup_routes(struct uwsgi_route *); 3970 #endif 3971 3972 void uwsgi_reload(char **); 3973 3974 char *uwsgi_chomp(char *); 3975 char *uwsgi_chomp2(char *); 3976 int uwsgi_file_to_string_list(char *, struct uwsgi_string_list **); 3977 void uwsgi_backtrace(int); 3978 void uwsgi_check_logrotate(void); 3979 char *uwsgi_check_touches(struct uwsgi_string_list *); 3980 3981 void uwsgi_manage_zerg(int, int, int *); 3982 3983 time_t uwsgi_now(void); 3984 3985 int uwsgi_calc_cheaper(void); 3986 int uwsgi_cheaper_algo_spare(int); 3987 int uwsgi_cheaper_algo_backlog(int); 3988 int uwsgi_cheaper_algo_backlog2(int); 3989 int uwsgi_cheaper_algo_manual(int); 3990 3991 int uwsgi_master_log(void); 3992 int uwsgi_master_req_log(void); 3993 void uwsgi_flush_logs(void); 3994 3995 void uwsgi_register_cheaper_algo(char *, int (*)(int)); 3996 3997 void uwsgi_setup_locking(void); 3998 int uwsgi_fcntl_lock(int); 3999 int uwsgi_fcntl_is_locked(int); 4000 4001 void uwsgi_emulate_cow_for_apps(int); 4002 4003 char *uwsgi_read_fd(int, size_t *, int); 4004 4005 void uwsgi_setup_post_buffering(void); 4006 4007 struct uwsgi_lock_item *uwsgi_lock_ipcsem_init(char *); 4008 4009 void uwsgi_write_pidfile(char *); 4010 void uwsgi_write_pidfile_explicit(char *, pid_t); 4011 int uwsgi_write_intfile(char *, int); 4012 4013 void uwsgi_protected_close(int); 4014 ssize_t uwsgi_protected_read(int, void *, size_t); 4015 int uwsgi_socket_uniq(struct uwsgi_socket *, struct uwsgi_socket *); 4016 int uwsgi_socket_is_already_bound(char *name); 4017 4018 char *uwsgi_expand_path(char *, int, char *); 4019 int uwsgi_try_autoload(char *); 4020 4021 uint64_t uwsgi_micros(void); 4022 uint64_t uwsgi_millis(void); 4023 int uwsgi_is_file(char *); 4024 int uwsgi_is_file2(char *, struct stat *); 4025 int uwsgi_is_dir(char *); 4026 int uwsgi_is_link(char *); 4027 4028 void uwsgi_receive_signal(int, char *, int); 4029 void uwsgi_exec_atexit(void); 4030 4031 struct uwsgi_stats { 4032 char *base; 4033 off_t pos; 4034 size_t tabs; 4035 size_t chunk; 4036 size_t size; 4037 int minified; 4038 int dirty; 4039 }; 4040 4041 struct uwsgi_stats_pusher_instance; 4042 4043 struct uwsgi_stats_pusher { 4044 char *name; 4045 void (*func) (struct uwsgi_stats_pusher_instance *, time_t, char *, size_t); 4046 int raw; 4047 struct uwsgi_stats_pusher *next; 4048 }; 4049 4050 struct uwsgi_stats_pusher_instance { 4051 struct uwsgi_stats_pusher *pusher; 4052 char *arg; 4053 void *data; 4054 int raw; 4055 int configured; 4056 int freq; 4057 time_t last_run; 4058 // retries 4059 int needs_retry; 4060 int retries; 4061 int max_retries; 4062 int retry_delay; 4063 time_t next_retry; 4064 4065 struct uwsgi_stats_pusher_instance *next; 4066 }; 4067 4068 struct uwsgi_thread; 4069 void uwsgi_stats_pusher_loop(struct uwsgi_thread *); 4070 4071 void uwsgi_stats_pusher_setup(void); 4072 void uwsgi_send_stats(int, struct uwsgi_stats *(*func) (void)); 4073 struct uwsgi_stats *uwsgi_master_generate_stats(void); 4074 struct uwsgi_stats_pusher * uwsgi_register_stats_pusher(char *, void (*)(struct uwsgi_stats_pusher_instance *, time_t, char *, size_t)); 4075 4076 struct uwsgi_stats *uwsgi_stats_new(size_t); 4077 int uwsgi_stats_symbol(struct uwsgi_stats *, char); 4078 int uwsgi_stats_comma(struct uwsgi_stats *); 4079 int uwsgi_stats_object_open(struct uwsgi_stats *); 4080 int uwsgi_stats_object_close(struct uwsgi_stats *); 4081 int uwsgi_stats_list_open(struct uwsgi_stats *); 4082 int uwsgi_stats_list_close(struct uwsgi_stats *); 4083 int uwsgi_stats_keyval(struct uwsgi_stats *, char *, char *); 4084 int uwsgi_stats_keyval_comma(struct uwsgi_stats *, char *, char *); 4085 int uwsgi_stats_keyvalnum(struct uwsgi_stats *, char *, char *, unsigned long long); 4086 int uwsgi_stats_keyvalnum_comma(struct uwsgi_stats *, char *, char *, unsigned long long); 4087 int uwsgi_stats_keyvaln(struct uwsgi_stats *, char *, char *, int); 4088 int uwsgi_stats_keyvaln_comma(struct uwsgi_stats *, char *, char *, int); 4089 int uwsgi_stats_key(struct uwsgi_stats *, char *); 4090 int uwsgi_stats_keylong(struct uwsgi_stats *, char *, unsigned long long); 4091 int uwsgi_stats_keylong_comma(struct uwsgi_stats *, char *, unsigned long long); 4092 int uwsgi_stats_keyslong(struct uwsgi_stats *, char *, long long); 4093 int uwsgi_stats_keyslong_comma(struct uwsgi_stats *, char *, long long); 4094 int uwsgi_stats_str(struct uwsgi_stats *, char *); 4095 4096 char *uwsgi_substitute(char *, char *, char *); 4097 4098 void uwsgi_opt_add_custom_option(char *, char *, void *); 4099 void uwsgi_opt_cflags(char *, char *, void *); 4100 void uwsgi_opt_build_plugin(char *, char *, void *); 4101 void uwsgi_opt_dot_h(char *, char *, void *); 4102 void uwsgi_opt_config_py(char *, char *, void *); 4103 void uwsgi_opt_connect_and_read(char *, char *, void *); 4104 void uwsgi_opt_extract(char *, char *, void *); 4105 4106 char *uwsgi_get_dot_h(); 4107 char *uwsgi_get_config_py(); 4108 char *uwsgi_get_cflags(); 4109 4110 struct uwsgi_string_list *uwsgi_string_list_has_item(struct uwsgi_string_list *, char *, size_t); 4111 4112 void trigger_harakiri(int); 4113 4114 void uwsgi_setup_systemd(); 4115 void uwsgi_setup_upstart(); 4116 void uwsgi_setup_zerg(); 4117 void uwsgi_setup_inherited_sockets(); 4118 void uwsgi_setup_emperor(); 4119 4120 #ifdef UWSGI_SSL 4121 void uwsgi_ssl_init(void); 4122 SSL_CTX *uwsgi_ssl_new_server_context(char *, char *, char *, char *, char *); 4123 char *uwsgi_rsa_sign(char *, char *, size_t, unsigned int *); 4124 char *uwsgi_sanitize_cert_filename(char *, char *, uint16_t); 4125 void uwsgi_opt_scd(char *, char *, void *); 4126 int uwsgi_subscription_sign_check(struct uwsgi_subscribe_slot *, struct uwsgi_subscribe_req *); 4127 4128 char *uwsgi_sha1(char *, size_t, char *); 4129 char *uwsgi_sha1_2n(char *, size_t, char *, size_t, char *); 4130 char *uwsgi_md5(char *, size_t, char *); 4131 #endif 4132 4133 void uwsgi_opt_ssa(char *, char *, void *); 4134 4135 int uwsgi_no_subscriptions(struct uwsgi_subscribe_slot **); 4136 void uwsgi_deadlock_check(pid_t); 4137 4138 4139 struct uwsgi_logchunk { 4140 char *name; 4141 char *ptr; 4142 size_t len; 4143 int vec; 4144 long pos; 4145 long pos_len; 4146 int type; 4147 int free; 4148 ssize_t(*func) (struct wsgi_request *, char **); 4149 struct uwsgi_logchunk *next; 4150 }; 4151 4152 void uwsgi_build_log_format(char *); 4153 4154 void uwsgi_add_logchunk(int, int, char *, size_t); 4155 struct uwsgi_logchunk *uwsgi_register_logchunk(char *, ssize_t (*)(struct wsgi_request *, char **), int); 4156 4157 void uwsgi_logit_simple(struct wsgi_request *); 4158 void uwsgi_logit_lf(struct wsgi_request *); 4159 void uwsgi_logit_lf_strftime(struct wsgi_request *); 4160 4161 struct uwsgi_logvar *uwsgi_logvar_get(struct wsgi_request *, char *, uint8_t); 4162 void uwsgi_logvar_add(struct wsgi_request *, char *, uint8_t, char *, uint8_t); 4163 4164 // scanners are instances of 'imperial_monitor' 4165 struct uwsgi_emperor_scanner { 4166 char *arg; 4167 int fd; 4168 void *data; 4169 void (*event_func) (struct uwsgi_emperor_scanner *); 4170 struct uwsgi_imperial_monitor *monitor; 4171 struct uwsgi_emperor_scanner *next; 4172 }; 4173 4174 void uwsgi_register_imperial_monitor(char *, void (*)(struct uwsgi_emperor_scanner *), void (*)(struct uwsgi_emperor_scanner *)); 4175 int uwsgi_emperor_is_valid(char *); 4176 4177 // an instance (called vassal) is a uWSGI stack running 4178 // it is identified by the name of its config file 4179 // a vassal is 'loyal' as soon as it manages a request 4180 struct uwsgi_instance { 4181 struct uwsgi_instance *ui_prev; 4182 struct uwsgi_instance *ui_next; 4183 4184 char name[0xff]; 4185 pid_t pid; 4186 4187 int status; 4188 time_t born; 4189 time_t last_mod; 4190 time_t last_loyal; 4191 time_t last_accepting; 4192 time_t last_ready; 4193 4194 time_t last_run; 4195 time_t first_run; 4196 4197 time_t last_heartbeat; 4198 4199 uint64_t respawns; 4200 int use_config; 4201 4202 int pipe[2]; 4203 int pipe_config[2]; 4204 4205 char *config; 4206 uint32_t config_len; 4207 4208 int loyal; 4209 4210 int zerg; 4211 4212 int ready; 4213 int accepting; 4214 4215 struct uwsgi_emperor_scanner *scanner; 4216 4217 uid_t uid; 4218 gid_t gid; 4219 4220 int on_demand_fd; 4221 char *socket_name; 4222 time_t cursed_at; 4223 }; 4224 4225 struct uwsgi_instance *emperor_get_by_fd(int); 4226 struct uwsgi_instance *emperor_get(char *); 4227 void emperor_stop(struct uwsgi_instance *); 4228 void emperor_curse(struct uwsgi_instance *); 4229 void emperor_respawn(struct uwsgi_instance *, time_t); 4230 void emperor_add(struct uwsgi_emperor_scanner *, char *, time_t, char *, uint32_t, uid_t, gid_t, char *); 4231 void emperor_back_to_ondemand(struct uwsgi_instance *); 4232 4233 void uwsgi_exec_command_with_args(char *); 4234 4235 void uwsgi_imperial_monitor_glob_init(struct uwsgi_emperor_scanner *); 4236 void uwsgi_imperial_monitor_directory_init(struct uwsgi_emperor_scanner *); 4237 void uwsgi_imperial_monitor_directory(struct uwsgi_emperor_scanner *); 4238 void uwsgi_imperial_monitor_glob(struct uwsgi_emperor_scanner *); 4239 4240 void uwsgi_register_clock(struct uwsgi_clock *); 4241 void uwsgi_set_clock(char *name); 4242 4243 void uwsgi_init_default(void); 4244 void uwsgi_setup_reload(void); 4245 void uwsgi_autoload_plugins_by_name(char *); 4246 void uwsgi_commandline_config(void); 4247 4248 void uwsgi_setup_log(void); 4249 void uwsgi_setup_log_master(void); 4250 4251 void uwsgi_setup_shared_sockets(void); 4252 4253 void uwsgi_setup_mules_and_farms(void); 4254 4255 void uwsgi_setup_workers(void); 4256 void uwsgi_map_sockets(void); 4257 4258 void uwsgi_set_cpu_affinity(void); 4259 4260 void uwsgi_emperor_start(void); 4261 4262 void uwsgi_bind_sockets(void); 4263 void uwsgi_set_sockets_protocols(void); 4264 4265 struct uwsgi_buffer *uwsgi_buffer_new(size_t); 4266 int uwsgi_buffer_append(struct uwsgi_buffer *, char *, size_t); 4267 int uwsgi_buffer_fix(struct uwsgi_buffer *, size_t); 4268 int uwsgi_buffer_ensure(struct uwsgi_buffer *, size_t); 4269 void uwsgi_buffer_destroy(struct uwsgi_buffer *); 4270 int uwsgi_buffer_u8(struct uwsgi_buffer *, uint8_t); 4271 int uwsgi_buffer_byte(struct uwsgi_buffer *, char); 4272 int uwsgi_buffer_u16le(struct uwsgi_buffer *, uint16_t); 4273 int uwsgi_buffer_u16be(struct uwsgi_buffer *, uint16_t); 4274 int uwsgi_buffer_u32be(struct uwsgi_buffer *, uint32_t); 4275 int uwsgi_buffer_u32le(struct uwsgi_buffer *, uint32_t); 4276 int uwsgi_buffer_u64le(struct uwsgi_buffer *, uint64_t); 4277 int uwsgi_buffer_f32be(struct uwsgi_buffer *, float); 4278 int uwsgi_buffer_u24be(struct uwsgi_buffer *, uint32_t); 4279 int uwsgi_buffer_u64be(struct uwsgi_buffer *, uint64_t); 4280 int uwsgi_buffer_f64be(struct uwsgi_buffer *, double); 4281 int uwsgi_buffer_num64(struct uwsgi_buffer *, int64_t); 4282 int uwsgi_buffer_append_keyval(struct uwsgi_buffer *, char *, uint16_t, char *, uint16_t); 4283 int uwsgi_buffer_append_keyval32(struct uwsgi_buffer *, char *, uint32_t, char *, uint32_t); 4284 int uwsgi_buffer_append_keynum(struct uwsgi_buffer *, char *, uint16_t, int64_t); 4285 int uwsgi_buffer_append_valnum(struct uwsgi_buffer *, int64_t); 4286 int uwsgi_buffer_append_ipv4(struct uwsgi_buffer *, void *); 4287 int uwsgi_buffer_append_keyipv4(struct uwsgi_buffer *, char *, uint16_t, void *); 4288 int uwsgi_buffer_decapitate(struct uwsgi_buffer *, size_t); 4289 int uwsgi_buffer_append_base64(struct uwsgi_buffer *, char *, size_t); 4290 int uwsgi_buffer_insert(struct uwsgi_buffer *, size_t, char *, size_t); 4291 int uwsgi_buffer_insert_chunked(struct uwsgi_buffer *, size_t, size_t); 4292 int uwsgi_buffer_append_chunked(struct uwsgi_buffer *, size_t); 4293 int uwsgi_buffer_append_json(struct uwsgi_buffer *, char *, size_t); 4294 int uwsgi_buffer_set_uh(struct uwsgi_buffer *, uint8_t, uint8_t); 4295 void uwsgi_buffer_map(struct uwsgi_buffer *, char *, size_t); 4296 struct uwsgi_buffer *uwsgi_buffer_from_file(char *); 4297 4298 ssize_t uwsgi_buffer_write_simple(struct wsgi_request *, struct uwsgi_buffer *); 4299 4300 struct uwsgi_buffer *uwsgi_to_http(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 4301 struct uwsgi_buffer *uwsgi_to_http_dumb(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 4302 4303 ssize_t uwsgi_pipe(int, int, int); 4304 ssize_t uwsgi_pipe_sized(int, int, size_t, int); 4305 4306 int uwsgi_buffer_send(struct uwsgi_buffer *, int); 4307 void uwsgi_master_cleanup_hooks(void); 4308 4309 pid_t uwsgi_daemonize2(); 4310 4311 void uwsgi_emperor_simple_do(struct uwsgi_emperor_scanner *, char *, char *, time_t, uid_t, gid_t, char *); 4312 4313 #if defined(__linux__) 4314 #define UWSGI_ELF 4315 char *uwsgi_elf_section(char *, char *, size_t *); 4316 #endif 4317 4318 void uwsgi_alarm_log_check(char *, size_t); 4319 void uwsgi_alarm_run(struct uwsgi_alarm_instance *, char *, size_t); 4320 void uwsgi_register_alarm(char *, void (*)(struct uwsgi_alarm_instance *), void (*)(struct uwsgi_alarm_instance *, char *, size_t)); 4321 void uwsgi_register_embedded_alarms(); 4322 void uwsgi_alarms_init(); 4323 void uwsgi_alarm_trigger(char *, char *, size_t); 4324 4325 struct uwsgi_thread { 4326 pthread_t tid; 4327 pthread_attr_t tattr; 4328 int pipe[2]; 4329 int queue; 4330 ssize_t rlen; 4331 void *data; 4332 char *buf; 4333 off_t pos; 4334 size_t len; 4335 uint64_t custom0; 4336 uint64_t custom1; 4337 uint64_t custom2; 4338 uint64_t custom3; 4339 // linked list for offloaded requests 4340 struct uwsgi_offload_request *offload_requests_head; 4341 struct uwsgi_offload_request *offload_requests_tail; 4342 void (*func) (struct uwsgi_thread *); 4343 }; 4344 struct uwsgi_thread *uwsgi_thread_new(void (*)(struct uwsgi_thread *)); 4345 struct uwsgi_thread *uwsgi_thread_new_with_data(void (*)(struct uwsgi_thread *), void *data); 4346 4347 struct uwsgi_offload_request { 4348 // the request socket 4349 int s; 4350 // the peer 4351 int fd; 4352 int fd2; 4353 4354 // if set the current request is expected to end leaving 4355 // the offload thread do its job 4356 uint8_t takeover; 4357 4358 // internal state 4359 int status; 4360 4361 // a filename, a socket... 4362 char *name; 4363 4364 off_t pos; 4365 char *buf; 4366 off_t buf_pos; 4367 4368 size_t to_write; 4369 size_t len; 4370 size_t written; 4371 4372 // a uwsgi_buffer (will be destroyed at the end of the task) 4373 struct uwsgi_buffer *ubuf; 4374 4375 struct uwsgi_offload_engine *engine; 4376 4377 // this pipe is used for notifications 4378 int pipe[2]; 4379 4380 struct uwsgi_offload_request *prev; 4381 struct uwsgi_offload_request *next; 4382 4383 // added in 2.1 4384 struct uwsgi_buffer *ubuf1; 4385 struct uwsgi_buffer *ubuf2; 4386 struct uwsgi_buffer *ubuf3; 4387 struct uwsgi_buffer *ubuf4; 4388 struct uwsgi_buffer *ubuf5; 4389 struct uwsgi_buffer *ubuf6; 4390 struct uwsgi_buffer *ubuf7; 4391 struct uwsgi_buffer *ubuf8; 4392 4393 int64_t custom1; 4394 int64_t custom2; 4395 int64_t custom3; 4396 int64_t custom4; 4397 int64_t custom5; 4398 int64_t custom6; 4399 int64_t custom7; 4400 int64_t custom8; 4401 4402 void *data; 4403 void (*free)(struct uwsgi_offload_request *); 4404 }; 4405 4406 struct uwsgi_offload_engine { 4407 char *name; 4408 int (*prepare_func)(struct wsgi_request *, struct uwsgi_offload_request *); 4409 int (*event_func) (struct uwsgi_thread *, struct uwsgi_offload_request *, int); 4410 struct uwsgi_offload_engine *next; 4411 }; 4412 4413 struct uwsgi_offload_engine *uwsgi_offload_engine_by_name(char *); 4414 struct uwsgi_offload_engine *uwsgi_offload_register_engine(char *, int (*)(struct wsgi_request *, struct uwsgi_offload_request *), int (*) (struct uwsgi_thread *, struct uwsgi_offload_request *, int)); 4415 4416 void uwsgi_offload_setup(struct uwsgi_offload_engine *, struct uwsgi_offload_request *, struct wsgi_request *, uint8_t); 4417 int uwsgi_offload_run(struct wsgi_request *, struct uwsgi_offload_request *, int *); 4418 void uwsgi_offload_engines_register_all(void); 4419 4420 struct uwsgi_thread *uwsgi_offload_thread_start(void); 4421 int uwsgi_offload_request_sendfile_do(struct wsgi_request *, int, size_t, size_t); 4422 int uwsgi_offload_request_net_do(struct wsgi_request *, char *, struct uwsgi_buffer *); 4423 int uwsgi_offload_request_memory_do(struct wsgi_request *, char *, size_t); 4424 int uwsgi_offload_request_pipe_do(struct wsgi_request *, int, size_t); 4425 4426 int uwsgi_simple_sendfile(struct wsgi_request *, int, size_t, size_t); 4427 int uwsgi_simple_write(struct wsgi_request *, char *, size_t); 4428 4429 4430 void uwsgi_subscription_set_algo(char *); 4431 struct uwsgi_subscribe_slot **uwsgi_subscription_init_ht(void); 4432 4433 int uwsgi_check_pidfile(char *); 4434 void uwsgi_daemons_spawn_all(); 4435 4436 int uwsgi_daemon_check_pid_death(pid_t); 4437 int uwsgi_daemon_check_pid_reload(pid_t); 4438 void uwsgi_daemons_smart_check(); 4439 4440 void uwsgi_setup_thread_req(long, struct wsgi_request *); 4441 void uwsgi_loop_cores_run(void *(*)(void *)); 4442 4443 int uwsgi_kvlist_parse(char *, size_t, char, int, ...); 4444 int uwsgi_send_http_stats(int); 4445 4446 ssize_t uwsgi_simple_request_read(struct wsgi_request *, char *, size_t); 4447 int uwsgi_plugin_modifier1(char *); 4448 4449 void *cache_udp_server_loop(void *); 4450 4451 int uwsgi_user_lock(int); 4452 int uwsgi_user_unlock(int); 4453 4454 void simple_loop_run_int(int); 4455 4456 char *uwsgi_strip(char *); 4457 4458 #ifdef UWSGI_SSL 4459 void uwsgi_opt_legion(char *, char *, void *); 4460 void uwsgi_opt_legion_mcast(char *, char *, void *); 4461 struct uwsgi_legion *uwsgi_legion_register(char *, char *, char *, char *, char *); 4462 void uwsgi_opt_legion_node(char *, char *, void *); 4463 void uwsgi_legion_register_node(struct uwsgi_legion *, char *); 4464 void uwsgi_opt_legion_quorum(char *, char *, void *); 4465 void uwsgi_opt_legion_hook(char *, char *, void *); 4466 void uwsgi_legion_register_hook(struct uwsgi_legion *, char *, char *); 4467 void uwsgi_opt_legion_scroll(char *, char *, void *); 4468 void uwsgi_legion_add(struct uwsgi_legion *); 4469 void uwsgi_legion_announce_death(void); 4470 char *uwsgi_ssl_rand(size_t); 4471 void uwsgi_start_legions(void); 4472 int uwsgi_legion_announce(struct uwsgi_legion *); 4473 struct uwsgi_legion *uwsgi_legion_get_by_name(char *); 4474 struct uwsgi_legion_action *uwsgi_legion_action_get(char *); 4475 struct uwsgi_legion_action *uwsgi_legion_action_register(char *, int (*)(struct uwsgi_legion *, char *)); 4476 int uwsgi_legion_action_call(char *, struct uwsgi_legion *, struct uwsgi_string_list *); 4477 void uwsgi_legion_atexit(void); 4478 #endif 4479 4480 struct uwsgi_option *uwsgi_opt_get(char *); 4481 int uwsgi_opt_exists(char *); 4482 int uwsgi_valid_fd(int); 4483 void uwsgi_close_all_fds(void); 4484 4485 int check_hex(char *, int); 4486 void uwsgi_uuid(char *); 4487 int uwsgi_uuid_cmp(char *, char *); 4488 4489 int uwsgi_legion_i_am_the_lord(char *); 4490 char *uwsgi_legion_lord_scroll(char *, uint16_t *); 4491 void uwsgi_additional_header_add(struct wsgi_request *, char *, uint16_t); 4492 void uwsgi_remove_header(struct wsgi_request *, char *, uint16_t); 4493 4494 void uwsgi_proto_hooks_setup(void); 4495 4496 char *uwsgi_base64_decode(char *, size_t, size_t *); 4497 char *uwsgi_base64_encode(char *, size_t, size_t *); 4498 4499 void uwsgi_subscribe_all(uint8_t, int); 4500 #define uwsgi_unsubscribe_all() uwsgi_subscribe_all(1, 1) 4501 4502 void uwsgi_websockets_init(void); 4503 int uwsgi_websocket_send(struct wsgi_request *, char *, size_t); 4504 int uwsgi_websocket_send_binary(struct wsgi_request *, char *, size_t); 4505 struct uwsgi_buffer *uwsgi_websocket_recv(struct wsgi_request *); 4506 struct uwsgi_buffer *uwsgi_websocket_recv_nb(struct wsgi_request *); 4507 4508 char *uwsgi_chunked_read(struct wsgi_request *, size_t *, int, int); 4509 4510 uint16_t uwsgi_be16(char *); 4511 uint32_t uwsgi_be32(char *); 4512 uint64_t uwsgi_be64(char *); 4513 4514 int uwsgi_websocket_handshake(struct wsgi_request *, char *, uint16_t, char *, uint16_t, char *, uint16_t); 4515 4516 int uwsgi_response_prepare_headers(struct wsgi_request *, char *, uint16_t); 4517 int uwsgi_response_prepare_headers_int(struct wsgi_request *, int); 4518 int uwsgi_response_add_header(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 4519 int uwsgi_response_add_header_force(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 4520 int uwsgi_response_commit_headers(struct wsgi_request *); 4521 int uwsgi_response_sendfile_do(struct wsgi_request *, int, size_t, size_t); 4522 int uwsgi_response_sendfile_do_can_close(struct wsgi_request *, int, size_t, size_t, int); 4523 4524 struct uwsgi_buffer *uwsgi_proto_base_add_header(struct wsgi_request *, char *, uint16_t, char *, uint16_t); 4525 4526 int uwsgi_simple_wait_write_hook(int, int); 4527 int uwsgi_simple_wait_read_hook(int, int); 4528 int uwsgi_simple_wait_read2_hook(int, int, int, int *); 4529 int uwsgi_simple_wait_milliseconds_hook(int); 4530 int uwsgi_response_write_headers_do(struct wsgi_request *); 4531 char *uwsgi_request_body_read(struct wsgi_request *, ssize_t , ssize_t *); 4532 char *uwsgi_request_body_readline(struct wsgi_request *, ssize_t, ssize_t *); 4533 void uwsgi_request_body_seek(struct wsgi_request *, off_t); 4534 4535 struct uwsgi_buffer *uwsgi_proto_base_prepare_headers(struct wsgi_request *, char *, uint16_t); 4536 struct uwsgi_buffer *uwsgi_proto_base_cgi_prepare_headers(struct wsgi_request *, char *, uint16_t); 4537 int uwsgi_response_write_body_do(struct wsgi_request *, char *, size_t); 4538 int uwsgi_response_writev_body_do(struct wsgi_request *, struct iovec *, size_t); 4539 4540 int uwsgi_proto_base_sendfile(struct wsgi_request *, int, size_t, size_t); 4541 #ifdef UWSGI_SSL 4542 int uwsgi_proto_ssl_sendfile(struct wsgi_request *, int, size_t, size_t); 4543 #endif 4544 4545 ssize_t uwsgi_sendfile_do(int, int, size_t, size_t); 4546 int uwsgi_proto_base_fix_headers(struct wsgi_request *); 4547 int uwsgi_response_add_content_length(struct wsgi_request *, uint64_t); 4548 void uwsgi_fix_range_for_size(enum uwsgi_range*, int64_t*, int64_t*, int64_t); 4549 void uwsgi_request_fix_range_for_size(struct wsgi_request *, int64_t); 4550 int uwsgi_response_add_content_range(struct wsgi_request *, int64_t, int64_t, int64_t); 4551 int uwsgi_response_add_expires(struct wsgi_request *, uint64_t); 4552 int uwsgi_response_add_last_modified(struct wsgi_request *, uint64_t); 4553 int uwsgi_response_add_date(struct wsgi_request *, char *, uint16_t, uint64_t); 4554 4555 const char *uwsgi_http_status_msg(char *, uint16_t *); 4556 int uwsgi_stats_dump_vars(struct uwsgi_stats *, struct uwsgi_core *); 4557 int uwsgi_stats_dump_request(struct uwsgi_stats *, struct uwsgi_core *); 4558 4559 int uwsgi_contains_n(char *, size_t, char *, size_t); 4560 4561 char *uwsgi_upload_progress_create(struct wsgi_request *, int *); 4562 int uwsgi_upload_progress_update(struct wsgi_request *, int, size_t); 4563 void uwsgi_upload_progress_destroy(char *, int); 4564 4565 void uwsgi_time_bomb(int, int); 4566 void uwsgi_master_manage_emperor(void); 4567 void uwsgi_master_manage_udp(int); 4568 4569 void uwsgi_threaded_logger_spawn(void); 4570 4571 void uwsgi_master_check_idle(void); 4572 int uwsgi_master_check_workers_deadline(void); 4573 int uwsgi_master_check_gateways_deadline(void); 4574 int uwsgi_master_check_mules_deadline(void); 4575 int uwsgi_master_check_spoolers_deadline(void); 4576 int uwsgi_master_check_crons_deadline(void); 4577 int uwsgi_master_check_spoolers_death(int); 4578 int uwsgi_master_check_emperor_death(int); 4579 int uwsgi_master_check_mules_death(int); 4580 int uwsgi_master_check_gateways_death(int); 4581 int uwsgi_master_check_daemons_death(int); 4582 4583 void uwsgi_master_check_death(void); 4584 int uwsgi_master_check_reload(char **); 4585 void uwsgi_master_commit_status(void); 4586 void uwsgi_master_check_chain(void); 4587 4588 void uwsgi_master_fix_request_counters(void); 4589 int uwsgi_master_manage_events(int); 4590 4591 void uwsgi_block_signal(int); 4592 void uwsgi_unblock_signal(int); 4593 4594 int uwsgi_worker_is_busy(int); 4595 4596 void uwsgi_post_accept(struct wsgi_request *); 4597 void uwsgi_tcp_nodelay(int); 4598 4599 struct uwsgi_exception_handler_instance; 4600 struct uwsgi_exception_handler { 4601 char *name; 4602 int (*func)(struct uwsgi_exception_handler_instance *, char *, size_t); 4603 struct uwsgi_exception_handler *next; 4604 }; 4605 4606 struct uwsgi_exception_handler_instance { 4607 struct uwsgi_exception_handler *handler; 4608 int configured; 4609 char *arg; 4610 uint32_t custom32; 4611 uint64_t custom64; 4612 void *custom_ptr; 4613 }; 4614 4615 void uwsgi_exception_setup_handlers(void); 4616 struct uwsgi_exception_handler *uwsgi_exception_handler_by_name(char *); 4617 4618 void uwsgi_manage_exception(struct wsgi_request *, int); 4619 int uwsgi_exceptions_catch(struct wsgi_request *); 4620 uint64_t uwsgi_worker_exceptions(int); 4621 struct uwsgi_exception_handler *uwsgi_register_exception_handler(char *, int (*)(struct uwsgi_exception_handler_instance *, char *, size_t)); 4622 4623 char *proxy1_parse(char *ptr, char *watermark, char **src, uint16_t *src_len, char **dst, uint16_t *dst_len, char **src_port, uint16_t *src_port_len, char **dst_port, uint16_t *dst_port_len); 4624 void uwsgi_async_queue_is_full(time_t); 4625 char *uwsgi_get_header(struct wsgi_request *, char *, uint16_t, uint16_t *); 4626 4627 void uwsgi_alarm_thread_start(void); 4628 void uwsgi_exceptions_handler_thread_start(void); 4629 4630 #define uwsgi_response_add_connection_close(x) uwsgi_response_add_header(x, (char *)"Connection", 10, (char *)"close", 5) 4631 #define uwsgi_response_add_content_type(x, y, z) uwsgi_response_add_header(x, (char *)"Content-Type", 12, y, z) 4632 4633 struct uwsgi_stats_pusher_instance *uwsgi_stats_pusher_add(struct uwsgi_stats_pusher *, char *); 4634 4635 int plugin_already_loaded(const char *); 4636 struct uwsgi_plugin *uwsgi_plugin_get(const char *); 4637 4638 struct uwsgi_cache_magic_context { 4639 char *cmd; 4640 uint16_t cmd_len; 4641 char *key; 4642 uint16_t key_len; 4643 uint64_t size; 4644 uint64_t expires; 4645 char *status; 4646 uint16_t status_len; 4647 char *cache; 4648 uint16_t cache_len; 4649 }; 4650 4651 char *uwsgi_cache_magic_get(char *, uint16_t, uint64_t *, uint64_t *, char *); 4652 int uwsgi_cache_magic_set(char *, uint16_t, char *, uint64_t, uint64_t, uint64_t, char *); 4653 int uwsgi_cache_magic_del(char *, uint16_t, char *); 4654 int uwsgi_cache_magic_exists(char *, uint16_t, char *); 4655 int uwsgi_cache_magic_clear(char *); 4656 void uwsgi_cache_magic_context_hook(char *, uint16_t, char *, uint16_t, void *); 4657 4658 char *uwsgi_legion_scrolls(char *, uint64_t *); 4659 int uwsgi_emperor_vassal_start(struct uwsgi_instance *); 4660 4661 #ifdef UWSGI_ZLIB 4662 #include <zlib.h> 4663 int uwsgi_deflate_init(z_stream *, char *, size_t); 4664 int uwsgi_inflate_init(z_stream *, char *, size_t); 4665 char *uwsgi_deflate(z_stream *, char *, size_t, size_t *); 4666 void uwsgi_crc32(uint32_t *, char *, size_t); 4667 struct uwsgi_buffer *uwsgi_gzip(char *, size_t); 4668 struct uwsgi_buffer *uwsgi_zlib_decompress(char *, size_t); 4669 int uwsgi_gzip_fix(z_stream *, uint32_t, struct uwsgi_buffer *, size_t); 4670 char *uwsgi_gzip_chunk(z_stream *, uint32_t *, char *, size_t, size_t *); 4671 int uwsgi_gzip_prepare(z_stream *, char *, size_t, uint32_t *); 4672 #endif 4673 4674 char *uwsgi_get_cookie(struct wsgi_request *, char *, uint16_t, uint16_t *); 4675 char *uwsgi_get_qs(struct wsgi_request *, char *, uint16_t, uint16_t *); 4676 4677 struct uwsgi_route_var *uwsgi_get_route_var(char *, uint16_t); 4678 struct uwsgi_route_var *uwsgi_register_route_var(char *, char *(*)(struct wsgi_request *, char *, uint16_t, uint16_t *)); 4679 4680 char *uwsgi_get_mime_type(char *, int, size_t *); 4681 4682 void config_magic_table_fill(char *, char *[]); 4683 4684 int uwsgi_blob_to_response(struct wsgi_request *, char *, size_t); 4685 struct uwsgi_cron *uwsgi_cron_add(char *); 4686 int uwsgi_is_full_http(struct uwsgi_buffer *); 4687 4688 int uwsgi_http_date(time_t t, char *); 4689 4690 int uwsgi_apply_transformations(struct wsgi_request *wsgi_req, char *, size_t); 4691 int uwsgi_apply_final_transformations(struct wsgi_request *); 4692 void uwsgi_free_transformations(struct wsgi_request *); 4693 struct uwsgi_transformation *uwsgi_add_transformation(struct wsgi_request *wsgi_req, int (*func)(struct wsgi_request *, struct uwsgi_transformation *), void *); 4694 4695 void uwsgi_file_write_do(struct uwsgi_string_list *); 4696 4697 int uwsgi_fd_is_safe(int); 4698 void uwsgi_add_safe_fd(int); 4699 4700 void uwsgi_ipcsem_clear(void); 4701 char *uwsgi_str_to_hex(char *, size_t); 4702 4703 // this 3 functions have been added 1.9.10 to allow plugins take the control over processes 4704 void uwsgi_worker_run(void); 4705 void uwsgi_mule_run(void); 4706 void uwsgi_spooler_run(void); 4707 void uwsgi_takeover(void); 4708 4709 char *uwsgi_binary_path(void); 4710 4711 int uwsgi_is_again(); 4712 void uwsgi_disconnect(struct wsgi_request *); 4713 int uwsgi_ready_fd(struct wsgi_request *); 4714 4715 void uwsgi_envdir(char *); 4716 void uwsgi_envdirs(struct uwsgi_string_list *); 4717 void uwsgi_opt_envdir(char *, char *, void *); 4718 4719 void uwsgi_add_reload_fds(); 4720 4721 void uwsgi_check_emperor(void); 4722 #ifdef UWSGI_AS_SHARED_LIBRARY 4723 int uwsgi_init(int, char **, char **); 4724 #endif 4725 4726 int uwsgi_master_check_cron_death(int); 4727 struct uwsgi_fsmon *uwsgi_register_fsmon(char *, void (*)(struct uwsgi_fsmon *), void *data); 4728 int uwsgi_fsmon_event(int); 4729 void uwsgi_fsmon_setup(); 4730 4731 void uwsgi_exit(int) __attribute__ ((__noreturn__)); 4732 void uwsgi_fallback_config(); 4733 4734 struct uwsgi_cache_item *uwsgi_cache_keys(struct uwsgi_cache *, uint64_t *, struct uwsgi_cache_item **); 4735 void uwsgi_cache_rlock(struct uwsgi_cache *); 4736 void uwsgi_cache_rwunlock(struct uwsgi_cache *); 4737 char *uwsgi_cache_item_key(struct uwsgi_cache_item *); 4738 4739 char *uwsgi_binsh(void); 4740 int uwsgi_file_executable(char *); 4741 4742 int uwsgi_mount(char *, char *, char *, char *, char *); 4743 int uwsgi_umount(char *, char *); 4744 int uwsgi_mount_hook(char *); 4745 int uwsgi_umount_hook(char *); 4746 4747 void uwsgi_hooks_run(struct uwsgi_string_list *, char *, int); 4748 void uwsgi_register_hook(char *, int (*)(char *)); 4749 struct uwsgi_hook *uwsgi_hook_by_name(char *); 4750 void uwsgi_register_base_hooks(void); 4751 4752 void uwsgi_setup_log_encoders(void); 4753 void uwsgi_log_encoders_register_embedded(void); 4754 4755 void uwsgi_register_log_encoder(char *, char *(*)(struct uwsgi_log_encoder *, char *, size_t, size_t *)); 4756 4757 int uwsgi_accept(int); 4758 void suspend_resume_them_all(int); 4759 4760 void uwsgi_master_fifo_prepare(); 4761 int uwsgi_master_fifo(); 4762 int uwsgi_master_fifo_manage(int); 4763 4764 void uwsgi_log_do_rotate(char *, char *, off_t, int); 4765 void uwsgi_log_rotate(); 4766 void uwsgi_log_reopen(); 4767 void uwsgi_reload_workers(); 4768 void uwsgi_reload_mules(); 4769 void uwsgi_reload_spoolers(); 4770 void uwsgi_chain_reload(); 4771 void uwsgi_refork_master(); 4772 void uwsgi_update_pidfiles(); 4773 void gracefully_kill_them_all(int); 4774 void uwsgi_brutally_reload_workers(); 4775 4776 void uwsgi_cheaper_increase(); 4777 void uwsgi_cheaper_decrease(); 4778 void uwsgi_go_cheap(); 4779 4780 char **uwsgi_split_quoted(char *, size_t, char *, size_t *); 4781 4782 void uwsgi_master_manage_emperor_proxy(); 4783 struct uwsgi_string_list *uwsgi_register_scheme(char *, char * (*)(char *, size_t *, int)); 4784 void uwsgi_setup_schemes(void); 4785 4786 struct uwsgi_string_list *uwsgi_check_scheme(char *); 4787 4788 void uwsgi_remap_fd(int, char *); 4789 void uwsgi_opt_exit(char *, char *, void *); 4790 int uwsgi_check_mountpoint(char *); 4791 void uwsgi_master_check_mountpoints(void); 4792 4793 enum { 4794 UWSGI_METRIC_COUNTER, 4795 UWSGI_METRIC_GAUGE, 4796 UWSGI_METRIC_ABSOLUTE, 4797 UWSGI_METRIC_ALIAS, 4798 }; 4799 4800 struct uwsgi_metric_child; 4801 4802 struct uwsgi_metric_collector { 4803 char *name; 4804 int64_t (*func)(struct uwsgi_metric *); 4805 struct uwsgi_metric_collector *next; 4806 }; 4807 4808 struct uwsgi_metric_threshold { 4809 int64_t value; 4810 uint8_t reset; 4811 int64_t reset_value; 4812 int32_t rate; 4813 char *alarm; 4814 char *msg; 4815 size_t msg_len; 4816 time_t last_alarm; 4817 struct uwsgi_metric_threshold *next; 4818 }; 4819 4820 struct uwsgi_metric { 4821 char *name; 4822 char *oid; 4823 4824 size_t name_len; 4825 size_t oid_len; 4826 4827 // pre-computed snmp representation 4828 char *asn; 4829 size_t asn_len; 4830 4831 // ABSOLUTE/COUNTER/GAUGE 4832 uint8_t type; 4833 4834 // this could be taken from a file storage and must be always added to value by the collector (default 0) 4835 int64_t initial_value; 4836 // the value of the metric (point to a shared memory area) 4837 int64_t *value; 4838 4839 // a custom blob you can attach to a metric 4840 void *custom; 4841 4842 // the collection frequency 4843 uint32_t freq; 4844 time_t last_update; 4845 4846 // run this function to collect the value 4847 struct uwsgi_metric_collector *collector; 4848 // take the value from this pointer to a 64bit value 4849 int64_t *ptr; 4850 // get the initial value from this file, and store each update in it 4851 char *filename; 4852 4853 // pointer to memory mapped storage 4854 char *map; 4855 4856 // arguments for collectors 4857 char *arg1; 4858 char *arg2; 4859 char *arg3; 4860 4861 int64_t arg1n; 4862 int64_t arg2n; 4863 int64_t arg3n; 4864 4865 struct uwsgi_metric_child *children; 4866 struct uwsgi_metric_threshold *thresholds; 4867 4868 struct uwsgi_metric *next; 4869 4870 // allow to reset metrics after each push 4871 uint8_t reset_after_push; 4872 }; 4873 4874 struct uwsgi_metric_child { 4875 struct uwsgi_metric *um; 4876 struct uwsgi_metric_child *next; 4877 }; 4878 4879 void uwsgi_setup_metrics(void); 4880 void uwsgi_metrics_start_collector(void); 4881 4882 int uwsgi_metric_set(char *, char *, int64_t); 4883 int uwsgi_metric_inc(char *, char *, int64_t); 4884 int uwsgi_metric_dec(char *, char *, int64_t); 4885 int uwsgi_metric_mul(char *, char *, int64_t); 4886 int uwsgi_metric_div(char *, char *, int64_t); 4887 int64_t uwsgi_metric_get(char *, char *); 4888 int64_t uwsgi_metric_getn(char *, size_t, char *, size_t); 4889 int uwsgi_metric_set_max(char *, char *, int64_t); 4890 int uwsgi_metric_set_min(char *, char *, int64_t); 4891 4892 struct uwsgi_metric_collector *uwsgi_register_metric_collector(char *, int64_t (*)(struct uwsgi_metric *)); 4893 struct uwsgi_metric *uwsgi_register_metric(char *, char *, uint8_t, char *, void *, uint32_t, void *); 4894 4895 void uwsgi_metrics_collectors_setup(void); 4896 struct uwsgi_metric *uwsgi_metric_find_by_name(char *); 4897 struct uwsgi_metric *uwsgi_metric_find_by_namen(char *, size_t); 4898 struct uwsgi_metric_child *uwsgi_metric_add_child(struct uwsgi_metric *, struct uwsgi_metric *); 4899 4900 struct uwsgi_metric *uwsgi_metric_find_by_oid(char *); 4901 struct uwsgi_metric *uwsgi_metric_find_by_oidn(char *, size_t); 4902 struct uwsgi_metric *uwsgi_metric_find_by_asn(char *, size_t); 4903 4904 int uwsgi_base128(struct uwsgi_buffer *, uint64_t, int); 4905 4906 struct wsgi_request *find_wsgi_req_proto_by_fd(int); 4907 4908 struct uwsgi_protocol *uwsgi_register_protocol(char *, void (*)(struct uwsgi_socket *)); 4909 4910 void uwsgi_protocols_register(void); 4911 4912 void uwsgi_build_plugin(char *dir); 4913 4914 void uwsgi_sharedareas_init(); 4915 4916 struct uwsgi_sharedarea *uwsgi_sharedarea_init(int); 4917 struct uwsgi_sharedarea *uwsgi_sharedarea_init_ptr(char *, uint64_t); 4918 struct uwsgi_sharedarea *uwsgi_sharedarea_init_fd(int, uint64_t, off_t); 4919 4920 int64_t uwsgi_sharedarea_read(int, uint64_t, char *, uint64_t); 4921 int uwsgi_sharedarea_write(int, uint64_t, char *, uint64_t); 4922 int uwsgi_sharedarea_read64(int, uint64_t, int64_t *); 4923 int uwsgi_sharedarea_write64(int, uint64_t, int64_t *); 4924 int uwsgi_sharedarea_read8(int, uint64_t, int8_t *); 4925 int uwsgi_sharedarea_write8(int, uint64_t, int8_t *); 4926 int uwsgi_sharedarea_read16(int, uint64_t, int16_t *); 4927 int uwsgi_sharedarea_write16(int, uint64_t, int16_t *); 4928 int uwsgi_sharedarea_read32(int, uint64_t, int32_t *); 4929 int uwsgi_sharedarea_write32(int, uint64_t, int32_t *); 4930 int uwsgi_sharedarea_inc8(int, uint64_t, int8_t); 4931 int uwsgi_sharedarea_inc16(int, uint64_t, int16_t); 4932 int uwsgi_sharedarea_inc32(int, uint64_t, int32_t); 4933 int uwsgi_sharedarea_inc64(int, uint64_t, int64_t); 4934 int uwsgi_sharedarea_dec8(int, uint64_t, int8_t); 4935 int uwsgi_sharedarea_dec16(int, uint64_t, int16_t); 4936 int uwsgi_sharedarea_dec32(int, uint64_t, int32_t); 4937 int uwsgi_sharedarea_dec64(int, uint64_t, int64_t); 4938 int uwsgi_sharedarea_wait(int, int, int); 4939 int uwsgi_sharedarea_unlock(int); 4940 int uwsgi_sharedarea_rlock(int); 4941 int uwsgi_sharedarea_wlock(int); 4942 int uwsgi_sharedarea_update(int); 4943 4944 struct uwsgi_sharedarea *uwsgi_sharedarea_get_by_id(int, uint64_t); 4945 int uwsgi_websocket_send_from_sharedarea(struct wsgi_request *, int, uint64_t, uint64_t); 4946 int uwsgi_websocket_send_binary_from_sharedarea(struct wsgi_request *, int, uint64_t, uint64_t); 4947 4948 void uwsgi_register_logchunks(void); 4949 4950 void uwsgi_setup(int, char **, char **); 4951 int uwsgi_run(void); 4952 4953 int uwsgi_is_connected(int); 4954 int uwsgi_pass_cred(int, char *, size_t); 4955 int uwsgi_pass_cred2(int, char *, size_t, struct sockaddr *, size_t); 4956 int uwsgi_recv_cred(int, char *, size_t, pid_t *, uid_t *, gid_t *); 4957 ssize_t uwsgi_recv_cred2(int, char *, size_t, pid_t *, uid_t *, gid_t *); 4958 int uwsgi_socket_passcred(int); 4959 4960 void uwsgi_dump_worker(int, char *); 4961 mode_t uwsgi_mode_t(char *, int *); 4962 4963 int uwsgi_notify_socket_manage(int); 4964 int uwsgi_notify_msg(char *, char *, size_t); 4965 void vassal_sos(); 4966 4967 int uwsgi_wait_for_fs(char *, int); 4968 int uwsgi_wait_for_mountpoint(char *); 4969 int uwsgi_wait_for_socket(char *); 4970 4971 #ifdef __cplusplus 4972 } 4973 #endif 4974