static int parse_config_entry(server *srv, array *ca, pcre_keyvalue_buffer *kvb, const char *option, size_t olen) { data_unset *du; if (NULL != (du = array_get_element_klen(ca, option, olen))) { data_array *da; size_t j; da = (data_array *)du; if (du->type != TYPE_ARRAY || !array_is_kvstring(da->value)) { log_error_write(srv, __FILE__, __LINE__, "SSS", "unexpected value for ", option, "; expected list of \"regex\" => \"subst\""); return HANDLER_ERROR; } for (j = 0; j < da->value->used; j++) { data_string *ds = (data_string *)da->value->data[j]; if (srv->srvconf.http_url_normalize) { pcre_keyvalue_burl_normalize_key(ds->key, srv->tmp_buf); pcre_keyvalue_burl_normalize_value(ds->value, srv->tmp_buf); } if (0 != pcre_keyvalue_buffer_append(srv, kvb, ds->key, ds->value)) { log_error_write(srv, __FILE__, __LINE__, "sb", "pcre-compile failed for", ds->key); return HANDLER_ERROR; } } } return 0; }
data_integer *status_counter_get_counter(server *srv, const char *s, size_t len) { data_integer *di; if (NULL == (di = (data_integer *)array_get_element_klen(srv->status, s, len))) { /* not found, create it */ if (NULL == (di = (data_integer *)array_get_unused_element(srv->status, TYPE_INTEGER))) { di = data_integer_init(); } buffer_copy_string_len(di->key, s, len); di->value = 0; array_insert_unique(srv->status, (data_unset *)di); } return di; }
static int ssi_expr_tokenizer(server *srv, connection *con, handler_ctx *p, ssi_tokenizer_t *t, int *token_id, buffer *token) { int tid = 0; size_t i; UNUSED(con); for (tid = 0; tid == 0 && t->offset < t->size && t->input[t->offset] ; ) { char c = t->input[t->offset]; data_string *ds; switch (c) { case '=': tid = TK_EQ; t->offset++; t->line_pos++; buffer_copy_string_len(token, CONST_STR_LEN("(=)")); break; case '>': if (t->input[t->offset + 1] == '=') { t->offset += 2; t->line_pos += 2; tid = TK_GE; buffer_copy_string_len(token, CONST_STR_LEN("(>=)")); } else { t->offset += 1; t->line_pos += 1; tid = TK_GT; buffer_copy_string_len(token, CONST_STR_LEN("(>)")); } break; case '<': if (t->input[t->offset + 1] == '=') { t->offset += 2; t->line_pos += 2; tid = TK_LE; buffer_copy_string_len(token, CONST_STR_LEN("(<=)")); } else { t->offset += 1; t->line_pos += 1; tid = TK_LT; buffer_copy_string_len(token, CONST_STR_LEN("(<)")); } break; case '!': if (t->input[t->offset + 1] == '=') { t->offset += 2; t->line_pos += 2; tid = TK_NE; buffer_copy_string_len(token, CONST_STR_LEN("(!=)")); } else { t->offset += 1; t->line_pos += 1; tid = TK_NOT; buffer_copy_string_len(token, CONST_STR_LEN("(!)")); } break; case '&': if (t->input[t->offset + 1] == '&') { t->offset += 2; t->line_pos += 2; tid = TK_AND; buffer_copy_string_len(token, CONST_STR_LEN("(&&)")); } else { log_error_write(srv, __FILE__, __LINE__, "sds", "pos:", t->line_pos, "missing second &"); return -1; } break; case '|': if (t->input[t->offset + 1] == '|') { t->offset += 2; t->line_pos += 2; tid = TK_OR; buffer_copy_string_len(token, CONST_STR_LEN("(||)")); } else { log_error_write(srv, __FILE__, __LINE__, "sds", "pos:", t->line_pos, "missing second |"); return -1; } break; case '\t': case ' ': t->offset++; t->line_pos++; break; case '\'': /* search for the terminating " */ for (i = 1; t->input[t->offset + i] && t->input[t->offset + i] != '\''; i++); if (t->input[t->offset + i]) { tid = TK_VALUE; buffer_copy_string_len(token, t->input + t->offset + 1, i-1); t->offset += i + 1; t->line_pos += i + 1; } else { /* ERROR */ log_error_write(srv, __FILE__, __LINE__, "sds", "pos:", t->line_pos, "missing closing quote"); return -1; } break; case '(': t->offset++; t->in_brace++; tid = TK_LPARAN; buffer_copy_string_len(token, CONST_STR_LEN("(")); break; case ')': t->offset++; t->in_brace--; tid = TK_RPARAN; buffer_copy_string_len(token, CONST_STR_LEN(")")); break; case '$': if (t->input[t->offset + 1] == '{') { for (i = 2; t->input[t->offset + i] && t->input[t->offset + i] != '}'; i++); if (t->input[t->offset + i] != '}') { log_error_write(srv, __FILE__, __LINE__, "sds", "pos:", t->line_pos, "missing closing quote"); return -1; } buffer_copy_string_len(token, t->input + t->offset + 2, i-3); } else { for (i = 1; isalpha(t->input[t->offset + i]) || t->input[t->offset + i] == '_' || ((i > 1) && isdigit(t->input[t->offset + i])); i++); buffer_copy_string_len(token, t->input + t->offset + 1, i-1); } tid = TK_VALUE; if (NULL != (ds = (data_string *)array_get_element_klen(p->ssi_cgi_env, CONST_BUF_LEN(token)))) { buffer_copy_buffer(token, ds->value); } else if (NULL != (ds = (data_string *)array_get_element_klen(p->ssi_vars, CONST_BUF_LEN(token)))) { buffer_copy_buffer(token, ds->value); } else { buffer_copy_string_len(token, CONST_STR_LEN("")); } t->offset += i; t->line_pos += i; break; default: for (i = 0; isgraph(t->input[t->offset + i]); i++) { char d = t->input[t->offset + i]; switch(d) { case ' ': case '\t': case ')': case '(': case '\'': case '=': case '!': case '<': case '>': case '&': case '|': break; } } tid = TK_VALUE; buffer_copy_string_len(token, t->input + t->offset, i); t->offset += i; t->line_pos += i; break; } } if (tid) { *token_id = tid; return 1; } else if (t->offset < t->size) { log_error_write(srv, __FILE__, __LINE__, "sds", "pos:", t->line_pos, "foobar"); } return 0; }