Ejemplo n.º 1
0
int main()
{
	ngx_list_t* list = ngx_list_create(10,sizeof(int));
	int i;
	for (i = 0; i < 100; i++) {
	int* p = (int*)ngx_list_push(list);
	*p = i*100;
	}

	ngx_list_node_t* data = &(list->head);
	for (i = 0;;i++) {
		if (i == list->ncap) {
		i = 0;
		data = data->next;
		if (data == NULL) {
		break;
	}
	}
	
	int j;
	for (j=0;j<data->ncur;j++) {
		int p = ((int*)data->data)[j];
		printf("%d\n",p);
	}
	}
	return 0;
}
Ejemplo n.º 2
0
static void ngx_http_sub_merge_wm_tables(ngx_conf_t *cf, ngx_http_sub_loc_conf_t *conf,
                ngx_http_sub_loc_conf_t *prev)
{
    int i;
    int nelts = conf->patterns->nelts;
    ngx_str_t *patterns = conf->patterns->elts;
    ngx_http_sub_wm_tables_t *wm_struct;
    ngx_array_t *hash_entries;
    ngx_http_sub_hash_entry_t *hash_entry;

    if(conf->wm_struct) {
        return;
    }
    
    if(!nelts) {
        if(prev && prev->wm_struct) {
            conf->wm_struct = prev->wm_struct;
            conf->patterns = prev->patterns;
            conf->values = prev->values;
            conf->tmp_buf_size = prev->tmp_buf_size;
        }
        return;
    }

    if(!wm_struct_list) {
        wm_struct_list = ngx_list_create(cf->pool, 1, sizeof(ngx_http_sub_wm_tables_t));
    }
    wm_struct = ngx_list_push(wm_struct_list);
    ngx_memzero(wm_struct, sizeof(ngx_http_sub_wm_tables_t));

    hash_entries = ngx_array_create(cf->pool, nelts, sizeof(ngx_http_sub_hash_entry_t));

    wm_struct->lmax = wm_struct->lmin = patterns[0].len;
    for(i = 0; i < nelts; i++) {
        size_t len = patterns[i].len;
        if(len > wm_struct->lmax) {
            wm_struct->lmax = len;
        }
        else if(len < wm_struct->lmin) {
            wm_struct->lmin = len;
        }
        hash_entry = ngx_array_push(hash_entries);
        hash_entry->pattern = patterns[i];
        hash_entry->index = i;
    }

    ngx_http_sub_wm_prep(wm_struct, hash_entries->elts, hash_entries->nelts);
    wm_struct->hash_entries = hash_entries;
    conf->tmp_buf_size = (wm_struct->lmax - 1) * 2;
    conf->wm_struct = wm_struct;
}
Ejemplo n.º 3
0
static void *
ngx_regex_create_conf(ngx_cycle_t *cycle)
{
    ngx_regex_conf_t  *rcf;
    rcf = ngx_pcalloc(cycle->pool, sizeof(ngx_regex_conf_t));
    if (rcf == NULL)
    {
        return NULL;
    }
    rcf->pcre_jit = NGX_CONF_UNSET;
    ngx_pcre_studies = ngx_list_create(cycle->pool, 8, sizeof(ngx_regex_elt_t));
    if (ngx_pcre_studies == NULL)
    {
        return NULL;
    }
    return rcf;
}
Ejemplo n.º 4
0
int main()
{
    ngx_pool_t *pool;
    int i;

    printf("--------------------------------\n");
    printf("create a new pool:\n");
    printf("--------------------------------\n");
    pool = ngx_create_pool(1024, NULL);
    dump_pool(pool);

    printf("--------------------------------\n");
    printf("alloc an list from the pool:\n");
    printf("--------------------------------\n");
    ngx_list_t *list = ngx_list_create(pool, 5, sizeof(int));
    dump_pool(pool);

    for (i = 0; i < 15; i++)
    {
        int *ptr = ngx_list_push(list);
        *ptr = i + 1;
    }

    printf("--------------------------------\n");
    printf("the list information:\n");
    printf("--------------------------------\n");
    dump_list(list);

    printf("--------------------------------\n");
    printf("the pool at the end:\n");
    printf("--------------------------------\n");
    dump_pool(pool);

    ngx_destroy_pool(pool);
    return 0;
}
Ejemplo n.º 5
0
ngx_int_t 
ngx_http_php_socket_tcp_thread_process_header(ngx_http_request_t *r)
{
    //ngx_php_request = r;
    ngx_uint_t receive_len = 0;

    //size_t len;
    //ngx_int_t rc;
    ngx_http_upstream_t *u;

    ngx_http_php_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);
    if (ctx == NULL){
        return NGX_ERROR;
    }

    u = r->upstream;

    receive_len = u->buffer.last - u->buffer.pos;

    if (ctx->receive_stat == 0){
        ctx->receive_list = ngx_list_create(r->pool, 20, sizeof(ngx_str_t));
        if (ctx->receive_list == NULL) {
            return NGX_ERROR;
        }
    }

    ngx_str_t *tmp_str = ngx_list_push(ctx->receive_list);

    tmp_str->data = ngx_palloc(r->pool, receive_len + 1);
    tmp_str->len = receive_len;
    ngx_memcpy(tmp_str->data, u->buffer.pos, receive_len);
    //tmp_str->data[receive_len] = '\0';

    ctx->receive_stat++;
    ctx->receive_total = ctx->receive_total + receive_len;
    //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%d", ctx->receive_stat);

    if (receive_len < u->conf->buffer_size){
        if (ctx->receive_stat == 1){
            ctx->receive_stat = 0;
            ctx->receive_buf.len = receive_len;
            ctx->receive_buf.data = u->buffer.pos;
        }
    }else {
        u->buffer.pos = u->buffer.start;
        u->buffer.last = u->buffer.start;
        return NGX_AGAIN;
    }


    ctx->enable_upstream = 0;

    if (u->state)
    {
        u->state->status = 200;
    }

    u->headers_in.status_n = 200;

    return NGX_OK;

}
Ejemplo n.º 6
0
ngx_int_t 
ngx_http_php_socket_tcp_process_header(ngx_http_request_t *r)
{
    ngx_php_request = r;
    ngx_uint_t receive_len = 0;

    //size_t len;
    //ngx_int_t rc;
    ngx_http_upstream_t *u;

    ngx_http_php_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);
    if (ctx == NULL){
        return NGX_ERROR;
    }

    u = r->upstream;
    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "123");
    //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%*s", (&u->buffer)->last - (&u->buffer)->pos,(&u->buffer)->pos);

    //ctx->receive_buf.len = (&u->buffer)->last - (&u->buffer)->pos;
    //ctx->receive_buf.data = (&u->buffer)->pos;

    //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "len=%d,recv=%*s", ctx->receive_buf.len, ctx->receive_buf.len, ctx->receive_buf.data);

    //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "len=%d", ctx->receive_buf.len);

    receive_len = u->buffer.last - u->buffer.pos;

    //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "len=%d", receive_len);

    if (ctx->receive_stat == 0){
        ctx->receive_list = ngx_list_create(r->pool, 20, sizeof(ngx_str_t));
        if (ctx->receive_list == NULL) {
            return NGX_ERROR;
        }
    }

    ngx_str_t *tmp_str = ngx_list_push(ctx->receive_list);

    tmp_str->data = ngx_palloc(r->pool, receive_len + 1);
    tmp_str->len = receive_len;
    ngx_memcpy(tmp_str->data, u->buffer.pos, receive_len);
    //tmp_str->data[receive_len] = '\0';

    ctx->receive_stat++;
    ctx->receive_total = ctx->receive_total + receive_len;
    //ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%d", ctx->receive_stat);

    if (receive_len < u->conf->buffer_size){
        if (ctx->receive_stat == 1){
            ctx->receive_stat = 0;
            ctx->receive_buf.len = receive_len;
            ctx->receive_buf.data = u->buffer.pos;
        }
    }else {
        u->buffer.pos = u->buffer.start;
        u->buffer.last = u->buffer.start;
        return NGX_AGAIN;
    }

    /*if (receive_len == u->conf->buffer_size || ctx->receive_stat > 0){

        if (ctx->receive_stat == 0){
            ctx->receive_list = ngx_list_create(r->pool, 20, sizeof(ngx_str_t));
            if (ctx->receive_list == NULL) {
                return NGX_ERROR;
            }
        }

        ngx_str_t *tmp_str = ngx_list_push(ctx->receive_list);

        tmp_str->data = ngx_palloc(r->pool, receive_len + 1);
        tmp_str->len = receive_len;
        ngx_memcpy(tmp_str->data, u->buffer.pos, receive_len + 1);
        tmp_str->data[receive_len] = '\0';

        ctx->receive_stat++;
        ctx->receive_total = ctx->receive_total + receive_len;
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "%d", ctx->receive_stat);

        //ctx->receive_buf.len = receive_len;
        //ctx->receive_buf.data = u->buffer.pos;

        u->buffer.pos = u->buffer.start;
        u->buffer.last = u->buffer.start;
        return NGX_AGAIN;
    }else {
        ctx->receive_buf.len = receive_len;
        ctx->receive_buf.data = u->buffer.pos;
    }*/

    ctx->enable_upstream = 0;
    //ngx_http_set_ctx(r, ctx, ngx_http_php_module);

    pthread_mutex_lock(&(ctx->mutex));
    pthread_cond_signal(&(ctx->cond));
    pthread_mutex_unlock(&(ctx->mutex));

    /*rc = ngx_http_parse_status_line(r, &u->buffer, &ctx->receive_status);

    if (rc == NGX_AGAIN){
        return rc;
    }*/

    if (u->state)
    {
        u->state->status = 200;
    }

    u->headers_in.status_n = 200;

    /*len = ctx->receive_status.end - ctx->receive_status.start;
    u->headers_in.status_line.len = len;

    u->headers_in.status_line.data = ngx_pnalloc(r->pool, len);
    if (u->headers_in.status_line.data == NULL)
    {
        return NGX_ERROR;
    }

    ngx_memcpy(u->headers_in.status_line.data, ctx->receive_status.start, len);

    u->process_header = ngx_http_php_socket_tcp_receive_parse;

    return ngx_http_php_socket_tcp_receive_parse(r);*/

    return NGX_OK;

}
Ejemplo n.º 7
0
static jlong JNICALL jni_ngx_list_create(JNIEnv *env, jclass cls, jlong pool, jlong n, jlong size) {
	return (uintptr_t)ngx_list_create((ngx_pool_t *)pool, (ngx_uint_t)n, (size_t)size);
}