Browse Source

#105 -- fixed. it was a compatibility issue. extern ngx_module_t does not work well for some cases.

tags/v2.6-rc3
V. Soshnikov 2 years ago
parent
commit
a050f43624
7 changed files with 1503 additions and 1549 deletions
  1. 0
    2
      config
  2. 0
    1251
      src/ngx_http_tnt_handlers.c
  3. 0
    249
      src/ngx_http_tnt_handlers.h
  4. 1480
    24
      src/ngx_http_tnt_module.c
  5. 1
    1
      src/ngx_http_tnt_version.h
  6. 21
    21
      src/tp_transcode.c
  7. 1
    1
      t/basic_features.py

+ 0
- 2
config View File

@@ -26,7 +26,6 @@ sources=" \
$module_src_dir/json_encoders.c \
$module_src_dir/tp_transcode.c \
$module_src_dir/ngx_http_tnt_module.c \
$module_src_dir/ngx_http_tnt_handlers.c \
"

headers=" \
@@ -34,7 +33,6 @@ headers=" \
$module_src_dir/tp_ext.h \
$module_src_dir/json_encoders.h \
$module_src_dir/tp_transcode.h \
$module_src_dir/ngx_http_tnt_handlers.h \
"

old_style_build=yes

+ 0
- 1251
src/ngx_http_tnt_handlers.c
File diff suppressed because it is too large
View File


+ 0
- 249
src/ngx_http_tnt_handlers.h View File

@@ -1,249 +0,0 @@
/*
* 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 AUTHORS ``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
* AUTHORS 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.
*
* Copyright (C) 2015-2017 Tarantool AUTHORS:
* please see AUTHORS file.
*/

#ifndef NGX_HTTP_TNT_CREATE_REQUEST_H_INCLUDED
#define NGX_HTTP_TNT_CREATE_REQUEST_H_INCLUDED 1

#include <ngx_core.h>
#include <ngx_http.h>
#include <tp_transcode.h>


typedef enum ngx_tnt_conf_states {
NGX_TNT_CONF_ON = 1,
NGX_TNT_CONF_OFF = 2,
NGX_TNT_CONF_PARSE_ARGS = 4,
NGX_TNT_CONF_UNESCAPE = 8,
NGX_TNT_CONF_PASS_BODY = 16,
NGX_TNT_CONF_PASS_HEADERS_OUT = 32,
NGX_TNT_CONF_PARSE_URLENCODED = 64,
} ngx_tnt_conf_states_e;

typedef struct ngx_http_tnt_header_val_s ngx_http_tnt_header_val_t;

typedef ngx_int_t (*ngx_http_set_header_pt)(ngx_http_request_t *r,
ngx_http_tnt_header_val_t *hv, ngx_str_t *value);

struct ngx_http_tnt_header_val_s {
ngx_http_complex_value_t value;
ngx_str_t key;
ngx_http_set_header_pt handler;
};

/** The structure hold the nginx location variables, e.g. loc_conf.
*/
typedef struct {
ngx_http_upstream_conf_t upstream;
ngx_int_t index;

size_t in_multiplier;
size_t out_multiplier;

/** Preset method name
*
* If this is set then tp_transcode use only this method name and
* tp_transcode will ignore the method name from the json or/and uri
*/
ngx_http_complex_value_t *method_ccv;
ngx_str_t method;

/** This is max allowed size of query + headers + body, the size in bytes
*/
size_t pass_http_request_buffer_size;

/** Pass query/headers to tarantool
*
* If this is set, then Tarantool recv. query args as the lua table,
* e.g. /tnt_method?arg1=X&arg2=123
*
* Tarantool
* function tnt_method(http_req)
* {
* http_req['args']['arg1'] -- eq 'Y'
* http_req['args']['arg2'] -- eq '123'
* }
*/
ngx_uint_t pass_http_request;

/** Http REST methods[default GET|PUT]
*
* if incoming HTTP method is in this set, then
* the tp_transcode expect the tarantool method name in url,
* i.e. HOST/METHOD_NAME/TAIL?ARGS
*
* XXX Also see method
*/
ngx_uint_t http_rest_methods;

/** Set of http methods[default POST|DELETE]
*
* If incoming HTTP method is in this set,
* then the tp_transcode expect method name in JSON protocol,
* i.e. {"method":STR}
*
* XXX Also see method
*/
ngx_uint_t http_methods;

/** If it is set, then the client will recv. a pure result, e.g. {}
* otherwise {"result":[], "id": NUM}id
*/
ngx_uint_t pure_result;

/** Tarantool returns array of array as the result set,
* this option will help avoid "array of array" behavior.
* For instance.
* If this option is set to 2, then the result will: result:{}.
* If this option is set to 0, then the result will: result:[[{}]].
*/
ngx_uint_t multireturn_skip_count;

ngx_array_t *headers;

} ngx_http_tnt_loc_conf_t;


/** Set of allowed REST methods
*/
static const ngx_uint_t ngx_http_tnt_allowed_methods =
(NGX_HTTP_POST|NGX_HTTP_GET|NGX_HTTP_PUT|NGX_HTTP_PATCH|NGX_HTTP_DELETE);

/** Upstream states
*/
enum ctx_state {
OK = 0,

INPUT_JSON_PARSE_FAILED,
INPUT_TO_LARGE,
INPUT_EMPTY,

READ_PAYLOAD,
READ_BODY,
SEND_REPLY
};

typedef struct ngx_http_tnt_ctx {

/** This is a reference to Tarantool payload data,
* e.g. size of TP message
*/
struct {
u_char mem[6];
u_char *p, *e;
} payload;

enum ctx_state state;
/** in_err - the error buffer
* tp_cache - the buffer for store parts of TP message
*/
ngx_buf_t *in_err, *tp_cache;

/** rest - bytes, until transcoding is end
* payload_size - the payload, as integer value
* rest_batch_size - the number(count), until batch is end
* batch_size - the number, parts in batch
*/
ssize_t rest, payload_size;
int rest_batch_size, batch_size;

/** The "Greeting" from the Tarantool
*/
ngx_int_t greeting:1;

/**
*/
ngx_int_t url_encoded_body:1;

/** The preset method and its length
*/
u_char preset_method[128];
u_char preset_method_len;
} ngx_http_tnt_ctx_t;

ngx_http_tnt_ctx_t * ngx_http_tnt_create_ctx(ngx_http_request_t *r);
void ngx_http_tnt_reset_ctx(ngx_http_tnt_ctx_t *ctx);

ngx_int_t ngx_http_tnt_init_handlers(ngx_http_request_t *r,
ngx_http_upstream_t *u,
ngx_http_tnt_loc_conf_t *tlcf);

/** Request handlers [
*/
ngx_int_t ngx_http_tnt_body_handler(ngx_http_request_t *r);
ngx_int_t ngx_http_tnt_query_handler(ngx_http_request_t *r);
/* ] */

ngx_int_t ngx_http_tnt_reinit_request(ngx_http_request_t *r);
ngx_int_t ngx_http_tnt_process_header(ngx_http_request_t *r);
void ngx_http_tnt_abort_request(ngx_http_request_t *r);
void ngx_http_tnt_finalize_request(ngx_http_request_t *r, ngx_int_t rc);

ngx_buf_t* ngx_http_tnt_set_err(ngx_http_request_t *r,
int errcode,
const u_char *msg,
size_t msglen);

/** Known errors. And, function allow get the know error by type [[
*/
typedef struct ngx_http_tnt_error {
const ngx_str_t msg;
int code;
} ngx_http_tnt_error_t;

/** The known error types
*/
enum ngx_http_tnt_err_messages_idx {
REQUEST_TOO_LARGE = 0,
UNKNOWN_PARSE_ERROR = 1,
HTTP_REQUEST_TOO_LARGE = 2
};

const ngx_http_tnt_error_t *get_error_text(int type);
/** ]]
*/

/** Get size of overhead of JSON protocol
*/
static inline size_t
ngx_http_tnt_overhead(void)
{
return sizeof("[{"
"'error': {"
"'code':-XXXXX,"
"'message':''"
"},"
"{ 'result': [[]],"
"'id': 1867996680 }"
"}");
}

#endif /* NGX_HTTP_TNT_CREATE_REQUEST_H_INCLUDED */

+ 1480
- 24
src/ngx_http_tnt_module.c
File diff suppressed because it is too large
View File


+ 1
- 1
src/ngx_http_tnt_version.h View File

@@ -33,6 +33,6 @@
#ifndef NGX_HTTP_TNT_VERSION_H
#define NGX_HTTP_TNT_VERSION_H 1

#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.5-stable"
#define NGX_HTTP_TNT_MODULE_VERSION_STRING "v2.5.1-stable"

#endif

+ 21
- 21
src/tp_transcode.c View File

@@ -1244,36 +1244,36 @@ tp_transcode_init(tp_transcode_t *t, const tp_transcode_init_args_t *args)
void
tp_transcode_free(tp_transcode_t *t)
{
assert(t);
assert(t->codec.ctx);
assert(t);
assert(t->codec.ctx);

if (unlikely(t->errmsg != NULL)) {
t->mf.free(t->mf.ctx, t->errmsg);
t->errmsg = NULL;
}
if (unlikely(t->errmsg != NULL)) {
t->mf.free(t->mf.ctx, t->errmsg);
t->errmsg = NULL;
}

t->codec.free(t->codec.ctx);
t->codec.ctx = NULL;
t->codec.free(t->codec.ctx);
t->codec.ctx = NULL;

t->method = NULL;
t->method_len = 0;
t->method = NULL;
t->method_len = 0;
}

enum tt_result
tp_transcode_complete(tp_transcode_t *t, size_t *complete_msg_size)
{
assert(t);
assert(t->codec.ctx);
*complete_msg_size = 0;
return t->codec.complete(t->codec.ctx, complete_msg_size);
assert(t);
assert(t->codec.ctx);
*complete_msg_size = 0;
return t->codec.complete(t->codec.ctx, complete_msg_size);
}

enum tt_result
tp_transcode(tp_transcode_t *t, const char *b, size_t s)
{
assert(t);
assert(t->codec.ctx);
return t->codec.transcode(t->codec.ctx, b, s);
assert(t);
assert(t->codec.ctx);
return t->codec.transcode(t->codec.ctx, b, s);
}

void
@@ -1281,10 +1281,10 @@ tp_transcode_bind_data(tp_transcode_t *t,
const char *data_beg,
const char *data_end)
{
assert(t);
t->data.pos = data_beg;
t->data.end = data_end;
t->data.len = data_end - data_beg;
assert(t);
t->data.pos = data_beg;
t->data.end = data_end;
t->data.len = data_end - data_beg;
}

void

+ 1
- 1
t/basic_features.py View File

@@ -79,7 +79,7 @@ def batch_cases():
])

assert(rc == 200), 'expected 200'
assert(len(res) == 2), 'expected 2 elements, got %i' % len(res)
assert(len(res) == 2), 'expected 2 elements, got ' + str(len(res))
assert(res[0]['result'][0][0][1] == '101234567891234567')
assert(res[1]['result'][0][0][1] == '101234567891234567')


Loading…
Cancel
Save