This commit is contained in:
Shengliang Guan 2021-01-22 11:59:14 +08:00
parent 2079533b50
commit fa7e9bd6d2
19 changed files with 247 additions and 238 deletions

View File

@ -26,7 +26,7 @@
int32_t httpParseBasicAuthToken(HttpContext *pContext, char *token, int32_t len) { int32_t httpParseBasicAuthToken(HttpContext *pContext, char *token, int32_t len) {
token[len] = '\0'; token[len] = '\0';
int32_t outlen = 0; int32_t outlen = 0;
char *base64 = (char *)base64_decode(token, len, &outlen); char * base64 = (char *)base64_decode(token, len, &outlen);
if (base64 == NULL || outlen == 0) { if (base64 == NULL || outlen == 0) {
httpError("context:%p, fd:%d, basic token:%s parsed error", pContext, pContext->fd, token); httpError("context:%p, fd:%d, basic token:%s parsed error", pContext, pContext->fd, token);
free(base64); free(base64);
@ -49,7 +49,7 @@ int32_t httpParseBasicAuthToken(HttpContext *pContext, char *token, int32_t len)
strncpy(pContext->user, base64, (size_t)user_len); strncpy(pContext->user, base64, (size_t)user_len);
pContext->user[user_len] = 0; pContext->user[user_len] = 0;
char *password = user + 1; char * password = user + 1;
int32_t pass_len = (int32_t)((base64 + outlen) - password); int32_t pass_len = (int32_t)((base64 + outlen) - password);
if (pass_len < 1 || pass_len >= HTTP_PASSWORD_LEN) { if (pass_len < 1 || pass_len >= HTTP_PASSWORD_LEN) {
httpError("context:%p, fd:%d, basic token:%s parse password error", pContext, pContext->fd, token); httpError("context:%p, fd:%d, basic token:%s parse password error", pContext, pContext->fd, token);

View File

@ -100,9 +100,7 @@ const char *httpContextStateStr(HttpContextState state) {
} }
} }
void httpNotifyContextClose(HttpContext *pContext) { void httpNotifyContextClose(HttpContext *pContext) { shutdown(pContext->fd, SHUT_WR); }
shutdown(pContext->fd, SHUT_WR);
}
bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState) { bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState) {
return (atomic_val_compare_exchange_32(&pContext->state, srcState, destState) == srcState); return (atomic_val_compare_exchange_32(&pContext->state, srcState, destState) == srcState);
@ -124,7 +122,7 @@ HttpContext *httpCreateContext(int32_t fd) {
httpDebug("context:%p, fd:%d, is created, data:%p", pContext, fd, ppContext); httpDebug("context:%p, fd:%d, is created, data:%p", pContext, fd, ppContext);
// set the ref to 0 // set the ref to 0
taosCacheRelease(tsHttpServer.contextCache, (void**)&ppContext, false); taosCacheRelease(tsHttpServer.contextCache, (void **)&ppContext, false);
return pContext; return pContext;
} }
@ -174,7 +172,6 @@ bool httpInitContext(HttpContext *pContext) {
pContext->encodeMethod = NULL; pContext->encodeMethod = NULL;
memset(&pContext->singleCmd, 0, sizeof(HttpSqlCmd)); memset(&pContext->singleCmd, 0, sizeof(HttpSqlCmd));
httpTrace("context:%p, fd:%d, parsed:%d", pContext, pContext->fd, pContext->parsed); httpTrace("context:%p, fd:%d, parsed:%d", pContext, pContext->fd, pContext->parsed);
return true; return true;
} }

View File

@ -125,14 +125,14 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
cmd->numOfRows--; cmd->numOfRows--;
continue; continue;
} }
int32_t* length = taos_fetch_lengths(result); int32_t *length = taos_fetch_lengths(result);
// for group by // for group by
if (groupFields != -1) { if (groupFields != -1) {
char target[HTTP_GC_TARGET_SIZE] = {0}; char target[HTTP_GC_TARGET_SIZE] = {0};
int32_t len; int32_t len;
len = snprintf(target,HTTP_GC_TARGET_SIZE,"%s{",aliasBuffer); len = snprintf(target, HTTP_GC_TARGET_SIZE, "%s{", aliasBuffer);
for (int32_t i = dataFields + 1; i<num_fields; i++){ for (int32_t i = dataFields + 1; i < num_fields; i++) {
switch (fields[i].type) { switch (fields[i].type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
@ -155,9 +155,9 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
if (row[i]!= NULL){ if (row[i] != NULL) {
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:", fields[i].name); len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:", fields[i].name);
memcpy(target + len, (char *) row[i], length[i]); memcpy(target + len, (char *)row[i], length[i]);
len = (int32_t)strlen(target); len = (int32_t)strlen(target);
} }
break; break;
@ -165,10 +165,9 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%s", fields[i].name, "-"); len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "%s:%s", fields[i].name, "-");
break; break;
} }
if(i < num_fields - 1 ){ if (i < num_fields - 1) {
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, ", "); len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, ", ");
} }
} }
len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "}"); len += snprintf(target + len, HTTP_GC_TARGET_SIZE - len, "}");
@ -217,10 +216,10 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
httpJsonStringForTransMean(jsonBuf, (char*)row[i], fields[i].bytes); httpJsonStringForTransMean(jsonBuf, (char *)row[i], fields[i].bytes);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (precision == TSDB_TIME_PRECISION_MILLI) { //ms if (precision == TSDB_TIME_PRECISION_MILLI) { // ms
httpJsonInt64(jsonBuf, *((int64_t *)row[i])); httpJsonInt64(jsonBuf, *((int64_t *)row[i]));
} else { } else {
httpJsonInt64(jsonBuf, *((int64_t *)row[i]) / 1000); httpJsonInt64(jsonBuf, *((int64_t *)row[i]) / 1000);

View File

@ -27,23 +27,22 @@ typedef enum {
struct ehttp_gzip_s { struct ehttp_gzip_s {
ehttp_gzip_conf_t conf; ehttp_gzip_conf_t conf;
ehttp_gzip_callbacks_t callbacks; ehttp_gzip_callbacks_t callbacks;
void *arg; void * arg;
z_stream *gzip; z_stream * gzip;
gz_header *header; gz_header * header;
char *chunk; char * chunk;
int32_t state; int32_t state;
}; };
static void dummy_on_data(ehttp_gzip_t *gzip, void *arg, const char *buf, int32_t len) { static void dummy_on_data(ehttp_gzip_t *gzip, void *arg, const char *buf, int32_t len) {}
}
static void ehttp_gzip_cleanup(ehttp_gzip_t *gzip) { static void ehttp_gzip_cleanup(ehttp_gzip_t *gzip) {
switch(gzip->state) { switch (gzip->state) {
case EHTTP_GZIP_READY: { case EHTTP_GZIP_READY: {
inflateEnd(gzip->gzip); inflateEnd(gzip->gzip);
} break; } break;
default: break; default:
break;
} }
if (gzip->gzip) { if (gzip->gzip) {
free(gzip->gzip); free(gzip->gzip);
@ -60,8 +59,8 @@ static void ehttp_gzip_cleanup(ehttp_gzip_t *gzip) {
gzip->state = EHTTP_GZIP_CLOSED; gzip->state = EHTTP_GZIP_CLOSED;
} }
ehttp_gzip_t* ehttp_gzip_create_decompressor(ehttp_gzip_conf_t conf, ehttp_gzip_callbacks_t callbacks, void *arg) { ehttp_gzip_t *ehttp_gzip_create_decompressor(ehttp_gzip_conf_t conf, ehttp_gzip_callbacks_t callbacks, void *arg) {
ehttp_gzip_t *gzip = (ehttp_gzip_t*)calloc(1, sizeof(*gzip)); ehttp_gzip_t *gzip = (ehttp_gzip_t *)calloc(1, sizeof(*gzip));
if (!gzip) return NULL; if (!gzip) return NULL;
do { do {
@ -69,12 +68,12 @@ ehttp_gzip_t* ehttp_gzip_create_decompressor(ehttp_gzip_conf_t conf, ehttp_gzip_
gzip->callbacks = callbacks; gzip->callbacks = callbacks;
gzip->arg = arg; gzip->arg = arg;
if (gzip->callbacks.on_data == NULL) gzip->callbacks.on_data = dummy_on_data; if (gzip->callbacks.on_data == NULL) gzip->callbacks.on_data = dummy_on_data;
gzip->gzip = (z_stream*)calloc(1, sizeof(*gzip->gzip)); gzip->gzip = (z_stream *)calloc(1, sizeof(*gzip->gzip));
if (gzip->conf.get_header) { if (gzip->conf.get_header) {
gzip->header = (gz_header*)calloc(1, sizeof(*gzip->header)); gzip->header = (gz_header *)calloc(1, sizeof(*gzip->header));
} }
if (gzip->conf.chunk_size<=0) gzip->conf.chunk_size = EHTTP_GZIP_CHUNK_SIZE_DEFAULT; if (gzip->conf.chunk_size <= 0) gzip->conf.chunk_size = EHTTP_GZIP_CHUNK_SIZE_DEFAULT;
gzip->chunk = (char*)malloc(gzip->conf.chunk_size); gzip->chunk = (char *)malloc(gzip->conf.chunk_size);
if (!gzip->gzip || (gzip->conf.get_header && !gzip->header) || !gzip->chunk) break; if (!gzip->gzip || (gzip->conf.get_header && !gzip->header) || !gzip->chunk) break;
gzip->gzip->zalloc = Z_NULL; gzip->gzip->zalloc = Z_NULL;
gzip->gzip->zfree = Z_NULL; gzip->gzip->zfree = Z_NULL;
@ -95,7 +94,7 @@ ehttp_gzip_t* ehttp_gzip_create_decompressor(ehttp_gzip_conf_t conf, ehttp_gzip_
} }
if (ret != Z_OK) break; if (ret != Z_OK) break;
gzip->gzip->next_out = (z_const Bytef*)gzip->chunk; gzip->gzip->next_out = (z_const Bytef *)gzip->chunk;
gzip->gzip->avail_out = gzip->conf.chunk_size; gzip->gzip->avail_out = gzip->conf.chunk_size;
gzip->state = EHTTP_GZIP_READY; gzip->state = EHTTP_GZIP_READY;
return gzip; return gzip;
@ -105,7 +104,7 @@ ehttp_gzip_t* ehttp_gzip_create_decompressor(ehttp_gzip_conf_t conf, ehttp_gzip_
return NULL; return NULL;
} }
ehttp_gzip_t* ehttp_gzip_create_compressor(ehttp_gzip_conf_t conf, ehttp_gzip_callbacks_t callbacks, void *arg); ehttp_gzip_t *ehttp_gzip_create_compressor(ehttp_gzip_conf_t conf, ehttp_gzip_callbacks_t callbacks, void *arg);
void ehttp_gzip_destroy(ehttp_gzip_t *gzip) { void ehttp_gzip_destroy(ehttp_gzip_t *gzip) {
ehttp_gzip_cleanup(gzip); ehttp_gzip_cleanup(gzip);
@ -129,15 +128,15 @@ int32_t ehttp_gzip_write(ehttp_gzip_t *gzip, const char *buf, int32_t len) {
} }
if (ret != Z_OK && ret != Z_STREAM_END) return -1; if (ret != Z_OK && ret != Z_STREAM_END) return -1;
if (gzip->gzip->avail_out>0) { if (gzip->gzip->avail_out > 0) {
if (ret!=Z_STREAM_END) continue; if (ret != Z_STREAM_END) continue;
} }
int32_t len = (int32_t)(gzip->gzip->next_out - (z_const Bytef*)gzip->chunk); int32_t len = (int32_t)(gzip->gzip->next_out - (z_const Bytef *)gzip->chunk);
gzip->gzip->next_out[0] = '\0'; gzip->gzip->next_out[0] = '\0';
gzip->callbacks.on_data(gzip, gzip->arg, gzip->chunk, len); gzip->callbacks.on_data(gzip, gzip->arg, gzip->chunk, len);
gzip->gzip->next_out = (z_const Bytef*)gzip->chunk; gzip->gzip->next_out = (z_const Bytef *)gzip->chunk;
gzip->gzip->avail_out = gzip->conf.chunk_size; gzip->gzip->avail_out = gzip->conf.chunk_size;
} }
@ -155,7 +154,7 @@ int32_t ehttp_gzip_finish(ehttp_gzip_t *gzip) {
if (ret != Z_STREAM_END) return -1; if (ret != Z_STREAM_END) return -1;
int32_t len = (int32_t)(gzip->gzip->next_out - (z_const Bytef*)gzip->chunk); int32_t len = (int32_t)(gzip->gzip->next_out - (z_const Bytef *)gzip->chunk);
gzip->gzip->next_out[0] = '\0'; gzip->gzip->next_out[0] = '\0';
gzip->callbacks.on_data(gzip, gzip->arg, gzip->chunk, len); gzip->callbacks.on_data(gzip, gzip->arg, gzip->chunk, len);
@ -164,4 +163,3 @@ int32_t ehttp_gzip_finish(ehttp_gzip_t *gzip) {
return 0; return 0;
} }

View File

@ -48,7 +48,7 @@ bool httpProcessData(HttpContext* pContext) {
/* /*
* httpCloseContextByApp has been called when parsing the error * httpCloseContextByApp has been called when parsing the error
*/ */
//httpCloseContextByApp(pContext); // httpCloseContextByApp(pContext);
} else { } else {
httpProcessRequest(pContext); httpProcessRequest(pContext);
} }

View File

@ -44,20 +44,21 @@ int32_t httpWriteBufByFd(struct HttpContext* pContext, const char* buf, int32_t
int32_t writeLen = 0; int32_t writeLen = 0;
do { do {
if (pContext->fd > 2){ if (pContext->fd > 2) {
len = (int32_t)taosSend(pContext->fd, buf + writeLen, (size_t)(sz - writeLen), MSG_NOSIGNAL); len = (int32_t)taosSend(pContext->fd, buf + writeLen, (size_t)(sz - writeLen), MSG_NOSIGNAL);
} } else {
else {
return sz; return sz;
} }
if (len < 0) { if (len < 0) {
httpDebug("context:%p, fd:%d, socket write errno:%d:%s, times:%d", pContext, pContext->fd, errno, strerror(errno), countWait); httpDebug("context:%p, fd:%d, socket write errno:%d:%s, times:%d", pContext, pContext->fd, errno, strerror(errno),
countWait);
if (++countWait > HTTP_WRITE_RETRY_TIMES) break; if (++countWait > HTTP_WRITE_RETRY_TIMES) break;
taosMsleep(HTTP_WRITE_WAIT_TIME_MS); taosMsleep(HTTP_WRITE_WAIT_TIME_MS);
continue; continue;
} else if (len == 0) { } else if (len == 0) {
httpDebug("context:%p, fd:%d, socket write errno:%d:%s, connect already closed", pContext, pContext->fd, errno, strerror(errno)); httpDebug("context:%p, fd:%d, socket write errno:%d:%s, connect already closed", pContext, pContext->fd, errno,
strerror(errno));
break; break;
} else { } else {
countWait = 0; countWait = 0;
@ -80,7 +81,7 @@ int32_t httpWriteBuf(struct HttpContext* pContext, const char* buf, int32_t sz)
return writeSz; return writeSz;
} }
int32_t httpWriteBufNoTrace(struct HttpContext *pContext, const char *buf, int32_t sz) { int32_t httpWriteBufNoTrace(struct HttpContext* pContext, const char* buf, int32_t sz) {
int32_t writeSz = httpWriteBufByFd(pContext, buf, sz); int32_t writeSz = httpWriteBufByFd(pContext, buf, sz);
if (writeSz != sz) { if (writeSz != sz) {
httpError("context:%p, fd:%d, dataSize:%d, writeSize:%d, failed to send response", pContext, pContext->fd, sz, httpError("context:%p, fd:%d, dataSize:%d, writeSize:%d, failed to send response", pContext, pContext->fd, sz,
@ -93,7 +94,7 @@ int32_t httpWriteBufNoTrace(struct HttpContext *pContext, const char *buf, int32
int32_t httpWriteJsonBufBody(JsonBuf* buf, bool isTheLast) { int32_t httpWriteJsonBufBody(JsonBuf* buf, bool isTheLast) {
int32_t remain = 0; int32_t remain = 0;
char sLen[24]; char sLen[24];
int32_t srcLen = (int32_t) (buf->lst - buf->buf); int32_t srcLen = (int32_t)(buf->lst - buf->buf);
if (buf->pContext->fd <= 0) { if (buf->pContext->fd <= 0) {
httpTrace("context:%p, fd:%d, write json body error", buf->pContext, buf->pContext->fd); httpTrace("context:%p, fd:%d, write json body error", buf->pContext, buf->pContext->fd);
@ -113,9 +114,9 @@ int32_t httpWriteJsonBufBody(JsonBuf* buf, bool isTheLast) {
httpTrace("context:%p, fd:%d, no data need dump", buf->pContext, buf->pContext->fd); httpTrace("context:%p, fd:%d, no data need dump", buf->pContext, buf->pContext->fd);
return 0; // there is no data to dump. return 0; // there is no data to dump.
} else { } else {
int32_t len = sprintf(sLen, "%d\r\n", srcLen); int32_t len = sprintf(sLen, "%x\r\n", srcLen);
httpTrace("context:%p, fd:%d, write body, chunkSize:%d, response:\n%s", buf->pContext, buf->pContext->fd, httpTrace("context:%p, fd:%d, write body, chunkSize:%d, response:\n%s", buf->pContext, buf->pContext->fd, srcLen,
srcLen, buf->buf); buf->buf);
httpWriteBufNoTrace(buf->pContext, sLen, len); httpWriteBufNoTrace(buf->pContext, sLen, len);
remain = httpWriteBufNoTrace(buf->pContext, buf->buf, srcLen); remain = httpWriteBufNoTrace(buf->pContext, buf->buf, srcLen);
} }
@ -126,8 +127,8 @@ int32_t httpWriteJsonBufBody(JsonBuf* buf, bool isTheLast) {
if (ret == 0) { if (ret == 0) {
if (compressBufLen > 0) { if (compressBufLen > 0) {
int32_t len = sprintf(sLen, "%x\r\n", compressBufLen); int32_t len = sprintf(sLen, "%x\r\n", compressBufLen);
httpTrace("context:%p, fd:%d, write body, chunkSize:%d, compressSize:%d, last:%d, response:\n%s", httpTrace("context:%p, fd:%d, write body, chunkSize:%d, compressSize:%d, last:%d, response:\n%s", buf->pContext,
buf->pContext, buf->pContext->fd, srcLen, compressBufLen, isTheLast, buf->buf); buf->pContext->fd, srcLen, compressBufLen, isTheLast, buf->buf);
httpWriteBufNoTrace(buf->pContext, sLen, len); httpWriteBufNoTrace(buf->pContext, sLen, len);
remain = httpWriteBufNoTrace(buf->pContext, (const char*)compressBuf, compressBufLen); remain = httpWriteBufNoTrace(buf->pContext, (const char*)compressBuf, compressBufLen);
} else { } else {
@ -257,7 +258,7 @@ void httpJsonInt64(JsonBuf* buf, int64_t num) {
void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) { void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) {
char ts[35] = {0}; char ts[35] = {0};
struct tm *ptm; struct tm* ptm;
int32_t precision = 1000; int32_t precision = 1000;
if (us) { if (us) {
precision = 1000000; precision = 1000000;
@ -265,7 +266,7 @@ void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) {
time_t tt = t / precision; time_t tt = t / precision;
ptm = localtime(&tt); ptm = localtime(&tt);
int32_t length = (int32_t) strftime(ts, 35, "%Y-%m-%d %H:%M:%S", ptm); int32_t length = (int32_t)strftime(ts, 35, "%Y-%m-%d %H:%M:%S", ptm);
if (us) { if (us) {
length += snprintf(ts + length, 8, ".%06" PRId64, t % precision); length += snprintf(ts + length, 8, ".%06" PRId64, t % precision);
} else { } else {
@ -277,7 +278,7 @@ void httpJsonTimestamp(JsonBuf* buf, int64_t t, bool us) {
void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us) { void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, bool us) {
char ts[40] = {0}; char ts[40] = {0};
struct tm *ptm; struct tm* ptm;
int32_t precision = 1000; int32_t precision = 1000;
if (us) { if (us) {
precision = 1000000; precision = 1000000;

View File

@ -237,7 +237,6 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const
} }
httpTrace("context:%p, fd:%d, keepAlive:%d", pContext, pContext->fd, pContext->parser->keepAlive); httpTrace("context:%p, fd:%d, keepAlive:%d", pContext, pContext->fd, pContext->parser->keepAlive);
} }
#if 0 #if 0
else if (0 == strcasecmp(key, "Content-Encoding")) { else if (0 == strcasecmp(key, "Content-Encoding")) {
if (0 == strcmp(val, "gzip")) { if (0 == strcmp(val, "gzip")) {
@ -246,7 +245,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const
} }
return 0; return 0;
} }
#endif #endif
else if (0 == strcasecmp(key, "Transfer-Encoding") || 0 == strcasecmp(key, "Content-Encoding")) { else if (0 == strcasecmp(key, "Transfer-Encoding") || 0 == strcasecmp(key, "Content-Encoding")) {
if (strstr(val, "gzip")) { if (strstr(val, "gzip")) {
@ -410,9 +409,7 @@ static int32_t httpPopStack(HttpParser *parser) {
return 0; return 0;
} }
static void httpClearStack(HttpStack *stack) { static void httpClearStack(HttpStack *stack) { stack->pos = 0; }
stack->pos = 0;
}
static int32_t httpCleanupStack(HttpStack *stack) { static int32_t httpCleanupStack(HttpStack *stack) {
free(stack->stacks); free(stack->stacks);
@ -522,16 +519,27 @@ char *httpDecodeUrl(const char *enc) {
char *p = strchr(enc, '%'); char *p = strchr(enc, '%');
if (!p) break; if (!p) break;
int32_t hex, cnt; int32_t hex, cnt;
int32_t n = sscanf(p+1, "%2x%n", &hex, &cnt); int32_t n = sscanf(p + 1, "%2x%n", &hex, &cnt);
if (n!=1 && cnt !=2) { ok = 0; break; } if (n != 1 && cnt != 2) {
if (httpAppendString(&str, enc, (int32_t)(p-enc))) { ok = 0; break; } ok = 0;
break;
}
if (httpAppendString(&str, enc, (int32_t)(p - enc))) {
ok = 0;
break;
}
char c = (char)hex; char c = (char)hex;
if (httpAppendString(&str, &c, 1)) { ok = 0; break; } if (httpAppendString(&str, &c, 1)) {
enc = p+3; ok = 0;
break;
}
enc = p + 3;
} }
char *dec = NULL; char *dec = NULL;
if (ok && *enc) { if (ok && *enc) {
if (httpAppendString(&str, enc, (int32_t)strlen(enc))) { ok = 0; } if (httpAppendString(&str, enc, (int32_t)strlen(enc))) {
ok = 0;
}
} }
if (ok) { if (ok) {
dec = str.str; dec = str.str;
@ -542,7 +550,7 @@ char *httpDecodeUrl(const char *enc) {
} }
static void httpOnData(ehttp_gzip_t *gzip, void *arg, const char *buf, int32_t len) { static void httpOnData(ehttp_gzip_t *gzip, void *arg, const char *buf, int32_t len) {
HttpParser *parser = (HttpParser*)arg; HttpParser *parser = (HttpParser *)arg;
httpOnBody(parser, buf, len); httpOnBody(parser, buf, len);
} }
@ -1029,7 +1037,7 @@ static int32_t httpParserOnEnd(HttpParser *parser, HTTP_PARSER_STATE state, cons
} }
static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) { static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) {
HttpContext *pContext = parser->pContext; HttpContext * pContext = parser->pContext;
int32_t ok = 0; int32_t ok = 0;
HTTP_PARSER_STATE state = httpTopStack(parser); HTTP_PARSER_STATE state = httpTopStack(parser);
do { do {
@ -1119,7 +1127,7 @@ static int32_t httpParseChar(HttpParser *parser, const char c, int32_t *again) {
int32_t httpParseBuf(HttpParser *parser, const char *buf, int32_t len) { int32_t httpParseBuf(HttpParser *parser, const char *buf, int32_t len) {
HttpContext *pContext = parser->pContext; HttpContext *pContext = parser->pContext;
const char *p = buf; const char * p = buf;
int32_t ret = 0; int32_t ret = 0;
int32_t i = 0; int32_t i = 0;

View File

@ -161,7 +161,8 @@ void httpSendTaosdInvalidSqlErrorResp(HttpContext *pContext, char *errMsg) {
temp[i] = '\''; temp[i] = '\'';
} else if (temp[i] == '\n') { } else if (temp[i] == '\n') {
temp[i] = ' '; temp[i] = ' ';
} else {} } else {
}
} }
httpSendErrorRespImp(pContext, httpCode, "Bad Request", TSDB_CODE_TSC_INVALID_SQL & 0XFFFF, temp); httpSendErrorRespImp(pContext, httpCode, "Bad Request", TSDB_CODE_TSC_INVALID_SQL & 0XFFFF, temp);

View File

@ -95,7 +95,6 @@ bool restProcessSqlRequest(HttpContext* pContext, int32_t timestampFmt) {
return false; return false;
} }
/* /*
* for async test * for async test
* *

View File

@ -83,7 +83,8 @@ void restStartSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result)
httpJsonToken(jsonBuf, JsonArrStt); httpJsonToken(jsonBuf, JsonArrStt);
} }
bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows, int32_t timestampFormat) { bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows,
int32_t timestampFormat) {
JsonBuf *jsonBuf = httpMallocJsonBuf(pContext); JsonBuf *jsonBuf = httpMallocJsonBuf(pContext);
if (jsonBuf == NULL) return false; if (jsonBuf == NULL) return false;
@ -95,7 +96,7 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
if (row == NULL) { if (row == NULL) {
continue; continue;
} }
int32_t* length = taos_fetch_lengths(result); int32_t *length = taos_fetch_lengths(result);
// data row array begin // data row array begin
httpJsonItemToken(jsonBuf); httpJsonItemToken(jsonBuf);
@ -131,15 +132,17 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
httpJsonStringForTransMean(jsonBuf, (char*)row[i], length[i]); httpJsonStringForTransMean(jsonBuf, (char *)row[i], length[i]);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (timestampFormat == REST_TIMESTAMP_FMT_LOCAL_STRING) { if (timestampFormat == REST_TIMESTAMP_FMT_LOCAL_STRING) {
httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO); httpJsonTimestamp(jsonBuf, *((int64_t *)row[i]),
taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO);
} else if (timestampFormat == REST_TIMESTAMP_FMT_TIMESTAMP) { } else if (timestampFormat == REST_TIMESTAMP_FMT_TIMESTAMP) {
httpJsonInt64(jsonBuf, *((int64_t *)row[i])); httpJsonInt64(jsonBuf, *((int64_t *)row[i]));
} else { } else {
httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i]), taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO); httpJsonUtcTimestamp(jsonBuf, *((int64_t *)row[i]),
taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO);
} }
break; break;
default: default:
@ -149,7 +152,7 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
// data row array end // data row array end
httpJsonToken(jsonBuf, JsonArrEnd); httpJsonToken(jsonBuf, JsonArrEnd);
cmd->numOfRows ++; cmd->numOfRows++;
if (pContext->fd <= 0) { if (pContext->fd <= 0) {
httpError("context:%p, fd:%d, user:%s, conn closed, abort retrieve", pContext, pContext->fd, pContext->user); httpError("context:%p, fd:%d, user:%s, conn closed, abort retrieve", pContext, pContext->fd, pContext->user);
@ -168,15 +171,15 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
} }
bool restBuildSqlTimestampJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows) { bool restBuildSqlTimestampJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows) {
return restBuildSqlJson(pContext,cmd, result, numOfRows, REST_TIMESTAMP_FMT_TIMESTAMP); return restBuildSqlJson(pContext, cmd, result, numOfRows, REST_TIMESTAMP_FMT_TIMESTAMP);
} }
bool restBuildSqlLocalTimeStringJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows) { bool restBuildSqlLocalTimeStringJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows) {
return restBuildSqlJson(pContext,cmd, result, numOfRows, REST_TIMESTAMP_FMT_LOCAL_STRING); return restBuildSqlJson(pContext, cmd, result, numOfRows, REST_TIMESTAMP_FMT_LOCAL_STRING);
} }
bool restBuildSqlUtcTimeStringJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows) { bool restBuildSqlUtcTimeStringJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int32_t numOfRows) {
return restBuildSqlJson(pContext,cmd, result, numOfRows, REST_TIMESTAMP_FMT_UTC_STRING); return restBuildSqlJson(pContext, cmd, result, numOfRows, REST_TIMESTAMP_FMT_UTC_STRING);
} }
void restStopSqlJson(HttpContext *pContext, HttpSqlCmd *cmd) { void restStopSqlJson(HttpContext *pContext, HttpSqlCmd *cmd) {

View File

@ -27,19 +27,21 @@
static bool httpReadData(HttpContext *pContext); static bool httpReadData(HttpContext *pContext);
static void httpStopThread(HttpThread* pThread) { static void httpStopThread(HttpThread *pThread) {
pThread->stop = true; pThread->stop = true;
// signal the thread to stop, try graceful method first, // signal the thread to stop, try graceful method first,
// and use pthread_cancel when failed // and use pthread_cancel when failed
struct epoll_event event = { .events = EPOLLIN }; struct epoll_event event = {.events = EPOLLIN};
eventfd_t fd = eventfd(1, 0); eventfd_t fd = eventfd(1, 0);
if (fd == -1) { if (fd == -1) {
httpError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s", pThread->label, strerror(errno)); httpError("%s, failed to create eventfd, will call pthread_cancel instead, which may result in data corruption: %s",
pThread->label, strerror(errno));
pThread->stop = true; pThread->stop = true;
pthread_cancel(pThread->thread); pthread_cancel(pThread->thread);
} else if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { } else if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) {
httpError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s", pThread->label, strerror(errno)); httpError("%s, failed to call epoll_ctl, will call pthread_cancel instead, which may result in data corruption: %s",
pThread->label, strerror(errno));
pthread_cancel(pThread->thread); pthread_cancel(pThread->thread);
} }
@ -61,7 +63,7 @@ void httpCleanUpConnect() {
} }
for (int32_t i = 0; i < pServer->numOfThreads; ++i) { for (int32_t i = 0; i < pServer->numOfThreads; ++i) {
HttpThread* pThread = pServer->pThreads + i; HttpThread *pThread = pServer->pThreads + i;
if (pThread != NULL) { if (pThread != NULL) {
httpStopThread(pThread); httpStopThread(pThread);
} }
@ -71,8 +73,8 @@ void httpCleanUpConnect() {
} }
static void httpProcessHttpData(void *param) { static void httpProcessHttpData(void *param) {
HttpServer *pServer = &tsHttpServer; HttpServer * pServer = &tsHttpServer;
HttpThread *pThread = (HttpThread *)param; HttpThread * pThread = (HttpThread *)param;
HttpContext *pContext; HttpContext *pContext;
int32_t fdNum; int32_t fdNum;
@ -92,8 +94,8 @@ static void httpProcessHttpData(void *param) {
pContext = httpGetContext(events[i].data.ptr); pContext = httpGetContext(events[i].data.ptr);
if (pContext == NULL) { if (pContext == NULL) {
httpError("context:%p, is already released, close connect", events[i].data.ptr); httpError("context:%p, is already released, close connect", events[i].data.ptr);
//epoll_ctl(pThread->pollFd, EPOLL_CTL_DEL, events[i].data.fd, NULL); // epoll_ctl(pThread->pollFd, EPOLL_CTL_DEL, events[i].data.fd, NULL);
//taosClose(events[i].data.fd); // taosClose(events[i].data.fd);
continue; continue;
} }
@ -210,8 +212,8 @@ static void *httpAcceptHttpConnection(void *arg) {
pContext = httpCreateContext(connFd); pContext = httpCreateContext(connFd);
if (pContext == NULL) { if (pContext == NULL) {
httpError("fd:%d, ip:%s:%u, no enough resource to allocate http context", connFd, taosInetNtoa(clientAddr.sin_addr), httpError("fd:%d, ip:%s:%u, no enough resource to allocate http context", connFd,
htons(clientAddr.sin_port)); taosInetNtoa(clientAddr.sin_addr), htons(clientAddr.sin_port));
taosCloseSocket(connFd); taosCloseSocket(connFd);
continue; continue;
} }

View File

@ -35,7 +35,8 @@ void httpCreateSession(HttpContext *pContext, void *taos) {
session.refCount = 1; session.refCount = 1;
int32_t len = snprintf(session.id, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass); int32_t len = snprintf(session.id, HTTP_SESSION_ID_LEN, "%s.%s", pContext->user, pContext->pass);
pContext->session = taosCachePut(server->sessionCache, session.id, len, &session, sizeof(HttpSession), tsHttpSessionExpire * 1000); pContext->session =
taosCachePut(server->sessionCache, session.id, len, &session, sizeof(HttpSession), tsHttpSessionExpire * 1000);
// void *temp = pContext->session; // void *temp = pContext->session;
// taosCacheRelease(server->sessionCache, (void **)&temp, false); // taosCacheRelease(server->sessionCache, (void **)&temp, false);

View File

@ -82,7 +82,7 @@ void httpProcessMultiSqlCallBackImp(void *param, TAOS_RES *result, int32_t code,
HttpContext *pContext = (HttpContext *)param; HttpContext *pContext = (HttpContext *)param;
if (pContext == NULL) return; if (pContext == NULL) return;
HttpSqlCmds *multiCmds = pContext->multiCmds; HttpSqlCmds * multiCmds = pContext->multiCmds;
HttpEncodeMethod *encode = pContext->encodeMethod; HttpEncodeMethod *encode = pContext->encodeMethod;
HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos; HttpSqlCmd *singleCmd = multiCmds->cmds + multiCmds->pos;
@ -269,8 +269,8 @@ void httpProcessSingleSqlCallBackImp(void *param, TAOS_RES *result, int32_t code
pContext->user, tstrerror(code), pObj, taos_errstr(pObj)); pContext->user, tstrerror(code), pObj, taos_errstr(pObj));
httpSendTaosdInvalidSqlErrorResp(pContext, taos_errstr(pObj)); httpSendTaosdInvalidSqlErrorResp(pContext, taos_errstr(pObj));
} else { } else {
httpError("context:%p, fd:%d, user:%s, query error, code:%s, sqlObj:%p", pContext, pContext->fd, httpError("context:%p, fd:%d, user:%s, query error, code:%s, sqlObj:%p", pContext, pContext->fd, pContext->user,
pContext->user, tstrerror(code), pObj); tstrerror(code), pObj);
httpSendErrorResp(pContext, code); httpSendErrorResp(pContext, code);
} }
taos_free_result(result); taos_free_result(result);

View File

@ -114,6 +114,4 @@ void httpCleanUpSystem() {
tsHttpServer.status = HTTP_SERVER_CLOSED; tsHttpServer.status = HTTP_SERVER_CLOSED;
} }
int32_t httpGetReqCount() { int32_t httpGetReqCount() { return atomic_exchange_32(&tsHttpServer.requestNum, 0); }
return atomic_exchange_32(&tsHttpServer.requestNum, 0);
}

View File

@ -227,14 +227,14 @@ ParseEnd:
} }
} }
int32_t tgParseSchema(const char *content, char*fileName) { int32_t tgParseSchema(const char *content, char *fileName) {
cJSON *root = cJSON_Parse(content); cJSON *root = cJSON_Parse(content);
if (root == NULL) { if (root == NULL) {
httpError("failed to parse telegraf schema file:%s, invalid json format, content:%s", fileName, content); httpError("failed to parse telegraf schema file:%s, invalid json format, content:%s", fileName, content);
return -1; return -1;
} }
int32_t size = 0; int32_t size = 0;
cJSON *metrics = cJSON_GetObjectItem(root, "metrics"); cJSON * metrics = cJSON_GetObjectItem(root, "metrics");
if (metrics != NULL) { if (metrics != NULL) {
size = cJSON_GetArraySize(metrics); size = cJSON_GetArraySize(metrics);
if (size <= 0) { if (size <= 0) {
@ -296,7 +296,7 @@ int32_t tgReadSchema(char *fileName) {
} }
void tgInitHandle(HttpServer *pServer) { void tgInitHandle(HttpServer *pServer) {
char fileName[TSDB_FILENAME_LEN*2] = {0}; char fileName[TSDB_FILENAME_LEN * 2] = {0};
sprintf(fileName, "%s/taos.telegraf.cfg", configDir); sprintf(fileName, "%s/taos.telegraf.cfg", configDir);
if (tgReadSchema(fileName) <= 0) { if (tgReadSchema(fileName) <= 0) {
tgFreeSchemas(); tgFreeSchemas();
@ -308,9 +308,7 @@ void tgInitHandle(HttpServer *pServer) {
httpAddMethod(pServer, &tgDecodeMethod); httpAddMethod(pServer, &tgDecodeMethod);
} }
void tgCleanupHandle() { void tgCleanupHandle() { tgFreeSchemas(); }
tgFreeSchemas();
}
bool tgGetUserFromUrl(HttpContext *pContext) { bool tgGetUserFromUrl(HttpContext *pContext) {
HttpParser *pParser = pContext->parser; HttpParser *pParser = pContext->parser;
@ -578,7 +576,7 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
table_cmd->cmdType = HTTP_CMD_TYPE_INSERT; table_cmd->cmdType = HTTP_CMD_TYPE_INSERT;
// order by tag name // order by tag name
cJSON *orderedTags[TG_MAX_SORT_TAG_SIZE] = {0}; cJSON * orderedTags[TG_MAX_SORT_TAG_SIZE] = {0};
int32_t orderTagsLen = 0; int32_t orderTagsLen = 0;
for (int32_t i = 0; i < tagsSize; ++i) { for (int32_t i = 0; i < tagsSize; ++i) {
cJSON *tag = cJSON_GetArrayItem(tags, i); cJSON *tag = cJSON_GetArrayItem(tags, i);
@ -603,7 +601,8 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
if (tsTelegrafUseFieldNum == 0) { if (tsTelegrafUseFieldNum == 0) {
table_cmd->stable = stable_cmd->stable = httpAddToSqlCmdBuffer(pContext, "%s", stname); table_cmd->stable = stable_cmd->stable = httpAddToSqlCmdBuffer(pContext, "%s", stname);
} else { } else {
table_cmd->stable = stable_cmd->stable = httpAddToSqlCmdBuffer(pContext, "%s_%d_%d", stname, fieldsSize, orderTagsLen); table_cmd->stable = stable_cmd->stable =
httpAddToSqlCmdBuffer(pContext, "%s_%d_%d", stname, fieldsSize, orderTagsLen);
} }
table_cmd->stable = stable_cmd->stable = table_cmd->stable = stable_cmd->stable =
httpShrinkTableName(pContext, table_cmd->stable, httpGetCmdsString(pContext, table_cmd->stable)); httpShrinkTableName(pContext, table_cmd->stable, httpGetCmdsString(pContext, table_cmd->stable));
@ -627,9 +626,11 @@ bool tgProcessSingleMetric(HttpContext *pContext, cJSON *metric, char *db) {
// table name // table name
if (tsTelegrafUseFieldNum == 0) { if (tsTelegrafUseFieldNum == 0) {
table_cmd->table = stable_cmd->table = httpAddToSqlCmdBufferNoTerminal(pContext, "%s_%s", stname, host->valuestring); table_cmd->table = stable_cmd->table =
httpAddToSqlCmdBufferNoTerminal(pContext, "%s_%s", stname, host->valuestring);
} else { } else {
table_cmd->table = stable_cmd->table = httpAddToSqlCmdBufferNoTerminal(pContext, "%s_%d_%d_%s", stname, fieldsSize, orderTagsLen, host->valuestring); table_cmd->table = stable_cmd->table =
httpAddToSqlCmdBufferNoTerminal(pContext, "%s_%d_%d_%s", stname, fieldsSize, orderTagsLen, host->valuestring);
} }
for (int32_t i = 0; i < orderTagsLen; ++i) { for (int32_t i = 0; i < orderTagsLen; ++i) {
cJSON *tag = orderedTags[i]; cJSON *tag = orderedTags[i];

View File

@ -160,8 +160,7 @@ bool httpMallocMultiCmds(HttpContext *pContext, int32_t cmdSize, int32_t bufferS
free(multiCmds->cmds); free(multiCmds->cmds);
multiCmds->cmds = (HttpSqlCmd *)malloc((size_t)cmdSize * sizeof(HttpSqlCmd)); multiCmds->cmds = (HttpSqlCmd *)malloc((size_t)cmdSize * sizeof(HttpSqlCmd));
if (multiCmds->cmds == NULL) { if (multiCmds->cmds == NULL) {
httpError("context:%p, fd:%d, user:%s, malloc cmds:%d error", pContext, pContext->fd, httpError("context:%p, fd:%d, user:%s, malloc cmds:%d error", pContext, pContext->fd, pContext->user, cmdSize);
pContext->user, cmdSize);
return false; return false;
} }
multiCmds->maxSize = (int16_t)cmdSize; multiCmds->maxSize = (int16_t)cmdSize;
@ -358,30 +357,32 @@ int32_t httpGzipDeCompress(char *srcData, int32_t nSrcData, char *destData, int3
(((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF, (((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
}; };
gzipStream.zalloc = (alloc_func) 0; gzipStream.zalloc = (alloc_func)0;
gzipStream.zfree = (free_func) 0; gzipStream.zfree = (free_func)0;
gzipStream.opaque = (voidpf) 0; gzipStream.opaque = (voidpf)0;
gzipStream.next_in = (Bytef *) srcData; gzipStream.next_in = (Bytef *)srcData;
gzipStream.avail_in = 0; gzipStream.avail_in = 0;
gzipStream.next_out = (Bytef *) destData; gzipStream.next_out = (Bytef *)destData;
if (inflateInit2(&gzipStream, 47) != Z_OK) { if (inflateInit2(&gzipStream, 47) != Z_OK) {
return -1; return -1;
} }
while (gzipStream.total_out < *nDestData && gzipStream.total_in < nSrcData) { while (gzipStream.total_out < *nDestData && gzipStream.total_in < nSrcData) {
gzipStream.avail_in = gzipStream.avail_out = nSrcData; //1 gzipStream.avail_in = gzipStream.avail_out = nSrcData; // 1
if ((err = inflate(&gzipStream, Z_NO_FLUSH)) == Z_STREAM_END) { if ((err = inflate(&gzipStream, Z_NO_FLUSH)) == Z_STREAM_END) {
break; break;
} }
if (err != Z_OK) { if (err != Z_OK) {
if (err == Z_DATA_ERROR) { if (err == Z_DATA_ERROR) {
gzipStream.next_in = (Bytef *) dummyHead; gzipStream.next_in = (Bytef *)dummyHead;
gzipStream.avail_in = sizeof(dummyHead); gzipStream.avail_in = sizeof(dummyHead);
if ((err = inflate(&gzipStream, Z_NO_FLUSH)) != Z_OK) { if ((err = inflate(&gzipStream, Z_NO_FLUSH)) != Z_OK) {
return -2; return -2;
} }
} else return -3; } else {
return -3;
}
} }
} }
@ -394,23 +395,25 @@ int32_t httpGzipDeCompress(char *srcData, int32_t nSrcData, char *destData, int3
} }
int32_t httpGzipCompressInit(HttpContext *pContext) { int32_t httpGzipCompressInit(HttpContext *pContext) {
pContext->gzipStream.zalloc = (alloc_func) 0; pContext->gzipStream.zalloc = (alloc_func)0;
pContext->gzipStream.zfree = (free_func) 0; pContext->gzipStream.zfree = (free_func)0;
pContext->gzipStream.opaque = (voidpf) 0; pContext->gzipStream.opaque = (voidpf)0;
if (deflateInit2(&pContext->gzipStream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK) { if (deflateInit2(&pContext->gzipStream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) !=
Z_OK) {
return -1; return -1;
} }
return 0; return 0;
} }
int32_t httpGzipCompress(HttpContext *pContext, char *srcData, int32_t nSrcData, char *destData, int32_t *nDestData, bool isTheLast) { int32_t httpGzipCompress(HttpContext *pContext, char *srcData, int32_t nSrcData, char *destData, int32_t *nDestData,
bool isTheLast) {
int32_t err = 0; int32_t err = 0;
int32_t lastTotalLen = (int32_t) (pContext->gzipStream.total_out); int32_t lastTotalLen = (int32_t)(pContext->gzipStream.total_out);
pContext->gzipStream.next_in = (Bytef *) srcData; pContext->gzipStream.next_in = (Bytef *)srcData;
pContext->gzipStream.avail_in = (uLong) nSrcData; pContext->gzipStream.avail_in = (uLong)nSrcData;
pContext->gzipStream.next_out = (Bytef *) destData; pContext->gzipStream.next_out = (Bytef *)destData;
pContext->gzipStream.avail_out = (uLong) (*nDestData); pContext->gzipStream.avail_out = (uLong)(*nDestData);
while (pContext->gzipStream.avail_in != 0) { while (pContext->gzipStream.avail_in != 0) {
if (deflate(&pContext->gzipStream, Z_FULL_FLUSH) != Z_OK) { if (deflate(&pContext->gzipStream, Z_FULL_FLUSH) != Z_OK) {
@ -442,12 +445,12 @@ int32_t httpGzipCompress(HttpContext *pContext, char *srcData, int32_t nSrcData,
} }
} }
*nDestData = (int32_t) (pContext->gzipStream.total_out) - lastTotalLen; *nDestData = (int32_t)(pContext->gzipStream.total_out) - lastTotalLen;
return 0; return 0;
} }
bool httpUrlMatch(HttpContext* pContext, int32_t pos, char* cmp) { bool httpUrlMatch(HttpContext *pContext, int32_t pos, char *cmp) {
HttpParser* pParser = pContext->parser; HttpParser *pParser = pContext->parser;
if (pos < 0 || pos >= HTTP_MAX_URL) { if (pos < 0 || pos >= HTTP_MAX_URL) {
return false; return false;

View File

@ -1,12 +1,10 @@
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
sleep 2000
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0 system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/cfg.sh -n dnode1 -c http -v 1 system sh/cfg.sh -n dnode1 -c http -v 1
system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1 system sh/cfg.sh -n dnode1 -c httpEnableRecordSql -v 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect sql connect
print ============================ dnode1 start print ============================ dnode1 start