ngx_http_push_stream_requested_channel_t * ngx_http_push_stream_parse_channels_ids_from_path(ngx_http_request_t *r, ngx_pool_t *pool) { ngx_http_push_stream_main_conf_t *mcf = ngx_http_get_module_main_conf(r, ngx_http_push_stream_module); ngx_http_push_stream_loc_conf_t *cf = ngx_http_get_module_loc_conf(r, ngx_http_push_stream_module); ngx_http_variable_value_t *vv_channels_path = ngx_http_get_indexed_variable(r, cf->index_channels_path); ngx_http_push_stream_requested_channel_t *channels_ids, *cur; ngx_str_t aux; int captures[15]; ngx_int_t n; if (vv_channels_path == NULL || vv_channels_path->not_found || vv_channels_path->len == 0) { return NULL; } if ((channels_ids = ngx_pcalloc(pool, sizeof(ngx_http_push_stream_requested_channel_t))) == NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: unable to allocate memory for channels_ids queue"); return NULL; } ngx_queue_init(&channels_ids->queue); // doing the parser of given channel path aux.data = vv_channels_path->data; do { aux.len = vv_channels_path->len - (aux.data - vv_channels_path->data); if ((n = ngx_regex_exec(mcf->backtrack_parser_regex, &aux, captures, 15)) >= 0) { if ((cur = ngx_pcalloc(pool, sizeof(ngx_http_push_stream_requested_channel_t))) == NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: unable to allocate memory for channel_id item"); return NULL; } if ((cur->id = ngx_http_push_stream_create_str(pool, captures[0])) == NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "push stream module: unable to allocate memory for channel_id string"); return NULL; } ngx_memcpy(cur->id->data, aux.data, captures[0]); cur->backtrack_messages = 0; if (captures[7] > captures[6]) { cur->backtrack_messages = ngx_atoi(aux.data + captures[6], captures[7] - captures[6]); } ngx_queue_insert_tail(&channels_ids->queue, &cur->queue); aux.data = aux.data + captures[1]; } } while ((n != NGX_REGEX_NO_MATCHED) && (aux.data < (vv_channels_path->data + vv_channels_path->len))); return channels_ids; }
static void ngx_resolver_process_ptr(ngx_resolver_t *r, u_char *buf, size_t n, ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan) { char *err; size_t len; in_addr_t addr; int32_t ttl; ngx_int_t digit; ngx_str_t name; ngx_uint_t i, mask, qident; ngx_resolver_an_t *an; ngx_resolver_ctx_t *ctx, *next; ngx_resolver_node_t *rn; if (ngx_resolver_copy(r, NULL, buf, &buf[12], &buf[n]) != NGX_OK) { goto invalid_in_addr_arpa; } addr = 0; i = 12; for (mask = 0; mask < 32; mask += 8) { len = buf[i++]; digit = ngx_atoi(&buf[i], len); if (digit == NGX_ERROR || digit > 255) { goto invalid_in_addr_arpa; } addr += digit << mask; i += len; } if (ngx_strcmp(&buf[i], "\7in-addr\4arpa") != 0) { goto invalid_in_addr_arpa; } /* lock addr mutex */ rn = ngx_resolver_lookup_addr(r, addr); if (rn == NULL || rn->query == NULL) { ngx_log_error(r->log_level, r->log, 0, "unexpected response for %ud.%ud.%ud.%ud", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); goto failed; }
ngx_int_t hustdb_ha_on_subrequest_complete(ngx_http_request_t * r, void * data, ngx_int_t rc) { hustdb_ha_ctx_t * ctx = data; do { if (!ctx || NGX_HTTP_OK != r->headers_out.status) { break; } ctx->base.response.len = ngx_http_get_buf_size(&r->upstream->buffer); ctx->base.response.data = r->upstream->buffer.pos; ngx_str_t * val = ngx_http_find_head_value(&r->headers_out.headers, &VERSION_KEY); if (val) { if (!ctx->version.data) { ctx->version = __make_str(val, r->parent); } else { ngx_int_t src = ngx_atoi(ctx->version.data, ctx->version.len); ngx_int_t dst = ngx_atoi(val->data, val->len); if (dst > src) { ctx->version = __make_str(val, r->parent); } } } } while (0); return ngx_http_finish_subrequest(r); }
static ngx_uint_t ngx_http_image_filter_value(ngx_str_t *value) { ngx_int_t n; if (value->len == 1 && value->data[0] == '-') { return (ngx_uint_t) - 1; } n = ngx_atoi(value->data, value->len); if (n > 0) { return (ngx_uint_t) n; } return 0; }
static ngx_uint_t ngx_http_statsd_metric_value(ngx_str_t *value) { ngx_int_t n, m; if (value->len == 1 && value->data[0] == '-') { return (ngx_uint_t) -1; }; /* Hack to convert milliseconds to a number. */ if (value->len > 4 && value->data[value->len - 4] == '.') { n = ngx_atoi(value->data, value->len - 4); m = ngx_atoi(value->data + (value->len - 3), 3); return (ngx_uint_t) ((n * 1000) + m); } else { n = ngx_atoi(value->data, value->len); if (n > 0) { return (ngx_uint_t) n; }; }; return 0; };
static char * ngx_rtmp_exec_kill_signal(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_rtmp_exec_main_conf_t *emcf = conf; ngx_str_t *value; value = cf->args->elts; value++; emcf->kill_signal = ngx_atoi(value->data, value->len); if (emcf->kill_signal != NGX_ERROR) { return NGX_CONF_OK; } #define NGX_RMTP_EXEC_SIGNAL(name) \ if (value->len == sizeof(#name) - 1 && \ ngx_strncasecmp(value->data, (u_char *) #name, value->len) == 0) \ { \ emcf->kill_signal = SIG##name; \ return NGX_CONF_OK; \ } /* POSIX.1-1990 signals */ NGX_RMTP_EXEC_SIGNAL(HUP); NGX_RMTP_EXEC_SIGNAL(INT); NGX_RMTP_EXEC_SIGNAL(QUIT); NGX_RMTP_EXEC_SIGNAL(ILL); NGX_RMTP_EXEC_SIGNAL(ABRT); NGX_RMTP_EXEC_SIGNAL(FPE); NGX_RMTP_EXEC_SIGNAL(KILL); NGX_RMTP_EXEC_SIGNAL(SEGV); NGX_RMTP_EXEC_SIGNAL(PIPE); NGX_RMTP_EXEC_SIGNAL(ALRM); NGX_RMTP_EXEC_SIGNAL(TERM); NGX_RMTP_EXEC_SIGNAL(USR1); NGX_RMTP_EXEC_SIGNAL(USR2); NGX_RMTP_EXEC_SIGNAL(CHLD); NGX_RMTP_EXEC_SIGNAL(CONT); NGX_RMTP_EXEC_SIGNAL(STOP); NGX_RMTP_EXEC_SIGNAL(TSTP); NGX_RMTP_EXEC_SIGNAL(TTIN); NGX_RMTP_EXEC_SIGNAL(TTOU); #undef NGX_RMTP_EXEC_SIGNAL return "unknown signal"; }
static char * ngx_http_identifier_cache_size(ngx_conf_t * cf, ngx_command_t * cmd, void * conf) { ngx_http_hustdb_ha_main_conf_t * mcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_hustdb_ha_module); if (!mcf || 2 != cf->args->nelts) { return "ngx_http_identifier_cache_size error"; } ngx_str_t * value = cf->args->elts; mcf->identifier_cache_size = ngx_atoi(value[1].data, value[1].len); if (NGX_ERROR == mcf->identifier_cache_size) { return "ngx_http_identifier_cache_size error"; } // TODO: you can modify the value here return NGX_CONF_OK; }
static char * ngx_http_session_redirect_timeout(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_session_conf_t *sscf = conf; ngx_str_t *value; value = cf->args->elts; sscf->redirect_timeout = ngx_atoi(value[1].data, value[1].len) * 1000; if (sscf->redirect_timeout <= 0) { return "Invalid timeout value, must larger than 0 seconds"; } return NGX_CONF_OK; }
static const char * ngx_rtmp_control_walk(ngx_http_request_t *r, ngx_rtmp_control_handler_t h, ngx_flag_t per_session) { ngx_rtmp_core_main_conf_t *cmcf = ngx_rtmp_core_main_conf; ngx_str_t srv; ngx_uint_t sn, n; const char *msg; ngx_rtmp_session_t **s; ngx_rtmp_control_ctx_t *ctx; ngx_rtmp_core_srv_conf_t **pcscf; ngx_rtmp_core_app_conf_t **pcacf = NULL; sn = 0; if (ngx_http_arg(r, (u_char *) "srv", sizeof("srv") - 1, &srv) == NGX_OK) { sn = ngx_atoi(srv.data, srv.len); } if (sn >= cmcf->servers.nelts) { return "Server index out of range"; } pcscf = cmcf->servers.elts; pcscf += sn; msg = ngx_rtmp_control_walk_server(r, *pcscf, &pcacf); if (msg != NGX_CONF_OK) { return msg; } ctx = ngx_http_get_module_ctx(r, ngx_rtmp_control_module); if (!per_session) { return h(r, NULL, *pcscf, pcacf); } s = ctx->sessions.elts; for (n = 0; n < ctx->sessions.nelts; n++) { msg = h(r, s[n], *pcscf, pcacf); if (msg != NGX_CONF_OK) { return msg; } } return NGX_CONF_OK; }
static char *ngx_http_lookaround_setmaxmaplevel(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_conf_get_module_loc_conf( cf, ngx_http_core_module ) ; clcf->handler = ngx_http_lookaround_handler ; ngx_http_lookaround_loc_conf *p_la_conf = conf ; ngx_str_t *value ; value = cf->args->elts; p_la_conf->nMapMaxLevel = ngx_atoi( value[ 1 ].data , value[ 1 ].len ) ; return NGX_CONF_OK ; }
/* memcache handler (return counter for the specified ip or NOT_FOUND) */ static void ngx_mail_throttle_ip_success_handler (mc_work_t *w) { ngx_mail_throttle_srv_conf_t * tscf; throttle_callback_t *callback = w->ctx; ngx_str_t ip = *callback->ip; ngx_mail_session_t *s = callback->session; size_t hits; ngx_str_t counter; /* the increment was successful - deep copy w->payload to counter */ counter.data = ngx_pstrdup (callback->pool, &w->payload); if (counter.data == NULL) { /* enomem */ counter = throttle_zero; /* "0" */ } else { counter.len = w->payload.len; } /* check if the limit has exceeded */ ngx_log_debug2(NGX_LOG_DEBUG_MAIL, callback->log, 0, "ip throttle:%V is %V", &ip, &counter); hits = ngx_atoi(counter.data, counter.len); tscf = ngx_mail_get_module_srv_conf(s, ngx_mail_throttle_module); if (tscf->mail_login_ip_max == 0) { //should never reach here because mail handler won't //start throttle control if it's unlimited. ngx_log_error (NGX_LOG_INFO, callback->log, 0, "ip throttle:[%V] allow [count:%d, limit:inf]", &ip, hits); callback->on_allow(callback); } else if (hits <= tscf->mail_login_ip_max) { ngx_log_error (NGX_LOG_INFO, callback->log, 0, "ip throttle:[%V] allow [count:%d, limit:%d]", &ip, hits, tscf->mail_login_ip_max); callback->on_allow(callback); } else { ngx_log_error (NGX_LOG_NOTICE, callback->log, 0, "ip throttle:[%V] deny [count:%d, limit:%d]", &ip, hits, tscf->mail_login_ip_max); callback->on_deny(callback); } }
ngx_int_t ngx_signal_process(ngx_cycle_t *cycle, char *sig) { ssize_t n; ngx_int_t pid; ngx_file_t file; ngx_core_conf_t *ccf; u_char buf[NGX_INT64_LEN + 2]; ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "signal process started"); ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); ngx_memzero(&file, sizeof(ngx_file_t)); file.name = ccf->pid; file.log = cycle->log; file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, NGX_FILE_DEFAULT_ACCESS); if (file.fd == NGX_INVALID_FILE) { ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, ngx_open_file_n " \"%s\" failed", file.name.data); return 1; } n = ngx_read_file(&file, buf, NGX_INT64_LEN + 2, 0); if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, ngx_close_file_n " \"%s\" failed", file.name.data); } if (n == NGX_ERROR) { return 1; } while (n-- && (buf[n] == CR || buf[n] == LF)) { /* void */ } pid = ngx_atoi(buf, ++n); if (pid == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, cycle->log, 0, "invalid PID number \"%*s\" in \"%s\"", n, buf, file.name.data); return 1; } return ngx_os_signal_process(cycle, sig, pid); }
//----------------------------------------------------------------------------- static char * ngx_c2h5oh(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_str_t *value; ngx_c2h5oh_loc_conf_t *alcf = conf; if (alcf->enabled) { return "is duplicate"; } alcf->enabled = 1; value = cf->args->elts; if (value[1].data == NULL || value[1].len == 0) { return "db_path is not specified"; } alcf->db_path.data = value[1].data; alcf->db_path.len = value[1].len; if (value[2].data == NULL || value[2].len == 0) { return "pool_size is not specified"; } ngx_int_t pool_size = ngx_atoi(value[2].data, value[2].len); if (pool_size <= 0) { return "pool size is invalid"; } alcf->pool_size = pool_size; if (c2h5oh_module_init((const char *)alcf->db_path.data, alcf->db_path.len, alcf->pool_size) != 0) { ngx_log_error(NGX_LOG_ERR, cf->log, 0, "[c2h5oh] error init c2h5oh"); return NGX_CONF_ERROR; } ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_c2h5oh_handler; return NGX_CONF_OK; }
static njs_ret_t ngx_http_js_ext_set_content_length(njs_vm_t *vm, void *obj, uintptr_t data, nxt_str_t *value) { ngx_int_t n; ngx_http_request_t *r; n = ngx_atoi(value->start, value->length); if (n == NGX_ERROR) { return NJS_ERROR; } r = (ngx_http_request_t *) obj; r->headers_out.content_length_n = n; return NJS_OK; }
char * ngx_conf_set_number_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *p = conf; int *np; ngx_str_t *value; np = (int *) (p + cmd->offset); if (*np != NGX_CONF_UNSET) { return "is duplicate"; } value = cf->args->elts; *np = (int)ngx_atoi(value[1].data, value[1].len); if (*np == NGX_ERROR) { return "invalid number"; } return NGX_CONF_OK; }
static char * ngx_http_vesb_customize_info(ngx_conf_t *cf,ngx_command_t *cmd, void *conf) { ngx_http_vesb_aio_log_loc_conf_t *vallcf = conf; ngx_str_t *value; value = cf->args->elts; vallcf->app_name = value[1]; vallcf->invoke_max_time = ngx_atoi(value[2].data, value[2].len); if (vallcf->invoke_max_time == -1) { vallcf->enable_tracking = 1; } return NGX_CONF_OK; }
/*esb:mongodb connection string config*/ static char * ngx_http_mongodb_set_conn(ngx_conf_t *cf,ngx_command_t *cmd, void *conf) { ngx_http_vesb_aio_log_main_conf_t *valcf = conf; mongo conn[1]; ngx_str_t *value; char *conn_str; int port,status; value = cf->args->elts; valcf->mongodb_conn_str = value[1]; valcf->mongodb_conn_port = ngx_atoi(value[2].data, value[2].len); if (valcf->mongodb_conn_port == (ngx_int_t) NGX_ERROR) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid number \"%V\"", &value[2]); return NGX_CONF_ERROR; } conn_str = (char *)valcf->mongodb_conn_str.data; port = (int)valcf->mongodb_conn_port; status = mongo_client( conn, conn_str, port ); if( status != MONGO_OK ) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "can't connect server %V %V", &value[1],&value[2]); return NGX_CONF_ERROR; } mongo_destroy( conn ); valcf->mongodb_enable = 1; return NGX_CONF_OK; }
static char *ngx_http_push_set_message_buffer_length(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *p = conf; ngx_int_t *min, *max; ngx_str_t *value; ngx_int_t intval; min = (ngx_int_t *) (p + offsetof(ngx_http_push_loc_conf_t, min_messages)); max = (ngx_int_t *) (p + offsetof(ngx_http_push_loc_conf_t, max_messages)); if(*min != NGX_CONF_UNSET || *max != NGX_CONF_UNSET) { return "is duplicate"; } value = cf->args->elts; if((intval = ngx_atoi(value[1].data, value[1].len))==NGX_ERROR) { return "invalid number"; } *min = intval; *max = intval; return NGX_CONF_OK; }
static char * ngx_http_session_timeout(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_session_conf_t *sscf = conf; ngx_str_t *value; value = cf->args->elts; sscf->timeout = ngx_atoi(value[1].data, value[1].len) * 1000; if (sscf->timeout < 20000) { return "Invalid timeout value, must larger than 20 seconds"; } if (sscf->timeout == 0) { sscf->timeout = NGX_HTTP_SESSION_DEFAULT_TMOUT; } return NGX_CONF_OK; }
ngx_int_t ngx_http_qrcode_set_casesensitive(ngx_http_request_t *r, ngx_int_t *val, ngx_array_t *compiled_args) { ngx_str_t *arg; ngx_int_t rc; arg = compiled_args->elts; rc = ngx_atoi(arg[0].data, arg[0].len); if (rc < 0 || rc > 1) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "error casesensitive value %V, it should be 0 or 1.", arg); return rc; } *val = rc; return NGX_OK; }
ngx_int_t ngx_http_qrcode_set_level(ngx_http_request_t *r, ngx_int_t *val, ngx_array_t *compiled_args) { ngx_str_t *arg; ngx_int_t rc; arg = compiled_args->elts; rc = ngx_atoi(arg[0].data, arg[0].len); if (rc < 0 || rc > 3) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "error level value %V, level should be 0, 1, 2 or 3.", arg); return rc; } *val = rc; return NGX_OK; }
ngx_int_t ngx_http_qrcode_set_margin(ngx_http_request_t *r, ngx_int_t *val, ngx_array_t *compiled_args) { ngx_str_t *arg; ngx_int_t rc; arg = compiled_args->elts; rc = ngx_atoi(arg[0].data, arg[0].len); if (rc == NGX_ERROR) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "error margin value %V.", arg); return rc; } *val = rc; return NGX_OK; }
static ngx_int_t nchan_parse_compound_msgid(nchan_msg_id_t *id, ngx_str_t *str){ u_char *split, *last; ngx_int_t time; //"<msg_time>:<msg_tag>" last = str->data + str->len; if((split = ngx_strlchr(str->data, last, ':')) != NULL) { time = ngx_atoi(str->data, split - str->data); split++; if(time != NGX_ERROR) { id->time = time; nchan_parse_msg_tag(split, last, id); return NGX_OK; } else { return NGX_ERROR; } } return NGX_DECLINED; }
/* TODO same as above */ static char * max_connections_max_queue_length_command (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_upstream_srv_conf_t *uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module); max_connections_srv_conf_t *maxconn_cf = ngx_http_conf_upstream_srv_conf(uscf, max_connections_module); ngx_str_t *value = cf->args->elts; ngx_int_t n = ngx_atoi(value[1].data, value[1].len); if (n == NGX_ERROR) { return "invalid number"; } maxconn_cf->max_queue_length = n; return NGX_CONF_OK; }
static void ngx_mail_throttle_quser_success_handler (mc_work_t *w) { throttle_callback_t *callback = w->ctx; ngx_mail_session_t *s = callback->session; ngx_log_t *log = callback->log; ngx_mail_throttle_srv_conf_t * tscf; size_t hits; ngx_str_t counter; /* increment succeeded / get succeeded */ counter.data = ngx_pstrdup(callback->pool, &w->payload); if (counter.data == NULL) { /* enomem */ counter = throttle_zero; } else { counter.len = w->payload.len; } /* check if the limit has exceeded */ ngx_log_debug2 (NGX_LOG_DEBUG_MAIL, log, 0, "user throttle:%V is %V", callback->user, &counter); hits = ngx_atoi (counter.data, counter.len); tscf = ngx_mail_get_module_srv_conf (s, ngx_mail_throttle_module); if (tscf->mail_login_user_max == 0) { //should never reach here because unlimited case has been handled ngx_log_error (NGX_LOG_INFO, log, 0, "user throttle:%V allow [count:%d,limit:inf]", callback->user, hits); callback->on_allow(callback); } else if (hits <= tscf->mail_login_user_max) { ngx_log_error (NGX_LOG_INFO, log, 0, "user throttle:%V allow [count:%d,limit:%d]", callback->user, hits, tscf->mail_login_user_max); callback->on_allow(callback); } else { ngx_log_error (NGX_LOG_NOTICE, log, 0, "user throttle:%V deny [count:%d,limit:%d]", callback->user, hits, tscf->mail_login_user_max); callback->on_deny(callback); } }
static ngx_uint_t ngx_http_image_filter_value(ngx_str_t *v) { ngx_int_t n; if (v->len == 1 && v->data[0] == '-') { return (ngx_uint_t) -1; } n = ngx_atoi(v->data, v->len); if (n == NGX_ERROR) { if (v->len == sizeof("left") - 1 && ngx_strncmp(v->data, "left", v->len) == 0) { return NGX_HTTP_IMAGE_OFFSET_LEFT; } else if (v->len == sizeof("right") - 1 && ngx_strncmp(v->data, "right", sizeof("right") - 1) == 0) { return NGX_HTTP_IMAGE_OFFSET_RIGHT; } else if (v->len == sizeof("top") - 1 && ngx_strncmp(v->data, "top", sizeof("top") - 1) == 0) { return NGX_HTTP_IMAGE_OFFSET_TOP; } else if (v->len == sizeof("bottom") - 1 && ngx_strncmp(v->data, "bottom", sizeof("bottom") - 1) == 0) { return NGX_HTTP_IMAGE_OFFSET_BOTTOM; } else { return NGX_HTTP_IMAGE_OFFSET_CENTER; } } else if (n > 0) { return (ngx_uint_t) n; } return 0; }
//keepalive connections static char * ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_upstream_srv_conf_t *uscf; ngx_http_upstream_keepalive_srv_conf_t *kcf = conf; ngx_int_t n; ngx_str_t *value; if (kcf->max_cached) { return "is duplicate"; } /* read options */ value = cf->args->elts; n = ngx_atoi(value[1].data, value[1].len); if (n == NGX_ERROR || n == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%V\" in \"%V\" directive", &value[1], &cmd->name); return NGX_CONF_ERROR; } kcf->max_cached = n; uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module); /* When using load balancer methods other than the default round-robin method, it is necessary to activate them before the keepalive directive. */ /* 保存原来的初始化upstream的钩子,并设置新的钩子 */ //这个是赋值均衡算法的一些初始化钩子用original_init_upstream保存 kcf->original_init_upstream = uscf->peer.init_upstream ? uscf->peer.init_upstream : ngx_http_upstream_init_round_robin; uscf->peer.init_upstream = ngx_http_upstream_init_keepalive; //原始的负债均衡钩子保存在kcf->original_init_upstream return NGX_CONF_OK; }
ngx_int_t ngx_http_tfs_parse_tair_server_addr_info(ngx_http_tfs_tair_server_addr_info_t *info, u_char *addr, uint32_t len, void *pool, uint8_t shared_memory) { u_char *temp, *p; ssize_t info_size; ngx_int_t i; p = addr; for (i = 0; i < NGX_HTTP_TFS_TAIR_SERVER_ADDR_PART_COUNT; i++) { temp = ngx_strlchr(p, p + len, ';'); if (temp == NULL) { return NGX_ERROR; } info_size = temp - p; if (shared_memory) { info->server[i].data = ngx_slab_alloc_locked((ngx_slab_pool_t *)pool, info_size); } else { info->server[i].data = ngx_pcalloc((ngx_pool_t *)pool, info_size); } if (info->server[i].data == NULL) { return NGX_ERROR; } info->server[i].len = info_size; memcpy(info->server[i].data, p, info_size); p += info_size + 1; len -= (info_size + 1); if (len <= 0) { return NGX_ERROR; } } info->area = ngx_atoi(p, len); if (info->area == NGX_ERROR) { return NGX_ERROR; } return NGX_OK; }
static char *ngx_conf_set_authen_config(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_authen_conf_t *authencf = conf; ngx_str_t *value = cf->args->elts; if (cf->args->nelts > 1) { authencf->addr = value[1]; if (ngx_inet_addr(authencf->addr.data, authencf->addr.len) == INADDR_NONE) { return "Invalid: Authen IP address"; } } if (cf->args->nelts > 2) { authencf->port = ngx_atoi(value[2].data, value[2].len); if (authencf->port == NGX_ERROR) { return "Invalid: Authen UDP port"; } } return NGX_CONF_OK; }
static char * ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_upstream_srv_conf_t *uscf; ngx_http_upstream_keepalive_srv_conf_t *kcf = conf; ngx_int_t n; ngx_str_t *value; if (kcf->max_cached) { return "is duplicate"; } /* read options */ value = cf->args->elts; n = ngx_atoi(value[1].data, value[1].len); if (n == NGX_ERROR || n == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid value \"%V\" in \"%V\" directive", &value[1], &cmd->name); return NGX_CONF_ERROR; } kcf->max_cached = n; /* init upstream handler */ uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module); kcf->original_init_upstream = uscf->peer.init_upstream ? uscf->peer.init_upstream : ngx_http_upstream_init_round_robin; uscf->peer.init_upstream = ngx_http_upstream_init_keepalive; return NGX_CONF_OK; }