forked from unbit/uwsgi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uwsgi.h
3594 lines (2696 loc) · 80.8 KB
/
uwsgi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* uWSGI */
/* indent -i8 -br -brs -brf -l0 -npsl -nip -npcs -npsl -di1 -il0 */
#ifdef __cplusplus
extern "C" {
#endif
#define UMAX16 65536
#define UMAX64_STR "18446744073709551616"
#define uwsgi_error(x) uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__);
#define uwsgi_error_realpath(x) uwsgi_log("realpath() of %s failed: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__);
#define uwsgi_log_safe(x) if (uwsgi.original_log_fd != 2) dup2(uwsgi.original_log_fd, 2) ; uwsgi_log(x);
#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__);
#define uwsgi_log_initial if (!uwsgi.no_initial_output) uwsgi_log
#ifdef UWSGI_ALARM
#define uwsgi_log_alarm(x, ...) uwsgi_log("[uwsgi-alarm" x, __VA_ARGS__)
#endif
#define uwsgi_fatal_error(x) uwsgi_error(x); exit(1);
#define uwsgi_error_open(x) uwsgi_log("open(\"%s\"): %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__);
#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__,\
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__);
#define uwsgi_debug(x, ...) uwsgi_log("[uWSGI DEBUG] " x, __VA_ARGS__);
#define uwsgi_rawlog(x) if (write(2, x, strlen(x)) != strlen(x)) uwsgi_error("write()")
#define uwsgi_str(x) uwsgi_concat2(x, (char *)"")
#define uwsgi_notify(x) if (uwsgi.notify) uwsgi.notify(x)
#define uwsgi_notify_ready() uwsgi.shared->ready = 1 ; if (uwsgi.notify_ready) uwsgi.notify_ready()
#define uwsgi_apps uwsgi.workers[uwsgi.mywid].apps
#define uwsgi_apps_cnt uwsgi.workers[uwsgi.mywid].apps_cnt
#define wsgi_req_time ((wsgi_req->end_of_request-wsgi_req->start_of_request)/1000)
#define thunder_lock if (uwsgi.threads > 1 && !uwsgi.is_et) {pthread_mutex_lock(&uwsgi.thunder_mutex);}
#define thunder_unlock if (uwsgi.threads > 1 && !uwsgi.is_et) {pthread_mutex_unlock(&uwsgi.thunder_mutex);}
#define uwsgi_check_scheme(file) (!uwsgi_startswith(file, "emperor:https://", 10) || !uwsgi_startswith(file, "https://", 7) || !uwsgi_startswith(file, "data:https://", 7) || !uwsgi_startswith(file, "sym:https://", 6) || !uwsgi_startswith(file, "fd:https://", 5) || !uwsgi_startswith(file, "exec:https://", 7) || !uwsgi_startswith(file, "section:https://", 10))
#define ushared uwsgi.shared
#define UWSGI_OPT_IMMEDIATE (1 << 0)
#define UWSGI_OPT_MASTER (1 << 1)
#define UWSGI_OPT_LOG_MASTER (1 << 2)
#define UWSGI_OPT_THREADS (1 << 3)
#define UWSGI_OPT_CHEAPER (1 << 4)
#define UWSGI_OPT_VHOST (1 << 5)
#define UWSGI_OPT_MEMORY (1 << 6)
#define UWSGI_OPT_PROCNAME (1 << 7)
#define UWSGI_OPT_LAZY (1 << 8)
#define UWSGI_OPT_NO_INITIAL (1 << 9)
#define UWSGI_OPT_NO_SERVER (1 << 10)
#define UWSGI_OPT_POST_BUFFERING (1 << 11)
#define UWSGI_OPT_CLUSTER (1 << 12)
#define UWSGI_OPT_MIME (1 << 13)
#define MAX_GENERIC_PLUGINS 64
#define MAX_RPC 64
#define MAX_GATEWAYS 64
#define MAX_TIMERS 64
#define MAX_PROBES 64
#define MAX_CRONS 64
#ifndef UWSGI_LOAD_EMBEDDED_PLUGINS
#define UWSGI_LOAD_EMBEDDED_PLUGINS
#endif
#ifndef UWSGI_DECLARE_EMBEDDED_PLUGINS
#define UWSGI_DECLARE_EMBEDDED_PLUGINS
#endif
#ifdef UWSGI_EMBED_CONFIG
extern char UWSGI_EMBED_CONFIG;
extern char UWSGI_EMBED_CONFIG_END;
#endif
#define UDEP(pname) extern struct uwsgi_plugin pname##_plugin;
#define ULEP(pname)\
if (pname##_plugin.request) {\
uwsgi.p[pname##_plugin.modifier1] = &pname##_plugin;\
if (uwsgi.p[pname##_plugin.modifier1]->on_load)\
uwsgi.p[pname##_plugin.modifier1]->on_load();\
}\
else {\
if (uwsgi.gp_cnt >= MAX_GENERIC_PLUGINS) {\
uwsgi_log("you have embedded too much generic plugins !!!\n");\
exit(1);\
}\
uwsgi.gp[uwsgi.gp_cnt] = &pname##_plugin;\
if (uwsgi.gp[uwsgi.gp_cnt]->on_load)\
uwsgi.gp[uwsgi.gp_cnt]->on_load();\
uwsgi.gp_cnt++;\
}\
#define fill_plugin_table(x, up)\
if (up->request) {\
uwsgi.p[x] = up;\
}\
else {\
if (uwsgi.gp_cnt >= MAX_GENERIC_PLUGINS) {\
uwsgi_log("you have embedded to much generic plugins !!!\n");\
exit(1);\
}\
uwsgi.gp[uwsgi.gp_cnt] = up;\
uwsgi.gp_cnt++;\
}\
#ifndef __need_IOV_MAX
#define __need_IOV_MAX
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <signal.h>
#include <math.h>
#include <sys/types.h>
#ifdef __linux__
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef __USE_GNU
#define __USE_GNU
#endif
#endif
#include <sys/socket.h>
#ifdef __linux__
#ifndef MSG_FASTOPEN
#define MSG_FASTOPEN 0x20000000
#endif
#endif
#undef _GNU_SOURCE
#include <netinet/in.h>
#include <termios.h>
#ifdef UWSGI_UUID
#include <uuid/uuid.h>
#endif
#ifdef __sun__
#define _XPG4_2
#define __EXTENSIONS__
#endif
#include <string.h>
#include <sys/stat.h>
#include <netinet/tcp.h>
#ifdef __linux__
#ifndef TCP_FASTOPEN
#define TCP_FASTOPEN 23
#endif
#endif
#include <netdb.h>
#ifdef __FreeBSD__
#include <sys/sysctl.h>
#include <sys/param.h>
#include <sys/cpuset.h>
#endif
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdarg.h>
#include <errno.h>
#ifndef __USE_ISOC99
#define __USE_ISOC99
#endif
#include <ctype.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef UWSGI_HAS_IFADDRS
#include <ifaddrs.h>
#endif
#include <pwd.h>
#include <grp.h>
#include <sys/utsname.h>
#ifdef __linux__
#include <sched.h>
#include <sys/prctl.h>
#include <linux/limits.h>
#include <sys/mount.h>
#ifdef UWSGI_PTRACE
#include <sys/ptrace.h>
#include <sys/user.h>
#include <sys/reg.h>
#endif
extern int pivot_root(const char *new_root, const char *put_old);
#endif
#include <limits.h>
#include <dirent.h>
#ifndef UWSGI_PLUGIN_BASE
#define UWSGI_PLUGIN_BASE ""
#endif
#include <arpa/inet.h>
#include <sys/mman.h>
#include <sys/file.h>
#include <stdint.h>
#include <sys/wait.h>
#ifdef __APPLE__
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4
#include <mach-o/dyld.h>
#endif
#include <dlfcn.h>
#include <poll.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/resource.h>
#include <getopt.h>
#ifdef __APPLE__
#include <libkern/OSAtomic.h>
#include <mach/task.h>
#include <mach/mach_init.h>
#endif
#ifdef UNBIT
#include "unbit.h"
#endif
#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif
#ifdef __sun__
#define WAIT_ANY (-1)
#include <sys/filio.h>
#define PRIO_MAX 20
#endif
#ifdef __HAIKU__
#define WAIT_ANY (-1)
#endif
#include <sys/ioctl.h>
#ifdef __linux__
#include <sys/sendfile.h>
#include <sys/epoll.h>
#elif defined(__sun__)
#include <sys/sendfile.h>
#include <sys/devpoll.h>
#elif defined(__HAIKU__)
#else
#include <sys/event.h>
#endif
#ifdef UWSGI_CAP
#include <sys/capability.h>
#endif
#ifdef __HAIKU__
#include <kernel/OS.h>
#endif
#undef _XOPEN_SOURCE
#ifdef __sun__
#undef __EXTENSIONS__
#endif
#ifdef UWSGI_ZEROMQ
#include <zmq.h>
#endif
#define UWSGI_CACHE_MAX_KEY_SIZE 2048
#define UWSGI_CACHE_FLAG_UNGETTABLE 0x0001
#define UWSGI_CACHE_FLAG_UPDATE 0x0002
#define UWSGI_CACHE_FLAG_LOCAL 0x0004
#define UWSGI_CACHE_FLAG_ABSEXPIRE 0x0008
#define uwsgi_cache_update_start(x, y, z) uwsgi_cache_set(x, y, "", 0, CACHE_FLAG_UNGETTABLE)
#ifdef UWSGI_SSL
#include "openssl/conf.h"
#include "openssl/ssl.h"
#include <openssl/err.h>
#endif
struct uwsgi_buffer {
char *buf;
off_t pos;
size_t len;
size_t limit;
};
struct uwsgi_string_list {
char *value;
size_t len;
uint64_t custom;
uint64_t custom2;
void *custom_ptr;
struct uwsgi_string_list *next;
};
struct uwsgi_custom_option {
char *name;
char *value;
int has_args;
struct uwsgi_custom_option *next;
};
struct uwsgi_lock_item {
char *id;
void *lock_ptr;
int rw;
pid_t pid;
int can_deadlock;
struct uwsgi_lock_item *next;
};
struct uwsgi_lock_ops {
struct uwsgi_lock_item* (*lock_init)(char *);
pid_t (*lock_check)(struct uwsgi_lock_item *);
void (*lock)(struct uwsgi_lock_item *);
void (*unlock)(struct uwsgi_lock_item *);
struct uwsgi_lock_item * (*rwlock_init)(char *);
pid_t (*rwlock_check)(struct uwsgi_lock_item *);
void (*rlock)(struct uwsgi_lock_item *);
void (*wlock)(struct uwsgi_lock_item *);
void (*rwunlock)(struct uwsgi_lock_item *);
};
#define uwsgi_lock_init(x) uwsgi.lock_ops.lock_init(x)
#define uwsgi_lock_check(x) uwsgi.lock_ops.lock_check(x)
#define uwsgi_lock(x) uwsgi.lock_ops.lock(x)
#define uwsgi_unlock(x) uwsgi.lock_ops.unlock(x)
#define uwsgi_rwlock_init(x) uwsgi.lock_ops.rwlock_init(x)
#define uwsgi_rwlock_check(x) uwsgi.lock_ops.rwlock_check(x)
#define uwsgi_rlock(x) uwsgi.lock_ops.rlock(x)
#define uwsgi_wlock(x) uwsgi.lock_ops.wlock(x)
#define uwsgi_rwunlock(x) uwsgi.lock_ops.rwunlock(x)
#ifdef UWSGI_PCRE
#include <pcre.h>
#endif
#ifdef UWSGI_MATHEVAL
#include <matheval.h>
#endif
struct uwsgi_dyn_dict {
char *key;
int keylen;
char *value;
int vallen;
uint64_t hits;
int status;
#ifdef UWSGI_PCRE
pcre *pattern;
pcre_extra *pattern_extra;
#endif
struct uwsgi_dyn_dict *prev;
struct uwsgi_dyn_dict *next;
};
#ifdef UWSGI_PCRE
struct uwsgi_regexp_list {
pcre *pattern;
pcre_extra *pattern_extra;
uint64_t custom;
char *custom_str;
void *custom_ptr;
struct uwsgi_regexp_list *next;
};
#endif
union uwsgi_sockaddr {
struct sockaddr sa;
struct sockaddr_in sa_in;
struct sockaddr_un sa_un;
#ifdef UWSGI_IPV6
struct sockaddr_in6 sa_in6;
#endif
};
union uwsgi_sockaddr_ptr {
struct sockaddr *sa;
struct sockaddr_in *sa_in;
struct sockaddr_un *sa_un;
#ifdef UWSGI_IPV6
struct sockaddr_in6 *sa_in6;
#endif
};
// Gateways are processes (managed by the master) that extends the
// server core features
// -- Gateways can prefork or spawn threads --
struct uwsgi_gateway {
char *name;
char *fullname;
void (*loop) (int, void *);
pid_t pid;
int num;
int use_signals;
int internal_subscription_pipe[2];
uint64_t respawns;
void *data;
};
struct uwsgi_gateway_socket {
char *name;
size_t name_len;
int fd;
char *zerg;
char *port;
int port_len;
int no_defer;
void *data;
// this requires UDP
int subscription;
int shared;
char *owner;
struct uwsgi_gateway *gateway;
struct uwsgi_gateway_socket *next;
// could be useful for ssl
void *ctx;
// could be useful ofr plugins
int mode;
};
// Daemons are external processes maintained by the master
struct uwsgi_daemon {
char *command;
pid_t pid;
uint64_t respawns;
time_t born;
time_t last_spawn;
int status;
int registered;
char *pidfile;
int daemonize;
// this is incremented every time a pidfile is not found
uint64_t pidfile_checks;
// frequency of pidfile checks (default 10 secs)
int freq;
struct uwsgi_daemon *next;
};
struct uwsgi_logger {
char *name;
char *id;
ssize_t (*func)(struct uwsgi_logger *, char *, size_t);
int configured;
int fd;
void *data;
union uwsgi_sockaddr addr;
socklen_t addr_len;
int count;
struct msghdr msg;
// used by choosen logger
char *arg;
struct uwsgi_logger *next;
};
#ifdef UWSGI_SSL
struct uwsgi_legion {
char *legion;
uint16_t legion_len;
uint64_t valor;
char *addr;
time_t lord;
time_t last_seen_lord;
char *name;
uint16_t name_len;
pid_t pid;
int socket;
EVP_CIPHER_CTX *encrypt_ctx;
EVP_CIPHER_CTX *decrypt_ctx;
struct uwsgi_string_list *nodes;
struct uwsgi_string_list *lord_hooks;
struct uwsgi_string_list *unlord_hooks;
struct uwsgi_string_list *setup_hooks;
struct uwsgi_string_list *death_hooks;
struct uwsgi_legion *next;
};
struct uwsgi_legion_action {
char *name;
int (*func)(struct uwsgi_legion *, char *);
struct uwsgi_legion_action *next;
};
#endif
struct uwsgi_queue_header {
uint64_t pos;
uint64_t pull_pos;
};
struct uwsgi_queue_item {
uint64_t size;
time_t ts;
};
// maintain alignment here !!!
struct uwsgi_cache_item {
// unused
uint16_t flags;
// size of the key
uint16_t keysize;
// djb hash of the key
uint32_t djbhash;
// size of the value (64bit)
uint64_t valsize;
// 64bit expiration (0 for immortal)
uint64_t expires;
// 64bit hits
uint64_t hits;
// previous same-hash item
uint64_t prev;
// next same-hash item
uint64_t next;
// key chracters follows...
char key[UWSGI_CACHE_MAX_KEY_SIZE];
} __attribute__ ((__packed__));
struct uwsgi_option {
char *name;
int type;
int shortcut;
char *help;
void (*func)(char *, char *, void *);
void *data;
uint64_t flags;
};
struct uwsgi_opt {
char *key;
char *value;
int configured;
};
#define MAX_CLUSTER_NODES 100
#define UWSGI_NODE_OK 0
#define UWSGI_NODE_FAILED 1
#define UWSGI_OK 0
#define UWSGI_AGAIN 1
#define UWSGI_ACCEPTING 2
#define UWSGI_PAUSED 3
#ifdef __linux__
#include <endian.h>
#elif defined(__sun__)
#include <sys/byteorder.h>
#ifdef _BIG_ENDIAN
#define __BIG_ENDIAN__ 1
#endif
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#elif defined(__HAIKU__)
#else
#include <machine/endian.h>
#endif
#define UWSGI_OPTION_LOGGING 0
#define UWSGI_OPTION_MAX_REQUESTS 1
#define UWSGI_OPTION_SOCKET_TIMEOUT 2
#define UWSGI_OPTION_MEMORY_DEBUG 3
#define UWSGI_OPTION_MASTER_INTERVAL 4
#define UWSGI_OPTION_HARAKIRI 5
#define UWSGI_OPTION_CGI_MODE 6
#define UWSGI_OPTION_THREADS 7
#define UWSGI_OPTION_REAPER 8
#define UWSGI_OPTION_LOG_ZERO 9
#define UWSGI_OPTION_LOG_SLOW 10
#define UWSGI_OPTION_LOG_4xx 11
#define UWSGI_OPTION_LOG_5xx 12
#define UWSGI_OPTION_LOG_BIG 13
#define UWSGI_OPTION_LOG_SENDFILE 14
#define UWSGI_OPTION_BACKLOG_STATUS 15
#define UWSGI_OPTION_BACKLOG_ERRORS 16
#define UWSGI_OPTION_SPOOLER_HARAKIRI 17
#define UWSGI_OPTION_MULE_HARAKIRI 18
#define UWSGI_SPOOLER_EXTERNAL 1
#define UWSGI_MODIFIER_ADMIN_REQUEST 10
#define UWSGI_MODIFIER_SPOOL_REQUEST 17
#define UWSGI_MODIFIER_EVAL 22
#define UWSGI_MODIFIER_FASTFUNC 26
#define UWSGI_MODIFIER_MANAGE_PATH_INFO 30
#define UWSGI_MODIFIER_MESSAGE 31
#define UWSGI_MODIFIER_MESSAGE_ARRAY 32
#define UWSGI_MODIFIER_MESSAGE_MARSHAL 33
#define UWSGI_MODIFIER_MULTICAST_ANNOUNCE 73
#define UWSGI_MODIFIER_MULTICAST 74
#define UWSGI_MODIFIER_PING 100
#define UWSGI_MODIFIER_RESPONSE 255
#define NL_SIZE 2
#define H_SEP_SIZE 2
#define UWSGI_RELOAD_CODE 17
#define UWSGI_END_CODE 30
#define UWSGI_EXILE_CODE 26
#define UWSGI_FAILED_APP_CODE 22
#define UWSGI_DE_HIJACKED_CODE 173
#define UWSGI_EXCEPTION_CODE 5
#define UWSGI_QUIET_CODE 29
#define MAX_VARS 64
struct uwsgi_loop {
char *name;
void (*loop) (void);
struct uwsgi_loop *next;
};
struct wsgi_request;
struct uwsgi_socket {
int fd;
char *name;
int name_len;
int family;
int bound;
int arg;
void *ctx;
int queue;
int no_defer;
int auto_port;
// true if connection must be initialized for each core
int per_core;
char *proto_name;
int (*proto) (struct wsgi_request *);
int (*proto_accept) (struct wsgi_request *, int);
ssize_t(*proto_write) (struct wsgi_request *, char *, size_t);
ssize_t(*proto_writev) (struct wsgi_request *, struct iovec *, size_t);
ssize_t(*proto_write_header) (struct wsgi_request *, char *, size_t);
ssize_t(*proto_writev_header) (struct wsgi_request *, struct iovec *, size_t);
ssize_t(*proto_sendfile) (struct wsgi_request *);
ssize_t(*proto_read_body) (struct wsgi_request *, char *, size_t);
void (*proto_close) (struct wsgi_request *);
void (*proto_thread_fixup) (struct uwsgi_socket *, int);
int edge_trigger;
int *retry;
int can_offload;
// this is a special map for having socket->thread mapping
int *fd_threads;
#ifdef UWSGI_UUID
char uuid[37];
#endif
// currently used by zeromq handlers
void *pub;
void *pull;
pthread_key_t key;
pthread_mutex_t lock;
char *receiver;
int disabled;
int recv_flag;
struct uwsgi_socket *next;
int lazy;
int shared;
int from_shared;
};
struct uwsgi_server;
struct uwsgi_plugin {
const char *name;
const char *alias;
uint8_t modifier1;
void *data;
void (*on_load) (void);
int (*init) (void);
void (*post_init) (void);
void (*post_fork) (void);
struct uwsgi_option *options;
void (*enable_threads) (void);
void (*init_thread) (int);
int (*request) (struct wsgi_request *);
void (*after_request) (struct wsgi_request *);
void (*preinit_apps) (void);
void (*init_apps) (void);
void (*postinit_apps) (void);
void (*fixup) (void);
void (*master_fixup) (int);
void (*master_cycle) (void);
int (*mount_app) (char *, char *);
int (*manage_udp) (char *, int, char *, int);
void (*suspend) (struct wsgi_request *);
void (*resume) (struct wsgi_request *);
void (*harakiri) (int);
void (*hijack_worker) (void);
void (*spooler_init) (void);
void (*atexit) (void);
int (*magic) (char *, char *);
void *(*encode_string) (char *);
char *(*decode_string) (void *);
int (*signal_handler) (uint8_t, void *);
char *(*code_string) (char *, char *, char *, char *, uint16_t);
int (*spooler) (char *, char *, uint16_t, char *, size_t);
uint16_t(*rpc) (void *, uint8_t, char **, uint16_t *, char *);
void (*jail) (int (*)(void *), char **);
void (*before_privileges_drop)(void);
int (*mule)(char *);
int (*mule_msg)(char *, size_t);
void (*master_cleanup) (void);
};
#ifdef UWSGI_PCRE
int uwsgi_regexp_build(char *, pcre **, pcre_extra **);
int uwsgi_regexp_match(pcre *, pcre_extra *, char *, int);
int uwsgi_regexp_match_ovec(pcre *, pcre_extra *, char *, int, int *, int);
int uwsgi_regexp_ovector(pcre *, pcre_extra *);
char *uwsgi_regexp_apply_ovec(char *, int, char *, int, int *, int);
#endif
struct uwsgi_app {
uint8_t modifier1;
char mountpoint[0xff];
int mountpoint_len;
void *interpreter;
void *callable;
#ifdef UWSGI_ASYNC
void **args;
void **environ;
#else
void *args;
void *environ;
#endif
void *sendfile;
void *input;
void *error;
void *stream;
void *responder0;
void *responder1;
void *responder2;
#ifdef UWSGI_ASYNC
void *eventfd_read;
void *eventfd_write;
#endif
void *(*request_subhandler) (struct wsgi_request *, struct uwsgi_app *);
int (*response_subhandler) (struct wsgi_request *);
int argc;
uint64_t requests;
uint64_t exceptions;
char chdir[0xff];
char touch_reload[0xff];
time_t touch_reload_mtime;
void *gateway_version;
void *uwsgi_version;
void *uwsgi_node;
time_t started_at;
time_t startup_time;
uint64_t avg_response_time;
};
struct uwsgi_spooler {
char dir[PATH_MAX];
pid_t pid;
uint64_t respawned;
uint64_t tasks;
struct uwsgi_lock_item *lock;
time_t harakiri;
int mode;
int running;
int signal_pipe[2];
struct uwsgi_spooler *next;
};
#ifdef UWSGI_ROUTING
#define UWSGI_ROUTE_NEXT 0
#define UWSGI_ROUTE_CONTINUE 1
#define UWSGI_ROUTE_BREAK 2
struct uwsgi_route {
pcre *pattern;
pcre_extra *pattern_extra;
int ovn;
int *ovector;
size_t subject;
size_t subject_len;
int (*func)(struct wsgi_request *, struct uwsgi_route *);
void *data;
size_t data_len;
void *data2;
size_t data2_len;
// 64bit value for custom usage
uint64_t custom;
// true ifthis is the last rule of this kind
int is_last;
struct uwsgi_route *next;
};
struct uwsgi_router {
char *name;
int (*func)(struct uwsgi_route *, char *);
struct uwsgi_router *next;
};
#endif
#ifdef UWSGI_ALARM
struct uwsgi_alarm;
struct uwsgi_alarm_instance {
char *name;
char *arg;
void *data_ptr;
uint8_t data8;
uint16_t data16;
uint32_t data32;
uint64_t data64;
time_t last_run;
char *last_msg;
size_t last_msg_size;
struct uwsgi_alarm *alarm;
struct uwsgi_alarm_instance *next;
};
struct uwsgi_alarm {
char *name;
void (*init)(struct uwsgi_alarm_instance *);
void (*func)(struct uwsgi_alarm_instance *, char *, size_t);
struct uwsgi_alarm *next;
};
struct uwsgi_alarm_ll {
struct uwsgi_alarm_instance *alarm;
struct uwsgi_alarm_ll *next;
};
struct uwsgi_alarm_log {
pcre *pattern;
pcre_extra *pattern_extra;
int negate;
struct uwsgi_alarm_ll *alarms;
struct uwsgi_alarm_log *next;
};
#endif
struct __attribute__ ((packed)) uwsgi_header {
uint8_t modifier1;
uint16_t pktsize;
uint8_t modifier2;
};
struct uwsgi_async_fd {
int fd;
int event;
struct uwsgi_async_fd *prev;
struct uwsgi_async_fd *next;
};
struct uwsgi_logvar {
char key[256];
uint8_t keylen;
char val[256];
uint8_t vallen;
struct uwsgi_logvar *next;
};
struct wsgi_request {
struct uwsgi_header uh;
//temporary attr
int app_id;
int dynamic;
int parsed;
char *appid;
uint16_t appid_len;
struct pollfd poll;
//this is big enough to contain sockaddr_in
struct sockaddr_un c_addr;
int c_len;
//iovec
struct iovec *hvec;
uint64_t start_of_request;
uint64_t start_of_request_in_sec;
uint64_t end_of_request;