forked from unbit/uwsgi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uwsgi.h
4127 lines (3164 loc) · 102 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 UMAX8 256
#define UMAX64_STR "18446744073709551615"
#define MAX64_STR "−9223372036854775808"
#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
#define uwsgi_log_alarm(x, ...) uwsgi_log("[uwsgi-alarm" x, __VA_ARGS__)
#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.is_et) {\
if (uwsgi.use_thunder_lock) {\
uwsgi_lock(uwsgi.the_thunder_lock);\
}\
else if (uwsgi.threads > 1) {\
pthread_mutex_lock(&uwsgi.thunder_mutex);\
}\
}
#define thunder_unlock if (!uwsgi.is_et) {\
if (uwsgi.use_thunder_lock) {\
uwsgi_unlock(uwsgi.the_thunder_lock);\
}\
else if (uwsgi.threads > 1) {\
pthread_mutex_unlock(&uwsgi.thunder_mutex);\
}\
}
#define uwsgi_check_scheme(file) (!uwsgi_startswith(file, "emperor://", 10) || !uwsgi_startswith(file, "http://", 7) || !uwsgi_startswith(file, "data://", 7) || !uwsgi_startswith(file, "sym://", 6) || !uwsgi_startswith(file, "fd://", 5) || !uwsgi_startswith(file, "exec://", 7) || !uwsgi_startswith(file, "section://", 10))
#define uwsgi_n64(x) strtoul(x, NULL, 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 UWSGI_OPT_REQ_LOG_MASTER (1 << 14)
#define MAX_GENERIC_PLUGINS 64
#define MAX_GATEWAYS 64
#define MAX_TIMERS 64
#define MAX_CRONS 64
#define UWSGI_VIA_SENDFILE 1
#define UWSGI_VIA_ROUTE 2
#define UWSGI_VIA_OFFLOAD 3
#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
#ifdef __sun__
#define _XPG4_2
#define __EXTENSIONS__
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#ifdef __UCLIBC__
#include <sched.h>
#endif
#undef _GNU_SOURCE
#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
#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>
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__
#ifndef MAC_OS_X_VERSION_MIN_REQUIRED
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4
#endif
#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 _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif
#if defined(__sun__)
#define WAIT_ANY (-1)
#include <sys/filio.h>
#define PRIO_MAX 20
#endif
#if defined(__HAIKU__) || defined(__CYGWIN__)
#ifndef WAIT_ANY
#define WAIT_ANY (-1)
#endif
#define PRIO_MAX 20
#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__)
#elif defined(__CYGWIN__)
#elif defined(__HURD__)
#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_FLAG_UNGETTABLE 0x01
#define UWSGI_CACHE_FLAG_UPDATE 1 << 1
#define UWSGI_CACHE_FLAG_LOCAL 1 << 2
#define UWSGI_CACHE_FLAG_ABSEXPIRE 1 << 3
#define UWSGI_CACHE_FLAG_MATH 1 << 4
#define UWSGI_CACHE_FLAG_INC 1 << 5
#define UWSGI_CACHE_FLAG_DEC 1 << 6
#define UWSGI_CACHE_FLAG_MUL 1 << 7
#define UWSGI_CACHE_FLAG_DIV 1 << 8
#define UWSGI_CACHE_FLAG_FIXEXPIRE 1 << 9
#ifdef UWSGI_SSL
#include "openssl/conf.h"
#include "openssl/ssl.h"
#include <openssl/err.h>
#endif
#include <glob.h>
#ifdef __CYGWIN__
#define __WINCRYPT_H__
#include <windows.h>
#ifdef UWSGI_UUID
#undef uuid_t
#endif
#undef CMSG_DATA
#define CMSG_DATA(cmsg) \
((unsigned char *) ((struct cmsghdr *)(cmsg) + 1))
#endif
struct uwsgi_buffer {
char *buf;
size_t pos;
size_t len;
size_t limit;
#ifdef UWSGI_DEBUG_BUFFER
int freed;
#endif
};
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)
#define uwsgi_wait_read_req(x) uwsgi.wait_read_hook(x->fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) ; x->switches++
#define uwsgi_wait_write_req(x) uwsgi.wait_write_hook(x->fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) ; x->switches++
#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
struct uwsgi_rbtree {
struct uwsgi_rb_timer *root;
struct uwsgi_rb_timer *sentinel;
};
struct uwsgi_rb_timer {
uint8_t color;
struct uwsgi_rb_timer *parent;
struct uwsgi_rb_timer *left;
struct uwsgi_rb_timer *right;
uint64_t value;
void *data;
};
struct uwsgi_rbtree *uwsgi_init_rb_timer(void);
struct uwsgi_rb_timer *uwsgi_min_rb_timer(struct uwsgi_rbtree *, struct uwsgi_rb_timer *);
struct uwsgi_rb_timer *uwsgi_add_rb_timer(struct uwsgi_rbtree *, uint64_t, void *);
void uwsgi_del_rb_timer(struct uwsgi_rbtree *, struct uwsgi_rb_timer *);
union uwsgi_sockaddr {
struct sockaddr sa;
struct sockaddr_in sa_in;
struct sockaddr_un sa_un;
#ifdef AF_INET6
struct sockaddr_in6 sa_in6;
#endif
};
union uwsgi_sockaddr_ptr {
struct sockaddr *sa;
struct sockaddr_in *sa_in;
struct sockaddr_un *sa_un;
#ifdef AF_INET6
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;
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;
#ifdef UWSGI_SSL
char *legion;
#endif
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;
char *buf;
// used by choosen logger
char *arg;
struct uwsgi_logger *next;
};
#ifdef UWSGI_SSL
struct uwsgi_legion_node {
char *name;
uint16_t name_len;
uint64_t valor;
char uuid[37];
char *scroll;
uint16_t scroll_len;
uint64_t checksum;
uint64_t lord_valor;
char lord_uuid[36];
time_t last_seen;
struct uwsgi_legion_node *prev;
struct uwsgi_legion_node *next;
};
struct uwsgi_legion {
char *legion;
uint16_t legion_len;
uint64_t valor;
char *addr;
char *name;
uint16_t name_len;
pid_t pid;
char uuid[37];
int socket;
int quorum;
int changed;
// set to 1 first time when quorum is reached
int joined;
uint64_t checksum;
char *scroll;
uint16_t scroll_len;
char *lord_scroll;
uint16_t lord_scroll_len;
uint16_t lord_scroll_size;
char lord_uuid[36];
uint64_t lord_valor;
time_t i_am_the_lord;
time_t unix_check;
time_t last_warning;
struct uwsgi_lock_item *lock;
EVP_CIPHER_CTX *encrypt_ctx;
EVP_CIPHER_CTX *decrypt_ctx;
char *scrolls;
uint64_t scrolls_len;
uint64_t scrolls_max_size;
// found nodes dynamic lists
struct uwsgi_legion_node *nodes_head;
struct uwsgi_legion_node *nodes_tail;
// static list of nodes to send announces to
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_string_list *join_hooks;
struct uwsgi_string_list *node_joined_hooks;
struct uwsgi_string_list *node_left_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;
};
struct uwsgi_hash_algo {
char *name;
uint32_t(*func) (char *, uint64_t);
struct uwsgi_hash_algo *next;
};
struct uwsgi_hash_algo *uwsgi_hash_algo_get(char *);
void uwsgi_hash_algo_register(char *, uint32_t(*)(char *, uint64_t));
void uwsgi_hash_algo_register_all(void);
// maintain alignment here !!!
struct uwsgi_cache_item {
// item specific flags
uint64_t flags;
// size of the key
uint64_t keysize;
// hash of the key
uint64_t hash;
// size of the value (64bit)
uint64_t valsize;
// block position (in non-bitmap mode maps to the key index)
uint64_t first_block;
// 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 characters follows...
char key[];
} __attribute__ ((__packed__));
struct uwsgi_cache {
char *name;
uint16_t name_len;
uint64_t keysize;
uint64_t blocks;
uint64_t blocksize;
struct uwsgi_hash_algo *hash;
uint64_t *hashtable;
uint32_t hashsize;
uint64_t first_available_block;
uint64_t *unused_blocks_stack;
uint64_t unused_blocks_stack_ptr;
uint8_t use_blocks_bitmap;
uint8_t *blocks_bitmap;
uint64_t blocks_bitmap_pos;
uint64_t blocks_bitmap_size;
uint64_t max_items;
uint64_t max_item_size;
uint64_t n_items;
struct uwsgi_cache_item *items;
uint8_t use_last_modified;
time_t last_modified_at;
void *data;
uint8_t no_expire;
uint64_t full;
uint64_t hits;
uint64_t miss;
char *store;
uint64_t filesize;
uint64_t store_sync;
int64_t math_initial;
struct uwsgi_string_list *nodes;
int udp_node_socket;
struct uwsgi_string_list *sync_nodes;
struct uwsgi_string_list *udp_servers;
struct uwsgi_lock_item *lock;
struct uwsgi_cache *next;
};
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 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__)
#elif defined(__HURD__)
#define PATH_MAX 8192
#define RTLD_DEFAULT ((void *) 0)
#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_OPTION_MAX_WORKER_LIFETIME 19
#define UWSGI_OPTION_MIN_WORKER_LIFETIME 20
#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;
// this is the protocol internal name
char *proto_name;
// call that when a request is accepted
int (*proto_accept) (struct wsgi_request *, int);
// call that to parse the request (without the body)
int (*proto) (struct wsgi_request *);
// call that to write reponse
int (*proto_write) (struct wsgi_request *, char *, size_t);
// call that to write headers (if a special case is needed for them)
int (*proto_write_headers) (struct wsgi_request *, char *, size_t);
// call that when sendfile() is invoked
int (*proto_sendfile) (struct wsgi_request *, int, size_t, size_t);
// call that to read the body of a request (could map to a simple read())
ssize_t(*proto_read_body) (struct wsgi_request *, char *, size_t);
// hook to call when a new series of response headers is created
struct uwsgi_buffer *(*proto_prepare_headers) (struct wsgi_request *, char *, uint16_t);
// hook to call when a header must be added
struct uwsgi_buffer *(*proto_add_header) (struct wsgi_request *, char *, uint16_t, char *, uint16_t);
// last function to call before sending headers to the client
int (*proto_fix_headers) (struct wsgi_request *);
// hook to call when a request is closed
void (*proto_close) (struct wsgi_request *);
// special hook to call (if needed) in multithread mode
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);
struct uwsgi_buffer* (*backtrace)(struct wsgi_request *);
struct uwsgi_buffer* (*exception_class)(struct wsgi_request *);
struct uwsgi_buffer* (*exception_msg)(struct wsgi_request *);
struct uwsgi_buffer* (*exception_repr)(struct wsgi_request *);
void (*exception_log)(struct wsgi_request *);
};
#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