Permalink
Please sign in to comment.
Showing
with
264 additions
and 14 deletions.
- +1 −0 .gitignore
- +147 −0 src/ngx_http_rds.h
- +23 −11 src/ngx_http_rds_json_filter_module.c
- +3 −1 src/ngx_http_rds_json_filter_module.h
- +50 −0 src/ngx_http_rds_json_processor.c
- +34 −0 src/ngx_http_rds_json_processor.h
- +2 −1 src/ngx_http_rds_json_util.c
- +4 −1 src/ngx_http_rds_json_util.h
@@ -0,0 +1,147 @@ | ||
+ | ||
+/* | ||
+ * Copyright (C) agentzh | ||
+ */ | ||
+ | ||
+#ifndef NGX_HTTP_RDS_H | ||
+#define NGX_HTTP_RDS_H | ||
+ | ||
+ | ||
+#include <nginx.h> | ||
+#include <ngx_core.h> | ||
+#include <ngx_http.h> | ||
+ | ||
+ | ||
+typedef struct { | ||
+ uint16_t std_errcode; | ||
+ uint16_t drv_errcode; | ||
+ ngx_str_t errstr; | ||
+ | ||
+ uint64_t affected_rows; | ||
+ uint64_t insert_id; | ||
+ uint16_t column_count; | ||
+ | ||
+} ngx_http_rds_header_t; | ||
+ | ||
+ | ||
+static ngx_int_t | ||
+ngx_http_rds_parse_header(ngx_http_request_t *r, ngx_buf_t *b, | ||
+ ngx_http_rds_header_t *header) | ||
+{ | ||
+ size_t rest; | ||
+ | ||
+ rest = sizeof(uint8_t) /* endian type */ | ||
+ + sizeof(uint32_t) /* format version */ | ||
+ + sizeof(uint8_t) /* result type */ | ||
+ | ||
+ + sizeof(uint16_t) /* standard error code */ | ||
+ + sizeof(uint16_t) /* driver-specific error code */ | ||
+ | ||
+ + sizeof(uint16_t) /* driver-specific errstr len */ | ||
+ + 0 /* driver-specific errstr data */ | ||
+ + sizeof(uint64_t) /* affected rows */ | ||
+ + sizeof(uint64_t) /* insert id */ | ||
+ + sizeof(uint16_t) /* column count */ | ||
+ ; | ||
+ | ||
+ if (b->last - b->pos < rest) { | ||
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | ||
+ "rds: header is incomplete in the buf"); | ||
+ return NGX_ERROR; | ||
+ } | ||
+ | ||
+ /* check endian type */ | ||
+ | ||
+ if ( *(uint8_t *) b->pos != | ||
+#if (NGX_HAVE_LITTLE_ENDIAN) | ||
+ 0 | ||
+#else /* big endian */ | ||
+ 1 | ||
+#endif | ||
+ ) | ||
+ { | ||
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | ||
+ "rds: endian type in the header differ"); | ||
+ return NGX_ERROR; | ||
+ } | ||
+ | ||
+ b->pos += sizeof(uint8_t); | ||
+ | ||
+ /* check RDS format version number */ | ||
+ | ||
+ if ( *(uint32_t *) b->pos != (uint32_t) resty_dbd_stream_version) { | ||
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | ||
+ "rds: RDS format version differ"); | ||
+ return NGX_ERROR; | ||
+ } | ||
+ | ||
+ b->pos += sizeof(uint32_t); | ||
+ | ||
+ /* check RDS format type */ | ||
+ | ||
+ if (*b->pos != 0) { | ||
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | ||
+ "rds: RDS format type must be 0 for now"); | ||
+ return NGX_ERROR; | ||
+ } | ||
+ | ||
+ b->pos++; | ||
+ | ||
+ /* save the standard error code */ | ||
+ | ||
+ header->std_errcode = *(uint16_t) b->pos; | ||
+ | ||
+ b->pos += sizeof(uint16_t); | ||
+ | ||
+ /* save the driver-specific error code */ | ||
+ | ||
+ header->drv_errcode = *(uint16_t) b->pos; | ||
+ | ||
+ b->pos += sizeof(uint16_t); | ||
+ | ||
+ /* save the error string length */ | ||
+ | ||
+ header->errstr.len = *(uint16_t) b->pos; | ||
+ | ||
+ b->pos += sizeof(uint16_t); | ||
+ | ||
+ /* check the rest data's size */ | ||
+ | ||
+ rest = header->errstr.len | ||
+ + sizeof(uint64_t) /* affected rows */ | ||
+ + sizeof(uint64_t) /* insert id */ | ||
+ + sizeof(uint16_t) /* column count */ | ||
+ ; | ||
+ | ||
+ if (b->last - b->pos < rest) { | ||
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | ||
+ "rds: header is incomplete in the buf"); | ||
+ return NGX_ERROR; | ||
+ } | ||
+ | ||
+ /* save the error string data */ | ||
+ | ||
+ header->errstr.data = b->pos; | ||
+ | ||
+ b->pos += header->errstr.len; | ||
+ | ||
+ /* save affected rows */ | ||
+ | ||
+ header->affected_rows = *(uint64_t *) b->pos; | ||
+ | ||
+ b->pos += sizeof(uint64_t); | ||
+ | ||
+ header->insert_id = *(uint64_t *)b->pos; | ||
+ | ||
+ b->pos += sizeof(uint64_t); | ||
+ | ||
+ header->column_count = *(uint16_t *) b->pos; | ||
+ | ||
+ b->pos += sizeof(uint16_t); | ||
+ | ||
+ return NGX_OK; | ||
+} | ||
+ | ||
+ | ||
+#endif /* NGX_HTTP_RDS_H */ | ||
+ |
@@ -0,0 +1,50 @@ | ||
+/* | ||
+ * Copyright (C) agentzh | ||
+ */ | ||
+ | ||
+ | ||
+#define DDEBUG 1 | ||
+#include "ddebug.h" | ||
+ | ||
+#include "ngx_http_rds_json_processor.h" | ||
+ | ||
+ | ||
+ngx_int_t | ||
+ngx_http_rds_json_process_header(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx){ | ||
+ /* TODO */ | ||
+ return NGX_OK; | ||
+} | ||
+ | ||
+ | ||
+ngx_int_t | ||
+ngx_http_rds_json_process_col(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx){ | ||
+ /* TODO */ | ||
+ return NGX_OK; | ||
+} | ||
+ | ||
+ | ||
+ngx_int_t | ||
+ngx_http_rds_json_process_row(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx){ | ||
+ /* TODO */ | ||
+ return NGX_OK; | ||
+} | ||
+ | ||
+ | ||
+ngx_int_t | ||
+ngx_http_rds_json_process_field(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx){ | ||
+ /* TODO */ | ||
+ return NGX_OK; | ||
+} | ||
+ | ||
+ | ||
+ngx_int_t | ||
+ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx){ | ||
+ /* TODO */ | ||
+ return NGX_OK; | ||
+} | ||
+ |
@@ -0,0 +1,34 @@ | ||
+ | ||
+/* | ||
+ * Copyright (C) agentzh | ||
+ */ | ||
+ | ||
+#ifndef NGX_HTTP_RDS_JSON_PROCESSOR_H | ||
+#define NGX_HTTP_RDS_JSON_PROCESSOR_H | ||
+ | ||
+ | ||
+#include "ngx_http_rds_json_filter_module.h" | ||
+ | ||
+#include <ngx_core.h> | ||
+#include <ngx_http.h> | ||
+#include <nginx.h> | ||
+ | ||
+ | ||
+ngx_int_t ngx_http_rds_json_process_header(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx); | ||
+ | ||
+ngx_int_t ngx_http_rds_json_process_col(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx); | ||
+ | ||
+ngx_int_t ngx_http_rds_json_process_row(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx); | ||
+ | ||
+ngx_int_t ngx_http_rds_json_process_field(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx); | ||
+ | ||
+ngx_int_t ngx_http_rds_json_process_more_field_data(ngx_http_request_t *r, | ||
+ ngx_chain_t *in, ngx_http_rds_json_ctx_t *ctx); | ||
+ | ||
+ | ||
+#endif /* NGX_HTTP_RDS_JSON_PROCESSOR_H */ | ||
+ |
@@ -1,7 +1,10 @@ | ||
#ifndef NGX_HTTP_RDS_JSON_UTIL_H | ||
#define NGX_HTTP_RDS_JSON_UTIL_H | ||
-ngx_int_t ngx_http_rds_json_test_content_type(r); | ||
+#include <ngx_core.h> | ||
+#include <ngx_http.h> | ||
+ | ||
+ngx_int_t ngx_http_rds_json_test_content_type(ngx_http_request_t *r); | ||
#endif /* NGX_HTTP_RDS_JSON_UTIL_H */ | ||
0 comments on commit
079825d