Skip to content

Commit 4bd56d4

Browse files
committed
adding switch to enable and disable the sdk
1 parent dfca2b5 commit 4bd56d4

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

ngx_http_fs_sdk_module.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ static char *ngx_http_add_params(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2626
static char *ngx_http_fs_sdk(ngx_conf_t *cf, void *post, void *data);
2727
static ngx_conf_post_handler_pt ngx_http_fs_sdk_p = ngx_http_fs_sdk;
2828

29-
#if FLAGSHIP_SDK_ENABLED
3029
typedef struct
3130
{
3231
ngx_array_t *params;
@@ -35,7 +34,6 @@ typedef struct
3534
ngx_str_t visitor_flags;
3635

3736
} ngx_http_fs_sdk_init_loc_conf_t;
38-
#endif
3937

4038
static void *ngx_http_fs_sdk_init_create_loc_conf(ngx_conf_t *cf)
4139
{
@@ -49,8 +47,8 @@ static void *ngx_http_fs_sdk_init_create_loc_conf(ngx_conf_t *cf)
4947

5048
return conf;
5149
}
52-
#if FLAGSHIP_SDK_ENABLED
5350

51+
#if FLAGSHIP_SDK_ENABLED
5452
static int flagship_sdk_initialized = 0;
5553

5654
static ngx_str_t env_id_string;
@@ -61,7 +59,6 @@ static ngx_str_t log_level_string;
6159
static void (*init_flagship)(char *, char *, int, char *);
6260
static char *(*get_all_flags)(char *, char *);
6361
#endif
64-
6562
/**
6663
* This module provided directive: fs_init, set_visitor_id, set_visitor_context, get_all_flags.
6764
*
@@ -103,10 +100,6 @@ static ngx_command_t ngx_http_fs_sdk_commands[] = {
103100
ngx_null_command /* command termination */
104101
};
105102

106-
/* The sdk init string. */
107-
//static u_char ngx_sdk_init[] = SDK_INIT;
108-
//static u_char ngx_it_works[] = IT_WORKS;
109-
110103
/* The module context. */
111104
static ngx_http_module_t ngx_http_fs_sdk_module_ctx = {
112105
ngx_http_fs_sdk_add_variables, /* preconfiguration */
@@ -214,6 +207,7 @@ static void initialize_flagship_sdk(char *sdk_path, ngx_http_request_t *r)
214207

215208
//create the sdk init handle
216209
init_flagship((char *)env_id_string.data, (char *)api_key_string.data, 60, (char *)log_level_string.data);
210+
217211
flagship_sdk_initialized = 1;
218212
}
219213
#endif
@@ -259,14 +253,6 @@ static ngx_int_t ngx_http_fs_sdk_get_all_flags_handler(ngx_http_request_t *r)
259253
out.buf = b;
260254
out.next = NULL; /* just one buffer */
261255

262-
/* #if FLAGSHIP_SDK_ENABLED
263-
264-
265-
266-
#else
267-
268-
#endif */
269-
270256
b->last = ngx_sprintf(b->last, "Active connections: %s \n", cglcf->visitor_flags.data);
271257

272258
r->headers_out.status = NGX_HTTP_OK;
@@ -277,12 +263,6 @@ static ngx_int_t ngx_http_fs_sdk_get_all_flags_handler(ngx_http_request_t *r)
277263

278264
b->last_in_chain = 1;
279265

280-
/* b->pos = (u_char *)msg; */ /* first position in memory of the data */
281-
/* b->last = (u_char *)msg + ((long int)ngx_strlen((const char *)msg)); */ /* last position in memory of the data */
282-
283-
/* b->memory = 1; */ /* content is in read-only memory */
284-
/* b->last_buf = 1; */ /* there will be no more buffers in the request */
285-
286266
/* Sending the headers for the reply. */
287267
r->headers_out.status = NGX_HTTP_OK; /* 200 status code */
288268
/* Get the content length of the body. */
@@ -318,6 +298,7 @@ static char *ngx_http_add_params(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
318298
pcf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_core_module);
319299
pcf->handler = ngx_http_fs_sdk_get_all_flags_handler;
320300

301+
#if FLAGSHIP_SDK_ENABLED
321302
ngx_str_t *value;
322303
ngx_array_t **params;
323304

@@ -355,6 +336,7 @@ static char *ngx_http_add_params(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
355336

356337
log_level_string.data = value[4].data;
357338
log_level_string.len = ngx_strlen(log_level_string.data);
339+
#endif
358340

359341
return NGX_CONF_OK;
360342
}
@@ -363,7 +345,7 @@ static char *ngx_http_get_all_flags(ngx_conf_t *cf, ngx_command_t *cmd, void *co
363345
{
364346
ngx_http_core_loc_conf_t *clcf; /* pointer to core location configuration */
365347

366-
/* Install the hello world handler. */
348+
/* Install get all flags handler. */
367349
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
368350
clcf->handler = ngx_http_fs_sdk_get_all_flags_handler;
369351

@@ -401,10 +383,11 @@ static ngx_int_t ngx_http_fs_sdk_variable(ngx_http_request_t *r, ngx_http_variab
401383
{
402384
u_char *p;
403385
u_char *value;
404-
ngx_http_fs_sdk_init_loc_conf_t *cglcf;
405386
char *flags;
406387

407-
#if FLAGSHIP_SDK_ENABLED
388+
#if FLAGSHIP_SDK_ENABLED
389+
390+
ngx_http_fs_sdk_init_loc_conf_t *cglcf;
408391

409392
initialize_flagship_sdk("/usr/local/nginx/sbin/libflagship.so", r);
410393

@@ -424,11 +407,11 @@ static ngx_int_t ngx_http_fs_sdk_variable(ngx_http_request_t *r, ngx_http_variab
424407

425408
flags = get_all_flags((char *)cglcf->visitor_id.data, (char *)cglcf->visitor_context.data);
426409

427-
#else
410+
#else
428411

429-
flags = "Flagship sdk disabled"
412+
flags = "Flagship sdk disabled";
430413

431-
#endif
414+
#endif
432415

433416
p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN);
434417

0 commit comments

Comments
 (0)