|
|
f656cf |
From 6267b5a57c432a3be68f362c571beb062d47b3a7 Mon Sep 17 00:00:00 2001
|
|
|
f656cf |
From: PascalWithopf <pwithopf@adiscon.com>
|
|
|
f656cf |
Date: Tue, 23 May 2017 15:32:34 +0200
|
|
|
f656cf |
Subject: [PATCH 10/11] omelasticsearch: replace cJSON with libfastjson
|
|
|
f656cf |
|
|
|
f656cf |
(cherry picked from commit 7982f50675471220c5ba035371a8f7537a50442b)
|
|
|
f656cf |
(cherry picked from commit 0b09c29db0cec5a215a95d03cfc37a27e486811c)
|
|
|
f656cf |
---
|
|
|
f656cf |
plugins/omelasticsearch/Makefile.am | 3 +-
|
|
|
f656cf |
plugins/omelasticsearch/cJSON/cjson.c | 525 ------------------------------
|
|
|
f656cf |
plugins/omelasticsearch/cJSON/cjson.h | 130 --------
|
|
|
f656cf |
plugins/omelasticsearch/omelasticsearch.c | 171 +++++-----
|
|
|
f656cf |
12 files changed, 84 insertions(+), 1323 deletions(-)
|
|
|
f656cf |
delete mode 100644 plugins/omelasticsearch/cJSON/cjson.c
|
|
|
f656cf |
delete mode 100644 plugins/omelasticsearch/cJSON/cjson.h
|
|
|
f656cf |
|
|
|
f656cf |
diff --git a/plugins/omelasticsearch/Makefile.am b/plugins/omelasticsearch/Makefile.am
|
|
|
f656cf |
index ba85a896d..2fadb74dc 100644
|
|
|
f656cf |
--- a/plugins/omelasticsearch/Makefile.am
|
|
|
f656cf |
+++ b/plugins/omelasticsearch/Makefile.am
|
|
|
f656cf |
@@ -1,7 +1,6 @@
|
|
|
f656cf |
pkglib_LTLIBRARIES = omelasticsearch.la
|
|
|
f656cf |
|
|
|
f656cf |
-# TODO: replace cJSON
|
|
|
f656cf |
-omelasticsearch_la_SOURCES = omelasticsearch.c cJSON/cjson.c cJSON/cjson.h
|
|
|
f656cf |
+omelasticsearch_la_SOURCES = omelasticsearch.c
|
|
|
f656cf |
omelasticsearch_la_CPPFLAGS = $(RSRT_CFLAGS) $(PTHREADS_CFLAGS)
|
|
|
f656cf |
omelasticsearch_la_LDFLAGS = -module -avoid-version
|
|
|
f656cf |
omelasticsearch_la_LIBADD = $(CURL_LIBS) $(LIBM)
|
|
|
f656cf |
diff --git a/plugins/omelasticsearch/cJSON/cjson.c b/plugins/omelasticsearch/cJSON/cjson.c
|
|
|
f656cf |
deleted file mode 100644
|
|
|
f656cf |
index 6f7d43a23..000000000
|
|
|
f656cf |
--- a/plugins/omelasticsearch/cJSON/cjson.c
|
|
|
f656cf |
+++ /dev/null
|
|
|
f656cf |
@@ -1,525 +0,0 @@
|
|
|
f656cf |
-/*
|
|
|
f656cf |
- Copyright (c) 2009 Dave Gamble
|
|
|
f656cf |
-
|
|
|
f656cf |
- Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
f656cf |
- of this software and associated documentation files (the "Software"), to deal
|
|
|
f656cf |
- in the Software without restriction, including without limitation the rights
|
|
|
f656cf |
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
f656cf |
- copies of the Software, and to permit persons to whom the Software is
|
|
|
f656cf |
- furnished to do so, subject to the following conditions:
|
|
|
f656cf |
-
|
|
|
f656cf |
- The above copyright notice and this permission notice shall be included in
|
|
|
f656cf |
- all copies or substantial portions of the Software.
|
|
|
f656cf |
-
|
|
|
f656cf |
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
f656cf |
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
f656cf |
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
f656cf |
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
f656cf |
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
f656cf |
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
f656cf |
- THE SOFTWARE.
|
|
|
f656cf |
-*/
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* this code has several warnings, but we ignore them because
|
|
|
f656cf |
- * this seems to work and we do not want to engage in that code body. If
|
|
|
f656cf |
- * we really run into troubles, it is better to change to libfastjson, which
|
|
|
f656cf |
- * we should do in the medium to long term anyhow...
|
|
|
f656cf |
- */
|
|
|
f656cf |
-#pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
|
|
f656cf |
-#pragma GCC diagnostic ignored "-Wredundant-decls"
|
|
|
f656cf |
-#pragma GCC diagnostic ignored "-Wstrict-prototypes"
|
|
|
f656cf |
-#pragma GCC diagnostic ignored "-Wswitch-default"
|
|
|
f656cf |
-#pragma GCC diagnostic ignored "-Wold-style-definition"
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* cJSON */
|
|
|
f656cf |
-/* JSON parser in C. */
|
|
|
f656cf |
-
|
|
|
f656cf |
-#include <string.h>
|
|
|
f656cf |
-#include <stdio.h>
|
|
|
f656cf |
-#include <math.h>
|
|
|
f656cf |
-#include <stdlib.h>
|
|
|
f656cf |
-#include <float.h>
|
|
|
f656cf |
-#include <limits.h>
|
|
|
f656cf |
-#include <ctype.h>
|
|
|
f656cf |
-#include "cjson.h"
|
|
|
f656cf |
-
|
|
|
f656cf |
-static const char *ep;
|
|
|
f656cf |
-
|
|
|
f656cf |
-const char *cJSON_GetErrorPtr() {return ep;}
|
|
|
f656cf |
-
|
|
|
f656cf |
-static int cJSON_strcasecmp(const char *s1,const char *s2)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
|
|
|
f656cf |
- for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
|
|
|
f656cf |
- return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-static void *(*cJSON_malloc)(size_t sz) = malloc;
|
|
|
f656cf |
-static void (*cJSON_free)(void *ptr) = free;
|
|
|
f656cf |
-
|
|
|
f656cf |
-static char* cJSON_strdup(const char* str)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- size_t len;
|
|
|
f656cf |
- char* copy;
|
|
|
f656cf |
-
|
|
|
f656cf |
- len = strlen(str) + 1;
|
|
|
f656cf |
- if (!(copy = (char*)cJSON_malloc(len))) return 0;
|
|
|
f656cf |
- memcpy(copy,str,len);
|
|
|
f656cf |
- return copy;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-void cJSON_InitHooks(cJSON_Hooks* hooks)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- if (!hooks) { /* Reset hooks */
|
|
|
f656cf |
- cJSON_malloc = malloc;
|
|
|
f656cf |
- cJSON_free = free;
|
|
|
f656cf |
- return;
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
|
|
|
f656cf |
- cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Internal constructor. */
|
|
|
f656cf |
-static cJSON *cJSON_New_Item()
|
|
|
f656cf |
-{
|
|
|
f656cf |
- cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
|
|
|
f656cf |
- if (node) memset(node,0,sizeof(cJSON));
|
|
|
f656cf |
- return node;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Delete a cJSON structure. */
|
|
|
f656cf |
-void cJSON_Delete(cJSON *c)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- cJSON *next;
|
|
|
f656cf |
- while (c)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- next=c->next;
|
|
|
f656cf |
- if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
|
|
|
f656cf |
- if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
|
|
|
f656cf |
- if (c->string) cJSON_free(c->string);
|
|
|
f656cf |
- cJSON_free(c);
|
|
|
f656cf |
- c=next;
|
|
|
f656cf |
- }
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Parse the input text to generate a number, and populate the result into item. */
|
|
|
f656cf |
-static const char *parse_number(cJSON *item,const char *num)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* Could use sscanf for this? */
|
|
|
f656cf |
- if (*num=='-') sign=-1,num++; /* Has sign? */
|
|
|
f656cf |
- if (*num=='0') num++; /* is zero */
|
|
|
f656cf |
- if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
|
|
|
f656cf |
- if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
|
|
|
f656cf |
- if (*num=='e' || *num=='E') /* Exponent? */
|
|
|
f656cf |
- { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
|
|
|
f656cf |
- while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
|
|
|
f656cf |
-
|
|
|
f656cf |
- item->valuedouble=n;
|
|
|
f656cf |
- item->valueint=(int)n;
|
|
|
f656cf |
- item->type=cJSON_Number;
|
|
|
f656cf |
- return num;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Render the number nicely from the given item into a string. */
|
|
|
f656cf |
-char *cJSON_print_number(cJSON *item)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- char *str;
|
|
|
f656cf |
- double d=item->valuedouble;
|
|
|
f656cf |
- if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
|
|
|
f656cf |
- if (str) sprintf(str,"%d",item->valueint);
|
|
|
f656cf |
- }
|
|
|
f656cf |
- else
|
|
|
f656cf |
- {
|
|
|
f656cf |
- str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
|
|
|
f656cf |
- if (str)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
|
|
|
f656cf |
- else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
|
|
|
f656cf |
- else sprintf(str,"%f",d);
|
|
|
f656cf |
- }
|
|
|
f656cf |
- }
|
|
|
f656cf |
- return str;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Parse the input text into an unescaped cstring, and populate item. */
|
|
|
f656cf |
-static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
|
|
|
f656cf |
-static const char *parse_string(cJSON *item,const char *str)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc,uc2;
|
|
|
f656cf |
- if (*str!='\"') {ep=str;return 0;} /* not a string! */
|
|
|
f656cf |
-
|
|
|
f656cf |
- while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
|
|
|
f656cf |
-
|
|
|
f656cf |
- out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
|
|
|
f656cf |
- if (!out) return 0;
|
|
|
f656cf |
-
|
|
|
f656cf |
- ptr=str+1;ptr2=out;
|
|
|
f656cf |
- while (*ptr!='\"' && *ptr)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- if (*ptr!='\\') *ptr2++=*ptr++;
|
|
|
f656cf |
- else
|
|
|
f656cf |
- {
|
|
|
f656cf |
- ptr++;
|
|
|
f656cf |
- switch (*ptr)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- case 'b': *ptr2++='\b'; break;
|
|
|
f656cf |
- case 'f': *ptr2++='\f'; break;
|
|
|
f656cf |
- case 'n': *ptr2++='\n'; break;
|
|
|
f656cf |
- case 'r': *ptr2++='\r'; break;
|
|
|
f656cf |
- case 't': *ptr2++='\t'; break;
|
|
|
f656cf |
- case 'u': /* transcode utf16 to utf8. */
|
|
|
f656cf |
- sscanf(ptr+1,"%4x",&uc);ptr+=4; /* get the unicode char. */
|
|
|
f656cf |
-
|
|
|
f656cf |
- if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid.
|
|
|
f656cf |
-
|
|
|
f656cf |
- if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs.
|
|
|
f656cf |
- {
|
|
|
f656cf |
- if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate.
|
|
|
f656cf |
- sscanf(ptr+3,"%4x",&uc2;;ptr+=6;
|
|
|
f656cf |
- if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate.
|
|
|
f656cf |
- uc=0x10000 | ((uc&0x3FF)<<10) | (uc2&0x3FF);
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len;
|
|
|
f656cf |
-
|
|
|
f656cf |
- switch (len) {
|
|
|
f656cf |
- case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
|
|
|
f656cf |
- case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
|
|
|
f656cf |
- case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
|
|
|
f656cf |
- case 1: *--ptr2 =(uc | firstByteMark[len]);
|
|
|
f656cf |
- }
|
|
|
f656cf |
- ptr2+=len;
|
|
|
f656cf |
- break;
|
|
|
f656cf |
- default: *ptr2++=*ptr; break;
|
|
|
f656cf |
- }
|
|
|
f656cf |
- ptr++;
|
|
|
f656cf |
- }
|
|
|
f656cf |
- }
|
|
|
f656cf |
- *ptr2=0;
|
|
|
f656cf |
- if (*ptr=='\"') ptr++;
|
|
|
f656cf |
- item->valuestring=out;
|
|
|
f656cf |
- item->type=cJSON_String;
|
|
|
f656cf |
- return ptr;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Render the cstring provided to an escaped version that can be printed. */
|
|
|
f656cf |
-static char *print_string_ptr(const char *str)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
|
|
|
f656cf |
-
|
|
|
f656cf |
- if (!str) return cJSON_strdup("");
|
|
|
f656cf |
- ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
|
|
|
f656cf |
-
|
|
|
f656cf |
- out=(char*)cJSON_malloc(len+3);
|
|
|
f656cf |
- if (!out) return 0;
|
|
|
f656cf |
-
|
|
|
f656cf |
- ptr2=out;ptr=str;
|
|
|
f656cf |
- *ptr2++='\"';
|
|
|
f656cf |
- while (*ptr)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
|
|
|
f656cf |
- else
|
|
|
f656cf |
- {
|
|
|
f656cf |
- *ptr2++='\\';
|
|
|
f656cf |
- switch (token=*ptr++)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- case '\\': *ptr2++='\\'; break;
|
|
|
f656cf |
- case '\"': *ptr2++='\"'; break;
|
|
|
f656cf |
- case '\b': *ptr2++='b'; break;
|
|
|
f656cf |
- case '\f': *ptr2++='f'; break;
|
|
|
f656cf |
- case '\n': *ptr2++='n'; break;
|
|
|
f656cf |
- case '\r': *ptr2++='r'; break;
|
|
|
f656cf |
- case '\t': *ptr2++='t'; break;
|
|
|
f656cf |
- default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */
|
|
|
f656cf |
- }
|
|
|
f656cf |
- }
|
|
|
f656cf |
- }
|
|
|
f656cf |
- *ptr2++='\"';*ptr2++=0;
|
|
|
f656cf |
- return out;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-/* Invote print_string_ptr (which is useful) on an item. */
|
|
|
f656cf |
-static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Predeclare these prototypes. */
|
|
|
f656cf |
-static const char *parse_value(cJSON *item,const char *value);
|
|
|
f656cf |
-static char *print_value(cJSON *item,int depth,int fmt);
|
|
|
f656cf |
-static const char *parse_array(cJSON *item,const char *value);
|
|
|
f656cf |
-static char *print_array(cJSON *item,int depth,int fmt);
|
|
|
f656cf |
-static const char *parse_object(cJSON *item,const char *value);
|
|
|
f656cf |
-static char *print_object(cJSON *item,int depth,int fmt);
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Utility to jump whitespace and cr/lf */
|
|
|
f656cf |
-static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Parse an object - create a new root, and populate. */
|
|
|
f656cf |
-cJSON *cJSON_Parse(const char *value)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- cJSON *c=cJSON_New_Item();
|
|
|
f656cf |
- ep=0;
|
|
|
f656cf |
- if (!c) return 0; /* memory fail */
|
|
|
f656cf |
-
|
|
|
f656cf |
- if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
|
|
|
f656cf |
- return c;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Render a cJSON item/entity/structure to text. */
|
|
|
f656cf |
-char *cJSON_Print(cJSON *item) {return print_value(item,0,1);}
|
|
|
f656cf |
-char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Parser core - when encountering text, process appropriately. */
|
|
|
f656cf |
-static const char *parse_value(cJSON *item,const char *value)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- if (!value) return 0; /* Fail on null. */
|
|
|
f656cf |
- if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; }
|
|
|
f656cf |
- if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; }
|
|
|
f656cf |
- if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; }
|
|
|
f656cf |
- if (*value=='\"') { return parse_string(item,value); }
|
|
|
f656cf |
- if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); }
|
|
|
f656cf |
- if (*value=='[') { return parse_array(item,value); }
|
|
|
f656cf |
- if (*value=='{') { return parse_object(item,value); }
|
|
|
f656cf |
-
|
|
|
f656cf |
- ep=value;return 0; /* failure. */
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Render a value to text. */
|
|
|
f656cf |
-static char *print_value(cJSON *item,int depth,int fmt)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- char *out=0;
|
|
|
f656cf |
- if (!item) return 0;
|
|
|
f656cf |
- switch ((item->type)&255)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- case cJSON_NULL: out=cJSON_strdup("null"); break;
|
|
|
f656cf |
- case cJSON_False: out=cJSON_strdup("false");break;
|
|
|
f656cf |
- case cJSON_True: out=cJSON_strdup("true"); break;
|
|
|
f656cf |
- case cJSON_Number: out=cJSON_print_number(item);break;
|
|
|
f656cf |
- case cJSON_String: out=print_string(item);break;
|
|
|
f656cf |
- case cJSON_Array: out=print_array(item,depth,fmt);break;
|
|
|
f656cf |
- case cJSON_Object: out=print_object(item,depth,fmt);break;
|
|
|
f656cf |
- }
|
|
|
f656cf |
- return out;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Build an array from input text. */
|
|
|
f656cf |
-static const char *parse_array(cJSON *item,const char *value)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- cJSON *child;
|
|
|
f656cf |
- if (*value!='[') {ep=value;return 0;} /* not an array! */
|
|
|
f656cf |
-
|
|
|
f656cf |
- item->type=cJSON_Array;
|
|
|
f656cf |
- value=skip(value+1);
|
|
|
f656cf |
- if (*value==']') return value+1; /* empty array. */
|
|
|
f656cf |
-
|
|
|
f656cf |
- item->child=child=cJSON_New_Item();
|
|
|
f656cf |
- if (!item->child) return 0; /* memory fail */
|
|
|
f656cf |
- value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
|
|
|
f656cf |
- if (!value) return 0;
|
|
|
f656cf |
-
|
|
|
f656cf |
- while (*value==',')
|
|
|
f656cf |
- {
|
|
|
f656cf |
- cJSON *new_item;
|
|
|
f656cf |
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
|
|
|
f656cf |
- child->next=new_item;new_item->prev=child;child=new_item;
|
|
|
f656cf |
- value=skip(parse_value(child,skip(value+1)));
|
|
|
f656cf |
- if (!value) return 0; /* memory fail */
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- if (*value==']') return value+1; /* end of array */
|
|
|
f656cf |
- ep=value;return 0; /* malformed. */
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Render an array to text */
|
|
|
f656cf |
-static char *print_array(cJSON *item,int depth,int fmt)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- char **entries;
|
|
|
f656cf |
- char *out=0,*ptr,*ret;int len=5;
|
|
|
f656cf |
- cJSON *child=item->child;
|
|
|
f656cf |
- int numentries=0,i=0,fail=0;
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* How many entries in the array? */
|
|
|
f656cf |
- while (child) numentries++,child=child->next;
|
|
|
f656cf |
- /* Allocate an array to hold the values for each */
|
|
|
f656cf |
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
|
|
|
f656cf |
- if (!entries) return 0;
|
|
|
f656cf |
- memset(entries,0,numentries*sizeof(char*));
|
|
|
f656cf |
- /* Retrieve all the results: */
|
|
|
f656cf |
- child=item->child;
|
|
|
f656cf |
- while (child && !fail)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- ret=print_value(child,depth+1,fmt);
|
|
|
f656cf |
- entries[i++]=ret;
|
|
|
f656cf |
- if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1;
|
|
|
f656cf |
- child=child->next;
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* If we didn't fail, try to malloc the output string */
|
|
|
f656cf |
- if (!fail) out=(char*)cJSON_malloc(len);
|
|
|
f656cf |
- /* If that fails, we fail. */
|
|
|
f656cf |
- if (!out) fail=1;
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* Handle failure. */
|
|
|
f656cf |
- if (fail)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- for (i=0;i
|
|
|
f656cf |
- cJSON_free(entries);
|
|
|
f656cf |
- return 0;
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* Compose the output array. */
|
|
|
f656cf |
- *out='[';
|
|
|
f656cf |
- ptr=out+1;*ptr=0;
|
|
|
f656cf |
- for (i=0;i
|
|
|
f656cf |
- {
|
|
|
f656cf |
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
|
|
|
f656cf |
- if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
|
|
|
f656cf |
- cJSON_free(entries[i]);
|
|
|
f656cf |
- }
|
|
|
f656cf |
- cJSON_free(entries);
|
|
|
f656cf |
- *ptr++=']';*ptr++=0;
|
|
|
f656cf |
- return out;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Build an object from the text. */
|
|
|
f656cf |
-static const char *parse_object(cJSON *item,const char *value)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- cJSON *child;
|
|
|
f656cf |
- if (*value!='{') {ep=value;return 0;} /* not an object! */
|
|
|
f656cf |
-
|
|
|
f656cf |
- item->type=cJSON_Object;
|
|
|
f656cf |
- value=skip(value+1);
|
|
|
f656cf |
- if (*value=='}') return value+1; /* empty array. */
|
|
|
f656cf |
-
|
|
|
f656cf |
- item->child=child=cJSON_New_Item();
|
|
|
f656cf |
- if (!item->child) return 0;
|
|
|
f656cf |
- value=skip(parse_string(child,skip(value)));
|
|
|
f656cf |
- if (!value) return 0;
|
|
|
f656cf |
- child->string=child->valuestring;child->valuestring=0;
|
|
|
f656cf |
- if (*value!=':') {ep=value;return 0;} /* fail! */
|
|
|
f656cf |
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
|
|
|
f656cf |
- if (!value) return 0;
|
|
|
f656cf |
-
|
|
|
f656cf |
- while (*value==',')
|
|
|
f656cf |
- {
|
|
|
f656cf |
- cJSON *new_item;
|
|
|
f656cf |
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
|
|
|
f656cf |
- child->next=new_item;new_item->prev=child;child=new_item;
|
|
|
f656cf |
- value=skip(parse_string(child,skip(value+1)));
|
|
|
f656cf |
- if (!value) return 0;
|
|
|
f656cf |
- child->string=child->valuestring;child->valuestring=0;
|
|
|
f656cf |
- if (*value!=':') {ep=value;return 0;} /* fail! */
|
|
|
f656cf |
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
|
|
|
f656cf |
- if (!value) return 0;
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- if (*value=='}') return value+1; /* end of array */
|
|
|
f656cf |
- ep=value;return 0; /* malformed. */
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Render an object to text. */
|
|
|
f656cf |
-static char *print_object(cJSON *item,int depth,int fmt)
|
|
|
f656cf |
-{
|
|
|
f656cf |
- char **entries=0,**names=0;
|
|
|
f656cf |
- char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
|
|
|
f656cf |
- cJSON *child=item->child;
|
|
|
f656cf |
- int numentries=0,fail=0;
|
|
|
f656cf |
- /* Count the number of entries. */
|
|
|
f656cf |
- while (child) numentries++,child=child->next;
|
|
|
f656cf |
- /* Allocate space for the names and the objects */
|
|
|
f656cf |
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
|
|
|
f656cf |
- if (!entries) return 0;
|
|
|
f656cf |
- names=(char**)cJSON_malloc(numentries*sizeof(char*));
|
|
|
f656cf |
- if (!names) {cJSON_free(entries);return 0;}
|
|
|
f656cf |
- memset(entries,0,sizeof(char*)*numentries);
|
|
|
f656cf |
- memset(names,0,sizeof(char*)*numentries);
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* Collect all the results into our arrays: */
|
|
|
f656cf |
- child=item->child;depth++;if (fmt) len+=depth;
|
|
|
f656cf |
- while (child)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- names[i]=str=print_string_ptr(child->string);
|
|
|
f656cf |
- entries[i++]=ret=print_value(child,depth,fmt);
|
|
|
f656cf |
- if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1;
|
|
|
f656cf |
- child=child->next;
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* Try to allocate the output string */
|
|
|
f656cf |
- if (!fail) out=(char*)cJSON_malloc(len);
|
|
|
f656cf |
- if (!out) fail=1;
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* Handle failure */
|
|
|
f656cf |
- if (fail)
|
|
|
f656cf |
- {
|
|
|
f656cf |
- for (i=0;i
|
|
|
f656cf |
- cJSON_free(names);cJSON_free(entries);
|
|
|
f656cf |
- return 0;
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- /* Compose the output: */
|
|
|
f656cf |
- *out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
|
|
|
f656cf |
- for (i=0;i
|
|
|
f656cf |
- {
|
|
|
f656cf |
- if (fmt) for (j=0;j
|
|
|
f656cf |
- strcpy(ptr,names[i]);ptr+=strlen(names[i]);
|
|
|
f656cf |
- *ptr++=':';if (fmt) *ptr++='\t';
|
|
|
f656cf |
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
|
|
|
f656cf |
- if (i!=numentries-1) *ptr++=',';
|
|
|
f656cf |
- if (fmt) *ptr++='\n';*ptr=0;
|
|
|
f656cf |
- cJSON_free(names[i]);cJSON_free(entries[i]);
|
|
|
f656cf |
- }
|
|
|
f656cf |
-
|
|
|
f656cf |
- cJSON_free(names);cJSON_free(entries);
|
|
|
f656cf |
- if (fmt) for (i=0;i
|
|
|
f656cf |
- *ptr++='}';*ptr++=0;
|
|
|
f656cf |
- return out;
|
|
|
f656cf |
-}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Get Array size/item / object item. */
|
|
|
f656cf |
-int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
|
|
|
f656cf |
-cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
|
|
|
f656cf |
-cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Utility for array list handling. */
|
|
|
f656cf |
-static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
|
|
|
f656cf |
-/* Utility for handling references. */
|
|
|
f656cf |
-static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Add item to array/object. */
|
|
|
f656cf |
-void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
|
|
|
f656cf |
-void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
|
|
|
f656cf |
-void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
|
|
|
f656cf |
-void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
|
|
|
f656cf |
-
|
|
|
f656cf |
-cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
|
|
|
f656cf |
- if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
|
|
|
f656cf |
-void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
|
|
|
f656cf |
-cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
|
|
|
f656cf |
-void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Replace array/object items with new ones. */
|
|
|
f656cf |
-void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
|
|
|
f656cf |
- newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
|
|
|
f656cf |
- if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
|
|
|
f656cf |
-void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Create basic types: */
|
|
|
f656cf |
-cJSON *cJSON_CreateNull() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
|
|
|
f656cf |
-cJSON *cJSON_CreateTrue() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
|
|
|
f656cf |
-cJSON *cJSON_CreateFalse() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
|
|
|
f656cf |
-cJSON *cJSON_CreateBool(int b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
|
|
|
f656cf |
-cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;}return item;}
|
|
|
f656cf |
-cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
|
|
|
f656cf |
-cJSON *cJSON_CreateArray() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
|
|
|
f656cf |
-cJSON *cJSON_CreateObject() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Create Arrays: */
|
|
|
f656cf |
-cJSON *cJSON_CreateIntArray(int *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
|
|
f656cf |
-cJSON *cJSON_CreateFloatArray(float *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
|
|
f656cf |
-cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
|
|
f656cf |
-cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateString(strings[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
|
|
|
f656cf |
diff --git a/plugins/omelasticsearch/cJSON/cjson.h b/plugins/omelasticsearch/cJSON/cjson.h
|
|
|
f656cf |
deleted file mode 100644
|
|
|
f656cf |
index a621720ce..000000000
|
|
|
f656cf |
--- a/plugins/omelasticsearch/cJSON/cjson.h
|
|
|
f656cf |
+++ /dev/null
|
|
|
f656cf |
@@ -1,130 +0,0 @@
|
|
|
f656cf |
-/*
|
|
|
f656cf |
- Copyright (c) 2009 Dave Gamble
|
|
|
f656cf |
-
|
|
|
f656cf |
- Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
f656cf |
- of this software and associated documentation files (the "Software"), to deal
|
|
|
f656cf |
- in the Software without restriction, including without limitation the rights
|
|
|
f656cf |
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
f656cf |
- copies of the Software, and to permit persons to whom the Software is
|
|
|
f656cf |
- furnished to do so, subject to the following conditions:
|
|
|
f656cf |
-
|
|
|
f656cf |
- The above copyright notice and this permission notice shall be included in
|
|
|
f656cf |
- all copies or substantial portions of the Software.
|
|
|
f656cf |
-
|
|
|
f656cf |
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
f656cf |
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
f656cf |
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
f656cf |
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
f656cf |
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
f656cf |
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
f656cf |
- THE SOFTWARE.
|
|
|
f656cf |
-*/
|
|
|
f656cf |
-
|
|
|
f656cf |
-#ifndef cJSON__h
|
|
|
f656cf |
-#define cJSON__h
|
|
|
f656cf |
-
|
|
|
f656cf |
-#ifdef __cplusplus
|
|
|
f656cf |
-extern "C"
|
|
|
f656cf |
-{
|
|
|
f656cf |
-#endif
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* cJSON Types: */
|
|
|
f656cf |
-#define cJSON_False 0
|
|
|
f656cf |
-#define cJSON_True 1
|
|
|
f656cf |
-#define cJSON_NULL 2
|
|
|
f656cf |
-#define cJSON_Number 3
|
|
|
f656cf |
-#define cJSON_String 4
|
|
|
f656cf |
-#define cJSON_Array 5
|
|
|
f656cf |
-#define cJSON_Object 6
|
|
|
f656cf |
-
|
|
|
f656cf |
-#define cJSON_IsReference 256
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* The cJSON structure: */
|
|
|
f656cf |
-typedef struct cJSON {
|
|
|
f656cf |
- struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
|
|
f656cf |
- struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
|
|
f656cf |
-
|
|
|
f656cf |
- int type; /* The type of the item, as above. */
|
|
|
f656cf |
-
|
|
|
f656cf |
- char *valuestring; /* The item's string, if type==cJSON_String */
|
|
|
f656cf |
- int valueint; /* The item's number, if type==cJSON_Number */
|
|
|
f656cf |
- double valuedouble; /* The item's number, if type==cJSON_Number */
|
|
|
f656cf |
-
|
|
|
f656cf |
- char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
|
|
f656cf |
-} cJSON;
|
|
|
f656cf |
-
|
|
|
f656cf |
-typedef struct cJSON_Hooks {
|
|
|
f656cf |
- void *(*malloc_fn)(size_t sz);
|
|
|
f656cf |
- void (*free_fn)(void *ptr);
|
|
|
f656cf |
-} cJSON_Hooks;
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Supply malloc, realloc and free functions to cJSON */
|
|
|
f656cf |
-extern void cJSON_InitHooks(cJSON_Hooks* hooks);
|
|
|
f656cf |
-
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
|
|
|
f656cf |
-extern cJSON *cJSON_Parse(const char *value);
|
|
|
f656cf |
-/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
|
|
|
f656cf |
-extern char *cJSON_Print(cJSON *item);
|
|
|
f656cf |
-/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
|
|
|
f656cf |
-extern char *cJSON_PrintUnformatted(cJSON *item);
|
|
|
f656cf |
-/* Delete a cJSON entity and all subentities. */
|
|
|
f656cf |
-extern void cJSON_Delete(cJSON *c);
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Returns the number of items in an array (or object). */
|
|
|
f656cf |
-extern int cJSON_GetArraySize(cJSON *array);
|
|
|
f656cf |
-/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
|
|
|
f656cf |
-extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
|
|
|
f656cf |
-/* Get item "string" from object. Case insensitive. */
|
|
|
f656cf |
-extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
|
|
f656cf |
-extern const char *cJSON_GetErrorPtr();
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* These calls create a cJSON item of the appropriate type. */
|
|
|
f656cf |
-extern cJSON *cJSON_CreateNull();
|
|
|
f656cf |
-extern cJSON *cJSON_CreateTrue();
|
|
|
f656cf |
-extern cJSON *cJSON_CreateFalse();
|
|
|
f656cf |
-extern cJSON *cJSON_CreateBool(int b);
|
|
|
f656cf |
-extern cJSON *cJSON_CreateNumber(double num);
|
|
|
f656cf |
-extern cJSON *cJSON_CreateString(const char *string);
|
|
|
f656cf |
-extern cJSON *cJSON_CreateArray();
|
|
|
f656cf |
-extern cJSON *cJSON_CreateObject();
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* These utilities create an Array of count items. */
|
|
|
f656cf |
-extern cJSON *cJSON_CreateIntArray(int *numbers,int count);
|
|
|
f656cf |
-extern cJSON *cJSON_CreateFloatArray(float *numbers,int count);
|
|
|
f656cf |
-extern cJSON *cJSON_CreateDoubleArray(double *numbers,int count);
|
|
|
f656cf |
-extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Append item to the specified array/object. */
|
|
|
f656cf |
-extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
|
|
f656cf |
-extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
|
|
|
f656cf |
-/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
|
|
f656cf |
-extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
|
|
f656cf |
-extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Remove/Detatch items from Arrays/Objects. */
|
|
|
f656cf |
-extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
|
|
|
f656cf |
-extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
|
|
|
f656cf |
-extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
|
|
|
f656cf |
-extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* Update array items. */
|
|
|
f656cf |
-extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
|
|
|
f656cf |
-extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
|
|
f656cf |
-
|
|
|
f656cf |
-/* rger: added helpers */
|
|
|
f656cf |
-
|
|
|
f656cf |
-char *cJSON_print_number(cJSON *item);
|
|
|
f656cf |
-#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
|
|
|
f656cf |
-#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
|
|
|
f656cf |
-#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
|
|
|
f656cf |
-#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
|
|
|
f656cf |
-#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
|
|
|
f656cf |
-
|
|
|
f656cf |
-#ifdef __cplusplus
|
|
|
f656cf |
-}
|
|
|
f656cf |
-#endif
|
|
|
f656cf |
-
|
|
|
f656cf |
-#endif
|
|
|
f656cf |
diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c
|
|
|
f656cf |
index 88bd5e16c..ed2b47535 100644
|
|
|
f656cf |
--- a/plugins/omelasticsearch/omelasticsearch.c
|
|
|
f656cf |
+++ b/plugins/omelasticsearch/omelasticsearch.c
|
|
|
f656cf |
@@ -41,7 +41,7 @@
|
|
|
f656cf |
#if defined(__FreeBSD__)
|
|
|
f656cf |
#include <unistd.h>
|
|
|
f656cf |
#endif
|
|
|
f656cf |
-#include "cJSON/cjson.h"
|
|
|
f656cf |
+#include <json.h>
|
|
|
f656cf |
#include "conf.h"
|
|
|
f656cf |
#include "syslogd-types.h"
|
|
|
f656cf |
#include "srUtils.h"
|
|
|
f656cf |
@@ -626,29 +626,29 @@ finalize_it:
|
|
|
f656cf |
* Dumps entire bulk request and response in error log
|
|
|
f656cf |
*/
|
|
|
f656cf |
static rsRetVal
|
|
|
f656cf |
-getDataErrorDefault(wrkrInstanceData_t *pWrkrData,cJSON **pReplyRoot,uchar *reqmsg,char **rendered)
|
|
|
f656cf |
+getDataErrorDefault(wrkrInstanceData_t *pWrkrData,fjson_object **pReplyRoot,uchar *reqmsg,char **rendered)
|
|
|
f656cf |
{
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
- cJSON *req=0;
|
|
|
f656cf |
- cJSON *errRoot=0;
|
|
|
f656cf |
- cJSON *replyRoot = *pReplyRoot;
|
|
|
f656cf |
+ fjson_object *req=NULL;
|
|
|
f656cf |
+ fjson_object *errRoot=NULL;
|
|
|
f656cf |
+ fjson_object *replyRoot = *pReplyRoot;
|
|
|
f656cf |
|
|
|
f656cf |
- if((req=cJSON_CreateObject()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
- cJSON_AddItemToObject(req, "url", cJSON_CreateString((char*)pWrkrData->restURL));
|
|
|
f656cf |
- cJSON_AddItemToObject(req, "postdata", cJSON_CreateString((char*)reqmsg));
|
|
|
f656cf |
+ if((req=fjson_object_new_object()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
+ fjson_object_object_add(req, "url", fjson_object_new_string((char*)pWrkrData->restURL));
|
|
|
f656cf |
+ fjson_object_object_add(req, "postdata", fjson_object_new_string((char*)reqmsg));
|
|
|
f656cf |
|
|
|
f656cf |
- if((errRoot=cJSON_CreateObject()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot, "request", req);
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot, "reply", replyRoot);
|
|
|
f656cf |
- *rendered = cJSON_Print(errRoot);
|
|
|
f656cf |
+ if((errRoot=fjson_object_new_object()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
+ fjson_object_object_add(errRoot, "request", req);
|
|
|
f656cf |
+ fjson_object_object_add(errRoot, "reply", replyRoot);
|
|
|
f656cf |
+ *rendered = strdup((char*)fjson_object_to_json_string(errRoot));
|
|
|
f656cf |
|
|
|
f656cf |
- req=0;
|
|
|
f656cf |
- cJSON_Delete(errRoot);
|
|
|
f656cf |
+ req=NULL;
|
|
|
f656cf |
+ fjson_object_put(errRoot);
|
|
|
f656cf |
|
|
|
f656cf |
*pReplyRoot = NULL; /* tell caller not to delete once again! */
|
|
|
f656cf |
|
|
|
f656cf |
finalize_it:
|
|
|
f656cf |
- cJSON_Delete(req);
|
|
|
f656cf |
+ fjson_object_put(req);
|
|
|
f656cf |
RETiRet;
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
@@ -703,8 +703,8 @@ finalize_it:
|
|
|
f656cf |
/*
|
|
|
f656cf |
* check the status of response from ES
|
|
|
f656cf |
*/
|
|
|
f656cf |
-static int checkReplyStatus(cJSON* ok) {
|
|
|
f656cf |
- return (ok == NULL || ok->type != cJSON_Number || ok->valueint < 0 || ok->valueint > 299);
|
|
|
f656cf |
+static int checkReplyStatus(fjson_object* ok) {
|
|
|
f656cf |
+ return (ok == NULL || !fjson_object_is_type(ok, fjson_type_int) || fjson_object_get_int(ok) < 0 || fjson_object_get_int(ok) > 299);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
/*
|
|
|
f656cf |
@@ -712,7 +712,7 @@ static int checkReplyStatus(cJSON* ok) {
|
|
|
f656cf |
*/
|
|
|
f656cf |
typedef struct exeContext{
|
|
|
f656cf |
int statusCheckOnly;
|
|
|
f656cf |
- cJSON *errRoot;
|
|
|
f656cf |
+ fjson_object *errRoot;
|
|
|
f656cf |
rsRetVal (*prepareErrorFileContent)(struct exeContext *ctx,int itemStatus,char *request,char *response);
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
@@ -722,25 +722,24 @@ typedef struct exeContext{
|
|
|
f656cf |
* get content to be written in error file using context passed
|
|
|
f656cf |
*/
|
|
|
f656cf |
static rsRetVal
|
|
|
f656cf |
-parseRequestAndResponseForContext(wrkrInstanceData_t *pWrkrData,cJSON **pReplyRoot,uchar *reqmsg,context *ctx)
|
|
|
f656cf |
+parseRequestAndResponseForContext(wrkrInstanceData_t *pWrkrData,fjson_object **pReplyRoot,uchar *reqmsg,context *ctx)
|
|
|
f656cf |
{
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
- cJSON *replyRoot = *pReplyRoot;
|
|
|
f656cf |
+ fjson_object *replyRoot = *pReplyRoot;
|
|
|
f656cf |
int i;
|
|
|
f656cf |
int numitems;
|
|
|
f656cf |
- cJSON *items=0;
|
|
|
f656cf |
+ fjson_object *items=NULL;
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
/*iterate over items*/
|
|
|
f656cf |
- items = cJSON_GetObjectItem(replyRoot, "items");
|
|
|
f656cf |
- if(items == NULL || items->type != cJSON_Array) {
|
|
|
f656cf |
+ if(!fjson_object_object_get_ex(replyRoot, "items", &items)) {
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: error in elasticsearch reply: "
|
|
|
f656cf |
"bulkmode insert does not return array, reply is: %s\n",
|
|
|
f656cf |
pWrkrData->reply);
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_DATAFAIL);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
- numitems = cJSON_GetArraySize(items);
|
|
|
f656cf |
+ numitems = fjson_object_array_length(items);
|
|
|
f656cf |
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: Entire request %s\n",reqmsg);
|
|
|
f656cf |
const char *lastReqRead= (char*)reqmsg;
|
|
|
f656cf |
@@ -748,32 +747,32 @@ parseRequestAndResponseForContext(wrkrInstanceData_t *pWrkrData,cJSON **pReplyRo
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: %d items in reply\n", numitems);
|
|
|
f656cf |
for(i = 0 ; i < numitems ; ++i) {
|
|
|
f656cf |
|
|
|
f656cf |
- cJSON *item=0;
|
|
|
f656cf |
- cJSON *result=0;
|
|
|
f656cf |
- cJSON *ok=0;
|
|
|
f656cf |
+ fjson_object *item=NULL;
|
|
|
f656cf |
+ fjson_object *result=NULL;
|
|
|
f656cf |
+ fjson_object *ok=NULL;
|
|
|
f656cf |
int itemStatus=0;
|
|
|
f656cf |
- item = cJSON_GetArrayItem(items, i);
|
|
|
f656cf |
+ item = fjson_object_array_get_idx(items, i);
|
|
|
f656cf |
if(item == NULL) {
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: error in elasticsearch reply: "
|
|
|
f656cf |
"cannot obtain reply array item %d\n", i);
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_DATAFAIL);
|
|
|
f656cf |
}
|
|
|
f656cf |
- result = item->child;
|
|
|
f656cf |
- if(result == NULL || result->type != cJSON_Object) {
|
|
|
f656cf |
+ fjson_object_object_get_ex(item, "create", &result);
|
|
|
f656cf |
+ if(result == NULL || !fjson_object_is_type(result, fjson_type_object)) {
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: error in elasticsearch reply: "
|
|
|
f656cf |
"cannot obtain 'result' item for #%d\n", i);
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_DATAFAIL);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
- ok = cJSON_GetObjectItem(result, "status");
|
|
|
f656cf |
+ fjson_object_object_get_ex(result, "status", &ok;;
|
|
|
f656cf |
itemStatus = checkReplyStatus(ok);
|
|
|
f656cf |
-
|
|
|
f656cf |
+
|
|
|
f656cf |
char *request =0;
|
|
|
f656cf |
char *response =0;
|
|
|
f656cf |
if(ctx->statusCheckOnly)
|
|
|
f656cf |
{
|
|
|
f656cf |
if(itemStatus) {
|
|
|
f656cf |
- DBGPRINTF("omelasticsearch: error in elasticsearch reply: item %d, status is %d\n", i, ok->valueint);
|
|
|
f656cf |
+ DBGPRINTF("omelasticsearch: error in elasticsearch reply: item %d, status is %d\n", i, fjson_object_get_int(ok));
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: status check found error.\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_DATAFAIL);
|
|
|
f656cf |
}
|
|
|
f656cf |
@@ -786,13 +785,12 @@ parseRequestAndResponseForContext(wrkrInstanceData_t *pWrkrData,cJSON **pReplyRo
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: Couldn't get post request\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
-
|
|
|
f656cf |
- response = cJSON_PrintUnformatted(result);
|
|
|
f656cf |
+ response = (char*)fjson_object_to_json_string_ext(result, FJSON_TO_STRING_PLAIN);
|
|
|
f656cf |
|
|
|
f656cf |
if(response==NULL)
|
|
|
f656cf |
{
|
|
|
f656cf |
free(request);/*as its has been assigned.*/
|
|
|
f656cf |
- DBGPRINTF("omelasticsearch: Error getting cJSON_PrintUnformatted. Cannot continue\n");
|
|
|
f656cf |
+ DBGPRINTF("omelasticsearch: Error getting fjson_object_to_string_ext. Cannot continue\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
@@ -801,7 +799,6 @@ parseRequestAndResponseForContext(wrkrInstanceData_t *pWrkrData,cJSON **pReplyRo
|
|
|
f656cf |
|
|
|
f656cf |
/*free memory in any case*/
|
|
|
f656cf |
free(request);
|
|
|
f656cf |
- free(response);
|
|
|
f656cf |
|
|
|
f656cf |
if(ret != RS_RET_OK)
|
|
|
f656cf |
{
|
|
|
f656cf |
@@ -826,23 +823,23 @@ getDataErrorOnly(context *ctx,int itemStatus,char *request,char *response)
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
if(itemStatus)
|
|
|
f656cf |
{
|
|
|
f656cf |
- cJSON *onlyErrorResponses =0;
|
|
|
f656cf |
- cJSON *onlyErrorRequests=0;
|
|
|
f656cf |
+ fjson_object *onlyErrorResponses =NULL;
|
|
|
f656cf |
+ fjson_object *onlyErrorRequests=NULL;
|
|
|
f656cf |
|
|
|
f656cf |
- if((onlyErrorResponses=cJSON_GetObjectItem(ctx->errRoot, "reply")) == NULL)
|
|
|
f656cf |
+ if(!fjson_object_object_get_ex(ctx->errRoot, "reply", &onlyErrorResponses))
|
|
|
f656cf |
{
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: Failed to get reply json array. Invalid context. Cannot continue\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
- cJSON_AddItemToArray(onlyErrorResponses, cJSON_CreateString(response));
|
|
|
f656cf |
+ fjson_object_array_add(onlyErrorResponses, fjson_object_new_string(response));
|
|
|
f656cf |
|
|
|
f656cf |
- if((onlyErrorRequests=cJSON_GetObjectItem(ctx->errRoot, "request")) == NULL)
|
|
|
f656cf |
+ if(!fjson_object_object_get_ex(ctx->errRoot, "request", &onlyErrorRequests))
|
|
|
f656cf |
{
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: Failed to get request json array. Invalid context. Cannot continue\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
- cJSON_AddItemToArray(onlyErrorRequests, cJSON_CreateString(request));
|
|
|
f656cf |
+ fjson_object_array_add(onlyErrorRequests, fjson_object_new_string(request));
|
|
|
f656cf |
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
@@ -861,24 +858,24 @@ getDataInterleaved(context *ctx,
|
|
|
f656cf |
char *response)
|
|
|
f656cf |
{
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
- cJSON *interleaved =0;
|
|
|
f656cf |
- if((interleaved=cJSON_GetObjectItem(ctx->errRoot, "response")) == NULL)
|
|
|
f656cf |
+ fjson_object *interleaved =NULL;
|
|
|
f656cf |
+ if(!fjson_object_object_get_ex(ctx->errRoot, "response", &interleaved))
|
|
|
f656cf |
{
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: Failed to get response json array. Invalid context. Cannot continue\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
- cJSON *interleavedNode=0;
|
|
|
f656cf |
+ fjson_object *interleavedNode=NULL;
|
|
|
f656cf |
/*create interleaved node that has req and response json data*/
|
|
|
f656cf |
- if((interleavedNode=cJSON_CreateObject()) == NULL)
|
|
|
f656cf |
+ if((interleavedNode=fjson_object_new_object()) == NULL)
|
|
|
f656cf |
{
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: Failed to create interleaved node. Cann't continue\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
- cJSON_AddItemToObject(interleavedNode,"request", cJSON_CreateString(request));
|
|
|
f656cf |
- cJSON_AddItemToObject(interleavedNode,"reply", cJSON_CreateString(response));
|
|
|
f656cf |
+ fjson_object_object_add(interleavedNode,"request", fjson_object_new_string(request));
|
|
|
f656cf |
+ fjson_object_object_add(interleavedNode,"reply", fjson_object_new_string(response));
|
|
|
f656cf |
|
|
|
f656cf |
- cJSON_AddItemToArray(interleaved, interleavedNode);
|
|
|
f656cf |
+ fjson_object_array_add(interleaved, interleavedNode);
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
@@ -912,24 +909,24 @@ static rsRetVal
|
|
|
f656cf |
initializeErrorOnlyConext(wrkrInstanceData_t *pWrkrData,context *ctx){
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
ctx->statusCheckOnly=0;
|
|
|
f656cf |
- cJSON *errRoot=0;
|
|
|
f656cf |
- cJSON *onlyErrorResponses =0;
|
|
|
f656cf |
- cJSON *onlyErrorRequests=0;
|
|
|
f656cf |
- if((errRoot=cJSON_CreateObject()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
+ fjson_object *errRoot=NULL;
|
|
|
f656cf |
+ fjson_object *onlyErrorResponses =NULL;
|
|
|
f656cf |
+ fjson_object *onlyErrorRequests=NULL;
|
|
|
f656cf |
+ if((errRoot=fjson_object_new_object()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
|
|
|
f656cf |
- if((onlyErrorResponses=cJSON_CreateArray()) == NULL) {
|
|
|
f656cf |
- cJSON_Delete(errRoot);
|
|
|
f656cf |
+ if((onlyErrorResponses=fjson_object_new_array()) == NULL) {
|
|
|
f656cf |
+ fjson_object_put(errRoot);
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
- if((onlyErrorRequests=cJSON_CreateArray()) == NULL) {
|
|
|
f656cf |
- cJSON_Delete(errRoot);
|
|
|
f656cf |
- cJSON_Delete(onlyErrorResponses);
|
|
|
f656cf |
+ if((onlyErrorRequests=fjson_object_new_array()) == NULL) {
|
|
|
f656cf |
+ fjson_object_put(errRoot);
|
|
|
f656cf |
+ fjson_object_put(onlyErrorResponses);
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot, "url", cJSON_CreateString((char*)pWrkrData->restURL));
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot,"request",onlyErrorRequests);
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot, "reply", onlyErrorResponses);
|
|
|
f656cf |
+ fjson_object_object_add(errRoot, "url", fjson_object_new_string((char*)pWrkrData->restURL));
|
|
|
f656cf |
+ fjson_object_object_add(errRoot,"request",onlyErrorRequests);
|
|
|
f656cf |
+ fjson_object_object_add(errRoot, "reply", onlyErrorResponses);
|
|
|
f656cf |
ctx->errRoot = errRoot;
|
|
|
f656cf |
ctx->prepareErrorFileContent= &getDataErrorOnly;
|
|
|
f656cf |
finalize_it:
|
|
|
f656cf |
@@ -943,17 +940,17 @@ static rsRetVal
|
|
|
f656cf |
initializeInterleavedConext(wrkrInstanceData_t *pWrkrData,context *ctx){
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
ctx->statusCheckOnly=0;
|
|
|
f656cf |
- cJSON *errRoot=0;
|
|
|
f656cf |
- cJSON *interleaved =0;
|
|
|
f656cf |
- if((errRoot=cJSON_CreateObject()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
- if((interleaved=cJSON_CreateArray()) == NULL) {
|
|
|
f656cf |
- cJSON_Delete(errRoot);
|
|
|
f656cf |
+ fjson_object *errRoot=NULL;
|
|
|
f656cf |
+ fjson_object *interleaved =NULL;
|
|
|
f656cf |
+ if((errRoot=fjson_object_new_object()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
+ if((interleaved=fjson_object_new_array()) == NULL) {
|
|
|
f656cf |
+ fjson_object_put(errRoot);
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot, "url", cJSON_CreateString((char*)pWrkrData->restURL));
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot,"response",interleaved);
|
|
|
f656cf |
+ fjson_object_object_add(errRoot, "url", fjson_object_new_string((char*)pWrkrData->restURL));
|
|
|
f656cf |
+ fjson_object_object_add(errRoot,"response",interleaved);
|
|
|
f656cf |
ctx->errRoot = errRoot;
|
|
|
f656cf |
ctx->prepareErrorFileContent= &getDataInterleaved;
|
|
|
f656cf |
finalize_it:
|
|
|
f656cf |
@@ -965,17 +962,17 @@ static rsRetVal
|
|
|
f656cf |
initializeErrorInterleavedConext(wrkrInstanceData_t *pWrkrData,context *ctx){
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
ctx->statusCheckOnly=0;
|
|
|
f656cf |
- cJSON *errRoot=0;
|
|
|
f656cf |
- cJSON *interleaved =0;
|
|
|
f656cf |
- if((errRoot=cJSON_CreateObject()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
- if((interleaved=cJSON_CreateArray()) == NULL) {
|
|
|
f656cf |
- cJSON_Delete(errRoot);
|
|
|
f656cf |
+ fjson_object *errRoot=NULL;
|
|
|
f656cf |
+ fjson_object *interleaved =NULL;
|
|
|
f656cf |
+ if((errRoot=fjson_object_new_object()) == NULL) ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
+ if((interleaved=fjson_object_new_array()) == NULL) {
|
|
|
f656cf |
+ fjson_object_put(errRoot);
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot, "url", cJSON_CreateString((char*)pWrkrData->restURL));
|
|
|
f656cf |
- cJSON_AddItemToObject(errRoot,"response",interleaved);
|
|
|
f656cf |
+ fjson_object_object_add(errRoot, "url", fjson_object_new_string((char*)pWrkrData->restURL));
|
|
|
f656cf |
+ fjson_object_object_add(errRoot,"response",interleaved);
|
|
|
f656cf |
ctx->errRoot = errRoot;
|
|
|
f656cf |
ctx->prepareErrorFileContent= &getDataErrorOnlyInterleaved;
|
|
|
f656cf |
finalize_it:
|
|
|
f656cf |
@@ -988,7 +985,7 @@ initializeErrorInterleavedConext(wrkrInstanceData_t *pWrkrData,context *ctx){
|
|
|
f656cf |
* needs to be closed, HUP must be sent.
|
|
|
f656cf |
*/
|
|
|
f656cf |
static rsRetVal
|
|
|
f656cf |
-writeDataError(wrkrInstanceData_t *pWrkrData, instanceData *pData, cJSON **pReplyRoot, uchar *reqmsg)
|
|
|
f656cf |
+writeDataError(wrkrInstanceData_t *pWrkrData, instanceData *pData, fjson_object **pReplyRoot, uchar *reqmsg)
|
|
|
f656cf |
{
|
|
|
f656cf |
char *rendered = NULL;
|
|
|
f656cf |
size_t toWrite;
|
|
|
f656cf |
@@ -1054,7 +1051,7 @@ writeDataError(wrkrInstanceData_t *pWrkrData, instanceData *pData, cJSON **pRepl
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: error creating file content.\n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
}
|
|
|
f656cf |
- rendered = cJSON_Print(ctx.errRoot);
|
|
|
f656cf |
+ rendered = (char*)fjson_object_to_json_string(ctx.errRoot);
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
@@ -1084,14 +1081,13 @@ writeDataError(wrkrInstanceData_t *pWrkrData, instanceData *pData, cJSON **pRepl
|
|
|
f656cf |
finalize_it:
|
|
|
f656cf |
if(bMutLocked)
|
|
|
f656cf |
pthread_mutex_unlock(&pData->mutErrFile);
|
|
|
f656cf |
- cJSON_Delete(ctx.errRoot);
|
|
|
f656cf |
- free(rendered);
|
|
|
f656cf |
+ fjson_object_put(ctx.errRoot);
|
|
|
f656cf |
RETiRet;
|
|
|
f656cf |
}
|
|
|
f656cf |
|
|
|
f656cf |
|
|
|
f656cf |
static rsRetVal
|
|
|
f656cf |
-checkResultBulkmode(wrkrInstanceData_t *pWrkrData, cJSON *root)
|
|
|
f656cf |
+checkResultBulkmode(wrkrInstanceData_t *pWrkrData, fjson_object *root)
|
|
|
f656cf |
{
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
context ctx;
|
|
|
f656cf |
@@ -1111,11 +1107,11 @@ checkResultBulkmode(wrkrInstanceData_t *pWrkrData, cJSON *root)
|
|
|
f656cf |
static rsRetVal
|
|
|
f656cf |
checkResult(wrkrInstanceData_t *pWrkrData, uchar *reqmsg)
|
|
|
f656cf |
{
|
|
|
f656cf |
- cJSON *root;
|
|
|
f656cf |
- cJSON *status;
|
|
|
f656cf |
+ fjson_object *root;
|
|
|
f656cf |
+ fjson_object *status;
|
|
|
f656cf |
DEFiRet;
|
|
|
f656cf |
|
|
|
f656cf |
- root = cJSON_Parse(pWrkrData->reply);
|
|
|
f656cf |
+ root = fjson_tokener_parse(pWrkrData->reply);
|
|
|
f656cf |
if(root == NULL) {
|
|
|
f656cf |
DBGPRINTF("omelasticsearch: could not parse JSON result \n");
|
|
|
f656cf |
ABORT_FINALIZE(RS_RET_ERR);
|
|
|
f656cf |
@@ -1124,10 +1120,7 @@ checkResult(wrkrInstanceData_t *pWrkrData, uchar *reqmsg)
|
|
|
f656cf |
if(pWrkrData->pData->bulkmode) {
|
|
|
f656cf |
iRet = checkResultBulkmode(pWrkrData, root);
|
|
|
f656cf |
} else {
|
|
|
f656cf |
- status = cJSON_GetObjectItem(root, "status");
|
|
|
f656cf |
- /* as far as we know, no "status" means all went well */
|
|
|
f656cf |
- if(status != NULL &&
|
|
|
f656cf |
- (status->type == cJSON_Number || status->valueint >= 0 || status->valueint <= 299)) {
|
|
|
f656cf |
+ if(fjson_object_object_get_ex(root, "status", &status)) {
|
|
|
f656cf |
iRet = RS_RET_DATAFAIL;
|
|
|
f656cf |
}
|
|
|
f656cf |
}
|
|
|
f656cf |
@@ -1143,7 +1136,7 @@ checkResult(wrkrInstanceData_t *pWrkrData, uchar *reqmsg)
|
|
|
f656cf |
|
|
|
f656cf |
finalize_it:
|
|
|
f656cf |
if(root != NULL)
|
|
|
f656cf |
- cJSON_Delete(root);
|
|
|
f656cf |
+ fjson_object_put(root);
|
|
|
f656cf |
if(iRet != RS_RET_OK) {
|
|
|
f656cf |
STATSCOUNTER_INC(indexESFail, mutIndexESFail);
|
|
|
f656cf |
}
|
|
|
f656cf |
diff --git a/tests/es-bulk-errfile-empty.sh b/tests/es-bulk-errfile-empty.sh
|
|
|
f656cf |
index 1f27f62fe..95883cb3d 100755
|
|
|
f656cf |
--- a/tests/es-bulk-errfile-empty.sh
|
|
|
f656cf |
+++ b/tests/es-bulk-errfile-empty.sh
|
|
|
f656cf |
@@ -12,6 +12,7 @@ echo \[es-bulk-errfile-empty\]: basic test for elasticsearch functionality
|
|
|
f656cf |
if [ -f rsyslog.errorfile ]
|
|
|
f656cf |
then
|
|
|
f656cf |
echo "error: error file exists!"
|
|
|
f656cf |
+ cat rsyslog.errorfile
|
|
|
f656cf |
exit 1
|
|
|
f656cf |
fi
|
|
|
f656cf |
. $srcdir/diag.sh seq-check 0 9999
|
|
|
f656cf |
--
|
|
|
f656cf |
2.14.4
|
|
|
f656cf |
|