forked from Taymindis/nginx-link-function
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.c
More file actions
2700 lines (2482 loc) · 98.7 KB
/
backup.c
File metadata and controls
2700 lines (2482 loc) · 98.7 KB
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
/**
* @file ngx_http_link_func_module.c
* @author taymindis <cloudleware2015@gmail.com>
* @date Sun JAN 28 12:06:52 2018
*
* @brief A nginx_link_function module for Nginx.
*
* @section LICENSE
*
* Copyright (c) 2018, Taymindis <cloudleware2015@gmail.com>
*
* This module is licensed under the terms of the BSD license.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_link_func_module.h>
#define MODULE_NAME "nginx_link_function"
/****
*
* Configs
*
*/
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
#define NGX_SUBREQ_NORMAL 0
#define NGX_SUBREQ_CHECK_STATUS 1
#define NGX_SUBREQ_INCL_BODY 2
#define NGX_SUBREQ_INCL_ARGS 3
static ngx_conf_enum_t ngx_http_link_func_subrequest_flags[] = {
{ ngx_string("check_status"), NGX_SUBREQ_CHECK_STATUS }, // subrequest run synchronizely but waiting for response and check status
{ ngx_string("incl_body"), NGX_SUBREQ_INCL_BODY }, // include body with the subrequest
{ ngx_string("incl_args"), NGX_SUBREQ_INCL_ARGS }, // include args with the subrequest
// { ngx_string("parallel"), NGX_SUBREQ_PARALLEL }, // subrequest run parallely but waiting for response
{ ngx_null_string, 0 }
};
#endif
typedef struct {
ngx_str_node_t sn;
void *value;
} ngx_http_link_func_http_cache_value_node_t;
typedef struct {
ngx_rbtree_t rbtree;
ngx_rbtree_node_t sentinel;
ngx_slab_pool_t *shpool;
} ngx_http_link_func_http_shm_t;
typedef struct {
ngx_str_t name;
ngx_http_link_func_http_shm_t *shared_mem;
} ngx_http_link_func_http_shm_ctx_t;
typedef struct {
ngx_flag_t is_ssl_support;
ngx_flag_t is_module_enabled;
ngx_flag_t is_cache_defined;
ngx_http_link_func_http_shm_ctx_t *shm_ctx;
} ngx_http_link_func_main_conf_t;
typedef void (*ngx_http_link_func_app_handler)(ngx_link_func_ctx_t*);
typedef void (*ngx_http_link_func_app_cycle_handler)(ngx_link_func_cycle_t*);
typedef struct {
void *_app;
ngx_str_t _libname;
ngx_str_t _downloadlink;
ngx_str_t _headers;
ngx_str_t _ca_cart;
ngx_queue_t *_link_func_locs_queue;
ngx_array_t *_props;
} ngx_http_link_func_srv_conf_t;
typedef struct {
ngx_str_t key;
ngx_http_complex_value_t value;
} ngx_http_link_func_req_header_t;
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
typedef struct {
ngx_str_t uri;
// ngx_uint_t flag;
ngx_flag_t incl_args;
ngx_flag_t incl_body;
ngx_flag_t check_status;
} ngx_http_link_func_subreq_conf_t;
#endif
typedef struct {
ngx_str_t _method_name;
ngx_http_link_func_app_handler _handler;
ngx_array_t *ext_req_headers;
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
ngx_array_t *subrequests;
#endif
// ngx_msec_t proc_timeout;
} ngx_http_link_func_loc_conf_t;
typedef struct {
unsigned done: 1;
unsigned waiting_more_body: 1;
unsigned aio_processing: 1;
/**resp ctx**/
uintptr_t status_code;
ngx_str_t status_line;
ngx_str_t content_type;
ngx_buf_t *resp_content;
ngx_int_t rc;
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
ngx_uint_t subreq_curr_index;
// ngx_uint_t subreq_parallel_wait_cnt;
ngx_uint_t subreq_sequential_wait_cnt;
ngx_flag_t status_check;
#endif
} ngx_http_link_func_internal_ctx_t;
typedef struct {
ngx_queue_t _queue;
ngx_http_link_func_loc_conf_t* _loc_conf;
} ngx_http_link_func_loc_q_t;
static ngx_int_t ngx_http_link_func_pre_configuration(ngx_conf_t *cf);
static ngx_int_t ngx_http_link_func_post_configuration(ngx_conf_t *cf);
static void* ngx_http_link_func_get_duplicate_handler(ngx_http_link_func_srv_conf_t *scf, ngx_str_t *method_name);
static ngx_int_t ngx_http_link_func_application_compatibility_check(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf);
static char* ngx_http_link_func_validation_check_and_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char* ngx_http_link_func_set_link_func_shm(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
// static char *ngx_http_link_func_srv_post_conf_handler(ngx_conf_t *cf, void *data, void *conf);
static void *ngx_http_link_func_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_link_func_init_main_conf(ngx_conf_t *cf, void *conf);
static void * ngx_http_link_func_create_srv_conf(ngx_conf_t *cf);
static char * ngx_http_link_func_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child);
static void * ngx_http_link_func_create_loc_conf(ngx_conf_t *cf);
static char * ngx_http_link_func_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
static char *ngx_http_link_func_ext_req_headers_add_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_link_func_init_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
static char *ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
// static ngx_int_t ngx_http_link_func_subreqest_parallel_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
static ngx_int_t ngx_http_link_func_subrequest_done(ngx_http_request_t *r, void *data, ngx_int_t rc);
static ngx_int_t ngx_http_link_func_process_subrequest(ngx_http_request_t *r, ngx_http_link_func_subreq_conf_t *subreq, ngx_http_link_func_internal_ctx_t *ctx);
#endif
static ngx_int_t ngx_http_link_func_content_handler(ngx_http_request_t *r);
static ngx_int_t ngx_http_link_func_precontent_handler(ngx_http_request_t *r);
static void ngx_http_link_func_parse_ext_request_headers(ngx_http_request_t *r, ngx_array_t *ext_req_headers);
static ngx_int_t ngx_http_link_func_rewrite_handler(ngx_http_request_t *r);
static ngx_int_t ngx_http_link_func_process_init(ngx_cycle_t *cycle);
static void ngx_http_link_func_process_exit(ngx_cycle_t *cycle);
static ngx_int_t ngx_http_link_func_module_init(ngx_cycle_t *cycle);
static void ngx_http_link_func_master_exit(ngx_cycle_t *cycle);
static void ngx_http_link_func_client_body_handler(ngx_http_request_t *r);
static ngx_int_t ngx_http_link_func_proceed_init_calls(ngx_cycle_t* cycle, ngx_http_link_func_srv_conf_t *scf, ngx_http_link_func_main_conf_t* mcf);
static u_char* ngx_http_link_func_strdup_with_p(ngx_pool_t *pool, const char *src, size_t len);
#if (NGX_THREADS) && (nginx_version > 1013003)
static void ngx_http_link_func_after_process(ngx_event_t *ev);
static void ngx_http_link_func_process_t_handler(void *data, ngx_log_t *log);
#endif
/*** Download Feature Support ***/
typedef struct {
char* header_content;
size_t header_len;
char* body_content;
size_t body_len;
} ngx_http_link_func_http_header_body;
static int ngx_http_link_func_write_to_file(char* out_path, char* out_buff, size_t size, ngx_conf_t *cf);
static int strpos(const char *haystack, const char *needle);
static ngx_http_link_func_http_header_body* convert_to_http_header_body(char* final_buf, int curr_size, ngx_conf_t *cf);
static int ngx_http_link_func_connect_and_request(int *sockfd, ngx_http_link_func_srv_conf_t* scf, ngx_conf_t *cf);
static ngx_http_link_func_http_header_body* ngx_http_link_func_read_data_from_server(int *sockfd, ngx_conf_t *cf);
static ngx_http_link_func_http_header_body* ngx_http_link_func_http_request( ngx_conf_t *cf, ngx_http_link_func_srv_conf_t* scf);
#if (NGX_SSL || NGX_OPENSSL)
static int ngx_http_link_func_connect_and_request_via_ssl(int *sockfd, ngx_http_link_func_srv_conf_t* scf, SSL_CTX **ctx, SSL **ssl, ngx_conf_t *cf);
static ngx_http_link_func_http_header_body* ngx_http_link_func_read_data_from_server_via_ssl(SSL *ssl, ngx_conf_t *cf);
static ngx_http_link_func_http_header_body* ngx_http_link_func_https_request( ngx_conf_t *cf, ngx_http_link_func_srv_conf_t* scf);
#endif
/*** End Download Feature Support ***/
/**Extern interface**/
void ngx_link_func_cyc_log_debug(ngx_link_func_cycle_t *cyc, const char* msg);
void ngx_link_func_cyc_log_info(ngx_link_func_cycle_t *cyc, const char* msg);
void ngx_link_func_cyc_log_warn(ngx_link_func_cycle_t *cyc, const char* msg);
void ngx_link_func_cyc_log_err(ngx_link_func_cycle_t *cyc, const char* msg);
u_char* ngx_link_func_cyc_get_prop(ngx_link_func_cycle_t *cyc, const char *key, size_t keylen);
void ngx_link_func_log_debug(ngx_link_func_ctx_t *ctx, const char* msg);
void ngx_link_func_log_info(ngx_link_func_ctx_t *ctx, const char* msg);
void ngx_link_func_log_warn(ngx_link_func_ctx_t *ctx, const char* msg);
void ngx_link_func_log_err(ngx_link_func_ctx_t *ctx, const char* msg);
char *ngx_link_func_strdup(ngx_link_func_ctx_t *ctx, const char *src);
int ngx_link_func_get_uri(ngx_link_func_ctx_t *ctx, ngx_link_func_str_t *str);
u_char* ngx_link_func_get_real_remote_addr(ngx_link_func_ctx_t *ctx);
u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen);
u_char* ngx_link_func_get_prop(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen);
int ngx_link_func_add_header_in(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen, const char *value, size_t val_len );
int ngx_link_func_add_header_out(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen, const char *value, size_t val_len );
void* ngx_link_func_get_query_param(ngx_link_func_ctx_t *ctx, const char *key);
void* ngx_link_func_palloc(ngx_link_func_ctx_t *ctx, size_t size);
void* ngx_link_func_pcalloc(ngx_link_func_ctx_t *ctx, size_t size);
uintptr_t ngx_link_func_shmtx_trylock(void *shared_mem);
void ngx_link_func_shmtx_lock(void *shared_mem);
void ngx_link_func_shmtx_unlock(void *shared_mem);
void* ngx_link_func_shm_alloc(void *shared_mem, size_t size);
void ngx_link_func_shm_free(void *shared_mem, void *ptr);
void* ngx_link_func_shm_alloc_locked(void *shared_mem, size_t size);
void ngx_link_func_shm_free_locked(void *shared_mem, void *ptr);
void* ngx_link_func_cache_get(void *shared_mem, const char* key);
void* ngx_link_func_cache_put(void *shared_mem, const char* key, void* value);
void* ngx_link_func_cache_new(void *shared_mem, const char* key, size_t size);
void* ngx_link_func_cache_remove(void *shared_mem, const char* key);
// void ngx_link_func_set_resp_var(ngx_link_func_ctx_t *ctx, const char* resp_content, size_t resp_len);
void ngx_link_func_write_resp(ngx_link_func_ctx_t *ctx, uintptr_t status_code, const char* status_line, const char* content_type, const char* resp_content, size_t resp_len);
void ngx_link_func_write_resp_l(ngx_link_func_ctx_t *ctx, uintptr_t status_code, const char* status_line,
size_t status_line_len, const char* content_type, size_t content_type_len,
const char* resp_content, size_t resp_content_len);
/**End Extern interface**/
// static ngx_conf_post_t ngx_http_link_func_srv_post_conf = {
// ngx_http_link_func_srv_post_conf_handler
// };
/**
* This module provided directive.
*/
static ngx_command_t ngx_http_link_func_commands[] = {
{
ngx_string("ngx_link_func_shm_size"),
NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1,
ngx_http_link_func_set_link_func_shm,
NGX_HTTP_MAIN_CONF_OFFSET,
0,
NULL
},
{
ngx_string("ngx_link_func_lib"),
NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1,
ngx_http_link_func_validation_check_and_set_str_slot,
NGX_HTTP_SRV_CONF_OFFSET,
offsetof(ngx_http_link_func_srv_conf_t, _libname),
NULL//&ngx_http_link_func_srv_post_conf
},
{
ngx_string("ngx_link_func_download_link_lib"),
NGX_HTTP_SRV_CONF | NGX_CONF_TAKE23,
ngx_http_link_func_validation_check_and_set_str_slot,
NGX_HTTP_SRV_CONF_OFFSET,
0,
NULL
},
{
ngx_string("ngx_link_func_ca_cert"),
NGX_HTTP_SRV_CONF | NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_SRV_CONF_OFFSET,
offsetof(ngx_http_link_func_srv_conf_t, _ca_cart),
NULL
},
{ ngx_string("ngx_link_func_add_req_header"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_HTTP_LIF_CONF | NGX_CONF_TAKE2,
ngx_http_link_func_ext_req_headers_add_cmd,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL
},
#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
{ ngx_string("ngx_link_func_subrequest"), /* directive */
NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_1MORE, /* location context and takes up to 4 arguments*/
ngx_http_link_func_subrequest_cmd, /* configuration setup function */
NGX_HTTP_LOC_CONF_OFFSET, /* No offset. Only one context is supported. */
0, /* No offset when storing the module configuration on struct. */
NULL
},
#endif
{ ngx_string("ngx_link_func_call"), /* directive */
NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1, /* location context and takes 1 or 2 arguments*/
ngx_http_link_func_init_method, /* configuration setup function */
NGX_HTTP_LOC_CONF_OFFSET, /* No offset. Only one context is supported. */
offsetof(ngx_http_link_func_loc_conf_t, _method_name), /* No offset when storing the module configuration on struct. */
NULL
},
{ ngx_string("ngx_link_func_add_prop"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_CONF_TAKE2,
ngx_conf_set_keyval_slot,
NGX_HTTP_SRV_CONF_OFFSET,
offsetof(ngx_http_link_func_srv_conf_t, _props),
NULL
},
ngx_null_command /* command termination */
};
/* The module context. */
static ngx_http_module_t ngx_http_link_func_module_ctx = {
ngx_http_link_func_pre_configuration, /* preconfiguration */
ngx_http_link_func_post_configuration, /* postconfiguration */
ngx_http_link_func_create_main_conf, /* create main configuration */
ngx_http_link_func_init_main_conf, /* init main configuration */
ngx_http_link_func_create_srv_conf, /* create server configuration */
ngx_http_link_func_merge_srv_conf, /* merge server configuration */
ngx_http_link_func_create_loc_conf, /* create location configuration */
ngx_http_link_func_merge_loc_conf /* merge location configuration */
};
/* Module definition. */
ngx_module_t ngx_http_link_func_module = {
NGX_MODULE_V1,
&ngx_http_link_func_module_ctx, /* module context */
ngx_http_link_func_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, // ngx_http_link_func_module_init, /* init module */ move module init into process init function to make it reload every time
ngx_http_link_func_process_init, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
ngx_http_link_func_process_exit, /* exit process */
ngx_http_link_func_master_exit, /* exit master */
NGX_MODULE_V1_PADDING
};
//ngx_int_t
//ngx_http_link_func_shm_cache_init(ngx_shm_zone_t *shm_zone, void *data)
//{
// size_t len;
// ngx_http_link_func_http_shm_ctx_t *oshm = data;
// ngx_http_link_func_http_shm_ctx_t *nshm = shm_zone->data;
// ngx_slab_pool_t *shpool;
//
// if (oshm) {
// nshm->name = oshm->name;
// nshm->shared_mem = oshm->shared_mem;
// return NGX_OK;
// }
//
// shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
//
// if (shm_zone->shm.exists) {
// shm_zone->data = shpool->data;
// return NGX_OK;
// }
//
//
// nshm->shared_mem = ngx_slab_alloc(shpool, sizeof(ngx_http_link_func_http_shm_t));
// ngx_rbtree_init(&nshm->shared_mem->rbtree, &nshm->shared_mem->sentinel, ngx_str_rbtree_insert_value);
//
// nshm->shared_mem->shpool = shpool;
//
// len = sizeof(" in nginx link function session shared cache \"\"") + shm_zone->shm.name.len;
//
// nshm->shared_mem->shpool->log_ctx = ngx_slab_alloc(nshm->shared_mem->shpool, len);
// if (nshm->shared_mem->shpool->log_ctx == NULL) {
// return NGX_ERROR;
// }
//
// ngx_sprintf(nshm->shared_mem->shpool->log_ctx, " in nginx link function session shared cache \"%V\"%Z",
// &shm_zone->shm.name);
//
// nshm->shared_mem->shpool->log_nomem = 0;
//
// return NGX_OK;
//}
//
//static char*
//ngx_http_link_func_set_link_func_shm(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
// ngx_str_t *values;
// ngx_http_link_func_main_conf_t *mcf = conf;
// ngx_shm_zone_t *shm_zone;
// ngx_int_t pg_size;
//
// values = cf->args->elts;
//
// pg_size = ngx_parse_size(&values[1]);
//
// if (pg_size == NGX_ERROR) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Invalid cache size, please specify like 1m,1g and etc.");
// return NGX_CONF_ERROR;
// }
//
//
// shm_zone = ngx_shared_memory_add(cf, &mcf->shm_ctx->name, pg_size, &ngx_http_link_func_module);
// if (shm_zone == NULL) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Unable to allocate apps defined size");
// return NGX_CONF_ERROR;
// }
// mcf->is_cache_defined = 1;
// shm_zone->init = ngx_http_link_func_shm_cache_init;
// shm_zone->data = mcf->shm_ctx;
//
// return NGX_CONF_OK;
//}
//
//static char*
//ngx_http_link_func_validation_check_and_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
// ngx_str_t *values;
// ngx_http_link_func_srv_conf_t *scf = conf;
//
// ngx_http_link_func_main_conf_t *mcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_link_func_module);
//
// values = cf->args->elts;
//
// if (cf->args->nelts == 2 ) {
// if (values[1].len == 0 ) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Location link path is empty");
// return NGX_CONF_ERROR;
// }
// scf->_libname = values[1];
// } else if (cf->args->nelts == 3 ) {
// if (values[1].len > 0 && values[2].len > 0) {
// if (ngx_strncmp(values[1].data, "https://", 8) == 0) {
// if (! mcf->is_ssl_support) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "https is not support, please include openssl, alternatively, use http or use ngx_http_link_func_link_lib to direct link to your local file");
// return NGX_CONF_ERROR;
// } else {
// scf->_downloadlink = values[1];
// }
// } else if (ngx_strncmp(values[1].data, "http://", 7) == 0) {
// scf->_downloadlink = values[1];
// } else {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Download link is invalid, only http or https is allowed, please use ngx_http_link_func_link_lib to direct link to your local file");
// return NGX_CONF_ERROR;
// }
//
// } else {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Download link or destination path is empty");
// return NGX_CONF_ERROR;
// }
// scf->_libname = values[2];
// } else if (cf->args->nelts == 4 ) { // extra headers
// if (values[1].len > 0 && values[2].len > 0 && values[3].len > 0) {
// if (ngx_strncmp(values[1].data, "https://", 8) == 0) {
// if (! mcf->is_ssl_support) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "https is not support, please include openssl, alternatively, use http or use ngx_http_link_func_link_lib to direct link to your local file");
// return NGX_CONF_ERROR;
// } else {
// scf->_downloadlink = values[1];
// scf->_headers = values[2];
// }
// } else if (ngx_strncmp(values[1].data, "http://", 7) == 0) {
// scf->_downloadlink = values[1];
// scf->_headers = values[2];
// } else {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Download link is invalid, only http or https is allowed, please use ngx_http_link_func_link_lib to direct link to your local file");
// return NGX_CONF_ERROR;
// }
// } else {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Download link, headers or destination path is empty, if you don't need headers, please specify with 2 parameter only");
// return NGX_CONF_ERROR;
// }
// scf->_libname = values[3];
// }
//
// mcf->is_module_enabled = 1;
//
// return NGX_CONF_OK;
//}
// static char *ngx_http_link_func_srv_post_conf_handler(ngx_conf_t *cf, void *data, void *conf) {
// ngx_str_t *value = conf;
// ngx_http_link_func_srv_conf_t *scf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_link_func_module);
// if (value->len > 0) {
// scf->_app = dlopen((char*) value->data, RTLD_LAZY | RTLD_NOW);
// if ( !scf->_app ) {
// ngx_conf_log_error(NGX_LOG_ERR, cf, 0, "%s", "unable to initialized the library ");
// return NGX_CONF_ERROR;
// } else {
// ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "Apps %V loaded successfully ", value);
// }
// }
// return NGX_CONF_OK;
// } /* ngx_http_link_func_srv_post_conf_handler */
//static char *
//ngx_http_link_func_ext_req_headers_add_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
// ngx_http_link_func_loc_conf_t *lcf = conf;
// ngx_str_t *value;
// ngx_http_link_func_req_header_t *hdr;
// ngx_http_compile_complex_value_t ccv;
//
// value = cf->args->elts;
//
// if (lcf->ext_req_headers == NULL || lcf->ext_req_headers == NGX_CONF_UNSET_PTR) {
// lcf->ext_req_headers = ngx_array_create(cf->pool, 2,
// sizeof(ngx_http_link_func_req_header_t));
// if (lcf->ext_req_headers == NULL) {
// return NGX_CONF_ERROR;
// }
// }
//
// hdr = ngx_array_push(lcf->ext_req_headers);
// if (hdr == NULL) {
// return NGX_CONF_ERROR;
// }
//
// hdr->key = value[1];
//
// ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
//
// ccv.cf = cf;
// ccv.value = &value[2];
// ccv.complex_value = &hdr->value;
//
// if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
// return NGX_CONF_ERROR;
// }
// return NGX_CONF_OK;
//}
//
//#if (NGX_LINK_FUNC_SUBREQ) && (nginx_version > 1013009)
//
//static char *
//ngx_http_link_func_subrequest_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
// ngx_http_link_func_loc_conf_t *lcf = conf;
// ngx_str_t *values;
// ngx_http_link_func_subreq_conf_t *subreq;
// ngx_uint_t i, j;
// ngx_conf_enum_t *e;
//
// values = cf->args->elts;
//
// if (lcf->subrequests == NULL || lcf->subrequests == NGX_CONF_UNSET_PTR) {
// lcf->subrequests = ngx_array_create(cf->pool, 2, sizeof(ngx_http_link_func_subreq_conf_t));
// if (lcf->subrequests == NULL) {
// return NGX_CONF_ERROR;
// }
// }
//
// subreq = ngx_array_push(lcf->subrequests);
// if (subreq == NULL) {
// return NGX_CONF_ERROR;
// }
// ngx_memzero(subreq, sizeof(ngx_http_link_func_subreq_conf_t));
//
// for (i = 1; i < cf->args->nelts; i++) {
// if (i == 1) {
// subreq->uri = values[i];
// } else {
// e = ngx_http_link_func_subrequest_flags;
// for (j = 0; e[j].name.len != 0; j++) {
// if (e[j].name.len == values[i].len
// && ngx_strcasecmp(e[j].name.data, values[i].data) == 0) {
// // subreq->flag = e[j].value;
//// #if(NGX_THREADS)
//// if (subreq->flag == NGX_SUBREQ_PARALLEL) {
//// return "parallel request is not applicable in aio threads yet.";
//// }
//// #endif
// switch (e[j].value) {
// case NGX_SUBREQ_CHECK_STATUS:
// subreq->check_status = 1;
// break;
// case NGX_SUBREQ_INCL_ARGS:
// subreq->incl_args = 1;
// break;
// case NGX_SUBREQ_INCL_BODY:
// subreq->incl_body = 1;
// break;
// default:
// return "invalid subrequest flag given, either incl_args, incl_body or check_status.";
// }
// break;
// }
// }
//
// if (e[j].name.len == 0) {
// return "invalid subrequest flag given, either incl_args, incl_body or check_status.";
// }
//
// } /*else if (i == 3) {
// if ( (sizeof("on") - 1) == values[i].len && ngx_strcasecmp((u_char*)"on", values[i].data) == 0) {
// subreq->incl_args = 1;
// }
// } else if (i == 4) {
// if ( (sizeof("on") - 1) == values[i].len && ngx_strcasecmp((u_char*)"on", values[i].data) == 0) {
// subreq->incl_body = 1;
// }
// }*/
// }
// return NGX_CONF_OK;
//}
//#endif
//
///**
// * Configuration setup function that installs the content handler.
// *
// * @param cf
// * Module configuration structure pointer.
// * @param cmd
// * Module directives structure pointer.
// * @param conf
// * Module configuration structure pointer.
// * @return string
// * Status of the configuration setup.
// */
//static char *
//ngx_http_link_func_init_method(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) {
// ngx_http_link_func_srv_conf_t *scf;
//
// scf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_link_func_module);
//
// if (scf && scf->_libname.len > 0) {
// return ngx_conf_set_str_slot(cf, cmd, conf);
// }
//
// return "No application linking in server block";
//} /* ngx_http_link_func_init_method */
//
//static ngx_int_t
//ngx_http_link_func_proceed_init_calls(ngx_cycle_t* cycle, ngx_http_link_func_srv_conf_t *scf, ngx_http_link_func_main_conf_t* mcf) {
// /**** Init the client apps ngx_http_link_func_init ***/
// char *error;
// ngx_http_link_func_app_cycle_handler func;
//
//#if __FreeBSD__
// (void) dlerror();
//#endif
//
// *(void**)(&func) = dlsym(scf->_app, (const char*)"ngx_link_func_init_cycle");
// if ((error = dlerror()) != NULL) {
// ngx_log_error(NGX_LOG_WARN, cycle->log, 0, "Unable to init call %s , skipped init called", error);
// } else {
// ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "application initializing");
// /*** Init the apps ***/
// ngx_link_func_cycle_t appcyc;
// appcyc.has_error = 0;
// appcyc.__cycle__ = cycle;
// appcyc.__srv_cf__ = scf;
// appcyc.__pl__ = cycle->pool;
// appcyc.__log__ = cycle->log;
// appcyc.shared_mem = (void*)mcf->shm_ctx->shared_mem;
// func(&appcyc);
// if (appcyc.has_error) {
// ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "%s", "link function worker Initialize unsuccessfully");
// return NGX_ERROR;
// }
// }
//
// ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "%s", "Done proceed init calls");
// return NGX_OK;
//}
//
//static ngx_int_t
//ngx_http_link_func_post_configuration(ngx_conf_t *cf) {
// ngx_http_link_func_main_conf_t *mcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_link_func_module);
//
// if (mcf != NULL && mcf->is_module_enabled ) {
// ngx_http_handler_pt *h;
// ngx_http_core_main_conf_t *cmcf;
//
// cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
//
// if ( cmcf == NULL ) {
// return NGX_ERROR;
// }
//
// if ( ngx_http_link_func_application_compatibility_check(cf, cmcf) == NGX_ERROR ) {
// return NGX_ERROR;
// }
//
// h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
// if (h == NULL) {
// return NGX_ERROR;
// }
//
// *h = ngx_http_link_func_rewrite_handler;
//
// /***Enable pre content phase for apps concurrent processing request layer, NGX_DONE and wait for finalize request ***/
//#if (nginx_version > 1013003)
// h = ngx_array_push(&cmcf->phases[NGX_HTTP_PRECONTENT_PHASE].handlers);
// if (h == NULL) {
// return NGX_ERROR;
// }
// *h = ngx_http_link_func_precontent_handler;
//
// h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
// if (h == NULL) {
// return NGX_ERROR;
// }
// *h = ngx_http_link_func_content_handler;
//#else
// h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
//
// if (h == NULL) {
// return NGX_ERROR;
// }
//
// *h = ngx_http_link_func_precontent_handler;
//
//#endif
//
// }
//
// /*** Default Init for shm with 1M if pool is empty***/
// if (mcf != NULL && !mcf->is_cache_defined ) {
// ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "%s", "Init Default Share memory with 1M");
// ngx_str_t default_size = ngx_string("1M");
//
// ngx_shm_zone_t *shm_zone = ngx_shared_memory_add(cf, &mcf->shm_ctx->name, ngx_parse_size(&default_size), &ngx_http_link_func_module);
// if (shm_zone == NULL) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Unable to allocate size");
// return NGX_ERROR;
// }
//
// shm_zone->init = ngx_http_link_func_shm_cache_init;
// shm_zone->data = mcf->shm_ctx;
// }
//
// return NGX_OK;
//}
static ngx_int_t
ngx_http_link_func_pre_configuration(ngx_conf_t *cf) {
#if (nginx_version < 1010003)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "nginx-link-function is not support nginx version below 1.10");
return NGX_ERROR;
#endif
#ifndef ngx_link_func_module_version_34
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "the ngx_http_link_func_module.h might not be latest or not found in the c header path, \
please copy latest ngx_http_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
with read and write permission.");
return NGX_ERROR;
#endif
return NGX_OK;
}
//static void*
//ngx_http_link_func_get_duplicate_handler(ngx_http_link_func_srv_conf_t *scf, ngx_str_t *method_name) {
// /* this is only do when init or exit application, don't be count as performance issue, this is for same method merged */
// ngx_queue_t* q;
// for (q = ngx_queue_head(scf->_link_func_locs_queue);
// q != ngx_queue_sentinel(scf->_link_func_locs_queue);
// q = ngx_queue_next(q)) {
// ngx_http_link_func_loc_q_t* cflq = (ngx_http_link_func_loc_q_t *) q;
// ngx_http_link_func_loc_conf_t *lcf = cflq->_loc_conf;
// if ( lcf && lcf->_method_name.len > 0 ) {
// if ( lcf->_handler && lcf->_method_name.len == method_name->len &&
// ngx_strncmp(lcf->_method_name.data, method_name->data, method_name->len) == 0 ) {
// return lcf->_handler;
// }
// }
// }
// return NULL;
//}
//static ngx_int_t
//ngx_http_link_func_application_compatibility_check(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf) {
// ngx_uint_t s;
// ngx_http_link_func_srv_conf_t *scf;
// ngx_http_core_srv_conf_t **cscfp;
//
// cscfp = cmcf->servers.elts;
//
//#if (NGX_THREADS) && (nginx_version > 1013003)
// ngx_conf_log_error(NGX_LOG_NOTICE, cf, 0, " enabled aio threads for link-function module ");
//#endif
// for (s = 0; s < cmcf->servers.nelts; s++) {
// ngx_http_core_srv_conf_t *cscf = cscfp[s];
// scf = cscf->ctx->srv_conf[ngx_http_link_func_module.ctx_index];
// if (scf && scf->_libname.len > 0 ) {
// ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "%s", "Loading application= %V", &scf->_libname);
//
// if (scf->_downloadlink.len > 0 ) {
// if (ngx_strncmp(scf->_downloadlink.data, "https://", 8) == 0) {
//#if (NGX_SSL || NGX_OPENSSL)
// ngx_http_link_func_https_request(cf, scf);
//#endif
// } else if (ngx_strncmp(scf->_downloadlink.data, "http://", 7) == 0) {
// ngx_http_link_func_http_request( cf, scf);
// }
// }
//
// char *error;
// scf->_app = dlopen((char*) scf->_libname.data, RTLD_LAZY | RTLD_NOW);
// if ( !scf->_app ) {
// if ((error = dlerror()) != NULL) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "unable to initialized the Application %s", error);
// } else {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "unable to initialized the Application unknown issue");
// }
// return NGX_ERROR;
// }
//
//#if __FreeBSD__
// (void) dlerror();
//#endif
// /* * check init function block, this version has to be at least init with empty function * */
// ngx_http_link_func_app_cycle_handler func;
// *(void**)(&func) = dlsym(scf->_app, (const char*)"ngx_link_func_init_cycle");
// if ((error = dlerror()) != NULL) {
// ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
// "function ngx_link_func_init_cycle(ngx_link_func_cycle_t *cycle) not found in \"%V\", at least create an empty init function block \n %s",
// &scf->_libname, error);
// return NGX_ERROR;
// }
//
//#if __FreeBSD__
// (void) dlerror();
//#endif
//
// *(void**)(&func) = dlsym(scf->_app, (const char*)"ngx_link_func_exit_cycle");
// if ((error = dlerror()) != NULL) {
// ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
// "function ngx_link_func_exit_cycle(ngx_link_func_cycle_t *cycle) not found in \"%V\", at least create an empty exit function block \n %s",
// &scf->_libname, error);
// }
//
//
// /*** loop and without remove queue***/
// ngx_queue_t* q;
// for (q = ngx_queue_head(scf->_link_func_locs_queue);
// q != ngx_queue_sentinel(scf->_link_func_locs_queue);
// q = ngx_queue_next(q)) {
// ngx_http_link_func_loc_q_t* cflq = (ngx_http_link_func_loc_q_t *) q;
//
// ngx_http_link_func_loc_conf_t *lcf = cflq->_loc_conf;
// if ( lcf && lcf->_method_name.len > 0 ) {
//
//#if __FreeBSD__
// (void) dlerror();
//#endif
//
// *(void**)(&lcf->_handler) = dlsym(scf->_app, (const char*)lcf->_method_name.data);
// if ((error = dlerror()) != NULL) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "Error function load: %s", error);
// return NGX_ERROR;
// }
// lcf->_handler = NULL; // reset back
// } else {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "Ambiguous function name");
// return NGX_ERROR;
// }
// }
//
// if (dlclose(scf->_app) != 0) {
// ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "Error to unload the app lib %V", &scf->_libname);
// return NGX_ERROR;
// } else {
// ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "app \"%V\" successfully verified", &scf->_libname);
// scf->_app = NULL; // reset back
// }
// } else {
// continue;
// }
// }
// return NGX_OK;
//}
static ngx_int_t
ngx_http_link_func_module_init(ngx_cycle_t *cycle) {
// we could load our dll directly here and avoid the other work
ngx_uint_t s;
ngx_http_link_func_srv_conf_t *scf;
ngx_http_core_srv_conf_t **cscfp;
ngx_http_core_main_conf_t *cmcf;
ngx_http_conf_ctx_t *ctx = (ngx_http_conf_ctx_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_module);
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
cscfp = cmcf->servers.elts;
#if (NGX_THREADS) && (nginx_version > 1013003)
ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, " enabled aio threads for link-function module ");
#endif
for (s = 0; s < cmcf->servers.nelts; s++) {
ngx_http_core_srv_conf_t *cscf = cscfp[s];
scf = cscf->ctx->srv_conf[ngx_http_link_func_module.ctx_index];
if (scf && scf->_libname.len > 0 ) {
ngx_log_error(NGX_LOG_DEBUG, cycle->log, 0, "Loading application= %V", &scf->_libname);
char *error;
scf->_app = dlopen((char*) scf->_libname.data, RTLD_LAZY | RTLD_NOW);
if ( !scf->_app ) {
if ((error = dlerror()) != NULL) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "unable to initialized the Application %s", error);
} else {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "%s", "unable to initialized the Application, unknown issue");
}
return NGX_ERROR;
} else {
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "Application %V loaded successfully ", &scf->_libname);
}
/*** loop and without remove queue***/
ngx_queue_t* q;
for (q = ngx_queue_head(scf->_link_func_locs_queue);
q != ngx_queue_sentinel(scf->_link_func_locs_queue);
q = ngx_queue_next(q)) {
ngx_http_link_func_loc_q_t* cflq = (ngx_http_link_func_loc_q_t *) q;
ngx_http_link_func_loc_conf_t *lcf = cflq->_loc_conf;
if ( lcf && lcf->_method_name.len > 0 ) {
if ( ( lcf->_handler = ngx_http_link_func_get_duplicate_handler(scf, &lcf->_method_name) ) == NULL ) {
#if __FreeBSD__
(void) dlerror();
#endif
*(void**)(&lcf->_handler) = dlsym(scf->_app, (const char*)lcf->_method_name.data);
if ((error = dlerror()) != NULL) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "Error function load: %s", error);
return NGX_ERROR;
}
}
} else {
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "%s", "Ambiguous function name");
return NGX_ERROR;
}
}
/*** Loop and remove queue, don't retain the queue ***/
while (! (ngx_queue_empty(scf->_link_func_locs_queue)) ) {
ngx_queue_t* q = ngx_queue_head(scf->_link_func_locs_queue);
// ngx_http_link_func_loc_q_t* cflq = ngx_queue_data(q, ngx_http_link_func_loc_q_t, _queue);
// ngx_http_link_func_loc_conf_t *lcf = cflq->_loc_conf;
// if ( lcf && lcf->_method_name.len > 0 ) {
// *(void**)(&lcf->_handler) = dlsym(scf->_app, (const char*)lcf->_method_name.data);
// if ((error = dlerror()) != NULL) {
// ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "Error function load: %s", error);
// return NGX_ERROR;
// }
// } else {
// ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "%s", "Ambiguous function name");
// return NGX_ERROR;
// }
ngx_queue_remove(q);
}
} else {
continue;
}
}
return NGX_OK;
}
static ngx_int_t
ngx_http_link_func_process_init(ngx_cycle_t *cycle) {
ngx_uint_t s;
ngx_http_link_func_srv_conf_t *scf;
ngx_http_core_srv_conf_t **cscfp;
ngx_http_core_main_conf_t *cmcf;
ngx_http_link_func_main_conf_t *mcf;
/** Only initialize when it is NGINX Worker or Single **/
if (ngx_process != NGX_PROCESS_WORKER && ngx_process != NGX_PROCESS_SINGLE) {
return NGX_OK;
}
if (ngx_http_link_func_module_init(cycle) == NGX_ERROR) {
return NGX_ERROR;
}
ngx_http_conf_ctx_t *ctx = (ngx_http_conf_ctx_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_module);
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
mcf = ctx->main_conf[ngx_http_link_func_module.ctx_index];
cscfp = cmcf->servers.elts;
for (s = 0; s < cmcf->servers.nelts; s++) {
ngx_http_core_srv_conf_t *cscf = cscfp[s];
scf = cscf->ctx->srv_conf[ngx_http_link_func_module.ctx_index];
if (scf && scf->_libname.len > 0 ) {