示例#1
0
OGRErr OGRTopoJSONReader::Parse( const char* pszText )
{
    if( NULL != pszText )
    {
        json_tokener *jstok = json_tokener_new();
        json_object *jsobj = json_tokener_parse_ex(jstok, pszText, -1);
        if( jstok->err != json_tokener_success)
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                      "TopoJSON parsing error: %s (at offset %d)",
            	      json_tokener_error_desc(jstok->err), jstok->char_offset);

            json_tokener_free(jstok);
            return OGRERR_CORRUPT_DATA;
        }
        json_tokener_free(jstok);

        /* JSON tree is shared for while lifetime of the reader object
         * and will be released in the destructor.
         */
        poGJObject_ = jsobj;
    }

    return OGRERR_NONE;
}
示例#2
0
文件: geonames.c 项目: stv0g/sun
static size_t json_parse_callback(void *contents, size_t size, size_t nmemb, void *userp) {
	static struct json_tokener *jtok;
	static struct json_object *jobj;
	size_t realsize = size * nmemb;

	/* initialize tokener */
	if (jtok == NULL) {
		jtok = json_tokener_new();
		jtok->err = json_tokener_continue;
	}

	if (jtok->err == json_tokener_continue) {
#ifdef DEBUG
		printf("got chunk: %d * %d = %d bytes\r\n", size, nmemb, realsize);
#endif

		jobj = json_tokener_parse_ex(jtok, (char *) contents, realsize);

		if (jtok->err == json_tokener_success) {
			*(struct json_object **) userp = jobj;
			json_tokener_free(jtok);
		}
		else if (jtok->err != json_tokener_continue) {
			fprintf(stderr, "parse error: %s\r\n", json_tokener_errors[jtok->err]);
			*(void **) userp = NULL;
			json_tokener_free(jtok);
		}
	}

	return realsize;
}
示例#3
0
json_object *OGRGMEParseJSON( const char* pszText )
{
    if( NULL != pszText )
    {
        json_tokener* jstok = NULL;
        json_object* jsobj = NULL;

        jstok = json_tokener_new();
        jsobj = json_tokener_parse_ex(jstok, pszText, -1);
        if( jstok->err != json_tokener_success)
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                      "JSON parsing error: %s (at offset %d)",
                          json_tokener_error_desc(jstok->err), jstok->char_offset);

            json_tokener_free(jstok);
            return NULL;
        }
        json_tokener_free(jstok);

        /* JSON tree is shared for while lifetime of the reader object
         * and will be released in the destructor.
         */
        return jsobj;
    }

    return NULL;
}
示例#4
0
/**
 * Load json document from memory buffer.
 * @param  pabyData Buffer.data.
 * @param  nLength  Buffer size.
 * @return          true on success. If error occurred it can be received using CPLGetLastErrorMsg method.
 *
 * @since GDAL 2.3
 */
bool CPLJSONDocument::LoadMemory(const GByte *pabyData, int nLength)
{
    if(nullptr == pabyData)
    {
        return false;
    }

    if( m_poRootJsonObject )
        json_object_put( TO_JSONOBJ(m_poRootJsonObject) );

    json_tokener *jstok = json_tokener_new();
    m_poRootJsonObject = json_tokener_parse_ex( jstok,
                                                reinterpret_cast<const char*>(pabyData),
                                                nLength );
    bool bParsed = jstok->err == json_tokener_success;
    if(!bParsed)
    {
        CPLError( CE_Failure, CPLE_AppDefined, "JSON parsing error: %s (at offset %d)",
                 json_tokener_error_desc( jstok->err ), jstok->char_offset );
        json_tokener_free( jstok );
        return false;
    }
    json_tokener_free( jstok );
    return bParsed;
}
示例#5
0
void vz::api::Volkszaehler::api_parse_exception(CURLresponse response, char *err, size_t n) {
	struct json_tokener *json_tok;
	struct json_object *json_obj;

	json_tok = json_tokener_new();
	json_obj = json_tokener_parse_ex(json_tok, response.data, response.size);

	if (json_tok->err == json_tokener_success) {
		json_obj = json_object_object_get(json_obj, "exception");

		if (json_obj) {
			const std::string err_type(json_object_get_string(json_object_object_get(json_obj,  "type")));
			const std::string err_message( json_object_get_string(json_object_object_get(json_obj,  "message")));

			snprintf(err, n, "'%s': '%s'", err_type.c_str(), err_message.c_str());
			// evaluate error
			if (err_type == "UniqueConstraintViolationException") {
				if (err_message.find("Duplicate entry") ) {
					print(log_warning, "middle says duplicated value. removing first entry!", channel()->name());
					_values.pop_front();
				}
			}
		}
		else {
			strncpy(err, "missing exception", n);
		}
	}
	else {
		strncpy(err, json_tokener_errors[json_tok->err], n);
	}

	json_object_put(json_obj);
	json_tokener_free(json_tok);
}
static void
jcrusher_data_destroy(JCrusherData * data)
{
  TSDebug("jcrusher", "Start of jcrusher_data_destroy()");
  if (data) {
    if (data->downstream_buffer) {
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying downstream buffer");
      TSIOBufferDestroy(data->downstream_buffer);
    }
    if (data->json_obj) {
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json object");
      json_object_put(data->json_obj);
      data->json_obj = NULL;
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json object -> done");
    }
    if (data->json_tok) {
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json tokener");
      json_tokener_free(data->json_tok);
      data->json_tok = NULL;
      TSDebug("jcrusher", "jcrusher_data_destroy - destroying json tokener -> done");
    }
    TSDebug("jcrusher", "jcrusher_data_destroy - Freeing data");
    TSfree(data);
    TSDebug("jcrusher", "jcrusher_data_destroy - Freeing data -> done");
  }
  TSDebug("jcrusher", "End of jcrusher_data_destroy()");
}
int bridge_request_destroy(bridge_request_t *self)
{
	json_object_put(self->response);
	json_tokener_free(self->tokener);
	FCGX_Free(&self->request, TRUE);
	return 0;
}
示例#8
0
static GError *
_body_parse_error (GString *b)
{
	g_assert (b != NULL);
	struct json_tokener *tok = json_tokener_new ();
	struct json_object *jbody = json_tokener_parse_ex (tok, b->str, b->len);
	json_tokener_free (tok);
	tok = NULL;

	if (!jbody)
		return NEWERROR(0, "No error explained");

	struct json_object *jcode, *jmsg;
	struct oio_ext_json_mapping_s map[] = {
		{"status", &jcode, json_type_int, 0},
		{"message",  &jmsg,  json_type_string, 0},
		{NULL, NULL, 0, 0}
	};
	GError *err =  oio_ext_extract_json(jbody, map);
	if (!err) {
		int code = 0;
		const char *msg = "Unknown error";
		if (jcode) code = json_object_get_int64 (jcode);
		if (jmsg) msg = json_object_get_string (jmsg);
		err = NEWERROR(code, "(code=%d) %s", code, msg);
	}
	json_object_put (jbody);
	return err;
}
示例#9
0
文件: api.cpp 项目: DoganA/vzlogger
void api_parse_exception(CURLresponse response, char *err, size_t n) {
	struct json_tokener *json_tok;
	struct json_object *json_obj;

	json_tok = json_tokener_new();
	json_obj = json_tokener_parse_ex(json_tok, response.data, response.size);

	if (json_tok->err == json_tokener_success) {
    json_obj = json_object_object_get(json_obj, "exception");

    if (json_obj) {
      snprintf(err, n, "%s: %s",
               json_object_get_string(json_object_object_get(json_obj,  "type")),
               json_object_get_string(json_object_object_get(json_obj,  "message"))
               );
    }
    else {
      strncpy(err, "missing exception", n);
    }
  }
  else {
    strncpy(err, json_tokener_errors[json_tok->err], n);
  }

	json_object_put(json_obj);
	json_tokener_free(json_tok);
}
示例#10
0
static int json_parse(lua_State *L)
{
    size_t len;
    const char *json = luaL_checklstring(L, 1, &len);
    struct json_state s = {
        .tok = json_tokener_new()
    };

    if (!s.tok)
        return 0;

    s.obj = json_tokener_parse_ex(s.tok, json, len);
    s.err = json_tokener_get_error(s.tok);

    if (s.obj)
    {
        _json_to_lua(L, s.obj);
        json_object_put(s.obj);
    }
    else
    {
        lua_pushnil(L);
    }

    if (s.err == json_tokener_continue)
        s.err = json_tokener_error_parse_eof;

    if (s.err)
        lua_pushstring(L, json_tokener_error_desc(s.err));

    json_tokener_free(s.tok);
    return (1 + !!s.err);
}
示例#11
0
static int json_new(lua_State *L)
{
    struct json_state *s;
    struct json_tokener *tok = json_tokener_new();

    if (!tok)
        return 0;

    s = lua_newuserdata(L, sizeof(*s));

    if (!s)
    {
        json_tokener_free(tok);
        return 0;
    }

    s->tok = tok;
    s->obj = NULL;
    s->err = json_tokener_continue;

    luaL_getmetatable(L, LUCI_JSONC_PARSER);
    lua_setmetatable(L, -2);

    return 1;
}
/*
 * Helper functions
 */
json_object *parse_json_len(const char *json_area, int length, int *end_offset)
{
	json_object *jobj;
	struct json_tokener *jtok;

	if (!json_area || length <= 0)
		return NULL;

	jtok = json_tokener_new();
	if (!jtok) {
		log_dbg("ERROR: Failed to init json tokener");
		return NULL;
	}

	jobj = json_tokener_parse_ex(jtok, json_area, length);
	if (!jobj)
		log_dbg("ERROR: Failed to parse json data (%d): %s",
			json_tokener_get_error(jtok),
			json_tokener_error_desc(json_tokener_get_error(jtok)));
	else
		*end_offset = jtok->char_offset;

	json_tokener_free(jtok);

	return jobj;
}
static json_object *_mmsvc_core_msg_json_tokener_parse_len(const char *str, int *len, mused_msg_parse_err_e *err)
{
	struct json_tokener *tok;
	struct json_object *obj;

	g_return_val_if_fail(str != NULL, NULL);
	g_return_val_if_fail(len != NULL, NULL);

	tok = json_tokener_new();

	g_return_val_if_fail(tok != NULL, NULL);

	obj = json_tokener_parse_ex(tok, str, *len);
	g_return_val_if_fail(obj != NULL, NULL);

	*len = tok->char_offset;

	if (tok->err != json_tokener_success) {
		LOGE("Json Error(%d) : %s", tok->err, json_tokener_error_desc(tok->err));
		json_object_put(obj);
		obj = NULL;
	}
	_mmsvc_core_msg_json_set_error(err, tok->err);

	json_tokener_free(tok);
	return obj;
}
示例#14
0
文件: handler.c 项目: Honululu/netifd
static void
netifd_parse_script_handler(const char *name, script_dump_cb cb)
{
	struct json_tokener *tok = NULL;
	json_object *obj;
	static char buf[512];
	char *start, *cmd;
	FILE *f;
	int len;

#define DUMP_SUFFIX	" '' dump"

	cmd = alloca(strlen(name) + 1 + sizeof(DUMP_SUFFIX));
	sprintf(cmd, "%s" DUMP_SUFFIX, name);

	f = popen(cmd, "r");
	if (!f)
		return;

	do {
		start = fgets(buf, sizeof(buf), f);
		if (!start)
			continue;

		len = strlen(start);

		if (!tok)
			tok = json_tokener_new();

		obj = json_tokener_parse_ex(tok, start, len);
		if (!is_error(obj)) {
			netifd_init_script_handler(name, obj, cb);
			json_object_put(obj);
			json_tokener_free(tok);
			tok = NULL;
		} else if (start[len - 1] == '\n') {
			json_tokener_free(tok);
			tok = NULL;
		}
	} while (!feof(f) && !ferror(f));

	if (tok)
		json_tokener_free(tok);

	pclose(f);
}
示例#15
0
static void
tlog_mem_json_reader_cleanup(struct tlog_json_reader *reader)
{
    struct tlog_mem_json_reader *mem_json_reader =
                                (struct tlog_mem_json_reader*)reader;
    if (mem_json_reader->tok != NULL) {
        json_tokener_free(mem_json_reader->tok);
        mem_json_reader->tok = NULL;
    }
}
示例#16
0
/** 
 * parse a JSON buffer into a value
 * 
 * @param ctx 
 * @param buf 
 * @param len 
 * @param valp 
 * 
 * @return 
 */
dpl_status_t
dpl_cdmi_parse_json_buffer(dpl_ctx_t *ctx,
                           const char *buf,
                           int len,
                           dpl_value_t **valp)
{
  int ret, ret2;
  json_tokener *tok = NULL;
  json_object *obj = NULL;
  dpl_value_t *val = NULL;

  //  write(1, buf, len);

  tok = json_tokener_new();
  if (NULL == tok)
    {
      ret = DPL_ENOMEM;
      goto end;
    }

  obj = json_tokener_parse_ex(tok, buf, len);
  if (NULL == obj)
    {
      ret = DPL_FAILURE;
      goto end;
    }

  ret2 = convert_obj_to_value(ctx, obj, 0, &val);
  if (DPL_SUCCESS != ret2)
    {
      ret = ret2;
      goto end;
    }
  
  if (NULL != valp)
    {
      *valp = val;
      val = NULL;
    }

  ret = DPL_SUCCESS;

 end:

  if (NULL != val)
    dpl_value_free(val);

  if (NULL != obj)
    json_object_put(obj);

  if (NULL != tok)
    json_tokener_free(tok);

  return ret;
}
示例#17
0
static gboolean xr_call_unserialize_response_json(xr_call* call, const char* buf, int len)
{
    struct json_tokener* t;
    struct json_object* r;
    int i;

    t = json_tokener_new();
    r = json_tokener_parse_ex(t, (char*)buf, len);
    json_tokener_free(t);

    if (r == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid JSON object.");
        return FALSE;
    }

    struct json_object* error = json_object_object_get(r, "error");
    if (error && !json_object_is_type(error, json_type_null))
    {
        if (json_object_is_type(error, json_type_object))
        {
            struct json_object* code = json_object_object_get(error, "code");
            struct json_object* message = json_object_object_get(error, "message");
            if (code && message && json_object_is_type(code, json_type_int) && json_object_is_type(message, json_type_string))
                xr_call_set_error(call, json_object_get_int(code), "%s", json_object_get_string(message));
            else
                xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid error object.");
        }
        else
            xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid error object.");

        json_object_put(r);
        return FALSE;
    }

    struct json_object* result = json_object_object_get(r, "result");
    if (result == NULL || json_object_is_type(result, json_type_null))
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Null result.");
        json_object_put(r);
        return FALSE;
    }

    xr_value* v = _xr_value_unserialize_json(result);
    if (v == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC response. Invalid result.");
        json_object_put(r);
        return FALSE;
    }

    xr_call_set_retval(call, v);
    json_object_put(r);
    return TRUE;
}
示例#18
0
static struct json_object *
compile_json(const gchar *json)
{
  struct json_tokener *tok;
  struct json_object *jso;

  tok = json_tokener_new();
  jso = json_tokener_parse_ex(tok, json, strlen(json));
  assert_true(tok->err == json_tokener_success, "expected to parse input json, but couldn't, json=%s", json);
  json_tokener_free(tok);
  return jso;
}
GError*
service_info_load_json(const gchar *encoded, struct service_info_s **out,
		gboolean permissive)
{
	struct json_tokener *tok = json_tokener_new();
	struct json_object *obj = json_tokener_parse_ex(tok,
			encoded, strlen(encoded));
	json_tokener_free(tok);
	GError *err = service_info_load_json_object(obj, out, permissive);
	json_object_put(obj);
	return err;
}
示例#20
0
int token_parse_json(struct access_token **tokenp, struct evbuffer *buf)
{
	char cbuf[1024];
	int removed;
	int ret;

	struct access_token *token;

	struct json_tokener *tokener;
	enum json_tokener_error jerr;
	struct json_object *obj;

	tokener = json_tokener_new();
	if (tokener == NULL) {
		return ENOMEM;
	}

	do {
		removed = evbuffer_remove(buf, cbuf, sizeof(cbuf));
		obj = json_tokener_parse_ex(tokener, cbuf, removed);
		jerr = json_tokener_get_error(tokener);
		verbose(FIREHOSE, "%s(): Passed %d bytes, result %p (%s), remaining %zd\n",
			__func__, removed, obj, json_tokener_error_desc(jerr),
		       evbuffer_get_length(buf));
	} while (obj == NULL && jerr == json_tokener_continue && evbuffer_get_length(buf) > 0);

	json_tokener_free(tokener);

	if (obj != NULL) {
		token = malloc(sizeof(*token));
		if (token == NULL) {
			ret = ENOMEM;
		} else {
			memset(token, 0, sizeof(*token));
			ret = build_token_into(token, obj);
			if (ret != 0) {
				token_free(token);
			}
		}
	} else {
		verbose(FIREHOSE, "%s(): json tokener reported: %s\n",
			__func__, json_tokener_error_desc(jerr));
	}

	json_object_put(obj);

	if (ret == 0) {
		*tokenp = token;
	}

	return ret;
}
int
noit_check_stats_from_json_str(noit_check_t *check, stats_t *s,
                               const char *json_str, int len) {
  int rv = -1;
  struct json_tokener *tok = NULL;
  struct json_object *root = NULL;
  tok = json_tokener_new();
  root = json_tokener_parse_ex(tok, json_str, len);
  if(root) rv = populate_stats_from_resmon_formatted_json(check, s, root, NULL);
  if(tok) json_tokener_free(tok);
  if(root) json_object_put(root);
  return rv;
}
示例#22
0
bool JSON_parser(Variant &return_value, const char *data, int data_len,
                 bool assoc, int depth, int64_t options) {
    json_tokener *tok;
    json_object *new_obj;
    bool retval = false;

#if JSON_C_MINOR_VERSION >= 11
    tok = json_tokener_new_ex(depth);
#else
    tok = json_tokener_new();
#endif
    if (!tok) {
        return retval;
    }

    //if (!(options & k_JSON_FB_LOOSE)) {
    //    json_tokener_set_flags(tok, JSON_TOKENER_STRICT);
    //}

    bool const stable_maps = options & k_JSON_FB_STABLE_MAPS;
    bool const collections = stable_maps || options & k_JSON_FB_COLLECTIONS;

    new_obj = json_tokener_parse_ex(tok, data, data_len);
    if (json_tokener_get_error(tok)==json_tokener_continue) {
        new_obj = json_tokener_parse_ex(tok, "", -1);
    }

    if (new_obj) {
        return_value = json_object_to_variant(new_obj, assoc, stable_maps,
                                              collections);
        json_object_put(new_obj);
        retval = true;
    } else {
        switch (json_tokener_get_error(tok)) {
        case json_tokener_success:
            retval = true;
            break;

        case json_tokener_error_depth:
            json_set_last_error_code(json_error_codes::JSON_ERROR_DEPTH);
            break;

        default:
            json_set_last_error_code(json_error_codes::JSON_ERROR_SYNTAX,
                                     json_tokener_get_error(tok));
        }
    }

    json_tokener_free(tok);
    return retval;
}
示例#23
0
static void
tlog_journal_json_reader_cleanup(struct tlog_json_reader *reader)
{
    struct tlog_journal_json_reader *journal_json_reader =
                                (struct tlog_journal_json_reader*)reader;
    if (journal_json_reader->tok != NULL) {
        json_tokener_free(journal_json_reader->tok);
        journal_json_reader->tok = NULL;
    }
    if (journal_json_reader->journal != NULL) {
        sd_journal_close(journal_json_reader->journal);
        journal_json_reader->journal = NULL;
    }
}
示例#24
0
文件: common.c 项目: danielinux/vde3
vde_sobj *vde_sobj_from_string(const char *str)
{
  struct json_tokener *tok;
  struct json_object *obj;

  tok = json_tokener_new();
  if (tok == NULL) {
    errno = ENOMEM;
    return NULL;
  }
  obj = json_tokener_parse_ex(tok, str, -1);
  json_tokener_free(tok);
  return obj;
}
示例#25
0
static gboolean xr_call_unserialize_request_json(xr_call* call, const char* buf, int len)
{
    struct json_tokener* t;
    struct json_object* r;
    int i;

    t = json_tokener_new();
    r = json_tokener_parse_ex(t, (char*)buf, len);
    json_tokener_free(t);

    if (r == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Invalid JSON object.");
        return FALSE;
    }

    call->method = g_strdup(json_object_get_string(json_object_object_get(r, "method")));
    if (call->method == NULL)
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Missing method.");
        json_object_put(r);
        return FALSE;
    }

    struct json_object* params = json_object_object_get(r, "params");
    if (params == NULL || !json_object_is_type(params, json_type_array))
    {
        xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Invalid params.");
        json_object_put(r);
        return FALSE;
    }

    const int params_count = json_object_array_length(params);
    for (i = 0; i < params_count; i++)
    {
        xr_value* v = _xr_value_unserialize_json(json_object_array_get_idx(params, i));
        if (v == NULL)
        {
            xr_call_set_error(call, -1, "Can't parse JSON-RPC request. Failed to unserialize parameter %d.", i);
            json_object_put(r);
            return FALSE;
        }

        xr_call_add_param(call, v);
    }

    json_object_put(r);
    return TRUE;
}
示例#26
0
static void
tlog_fd_json_reader_cleanup(struct tlog_json_reader *reader)
{
    struct tlog_fd_json_reader *fd_json_reader =
                                (struct tlog_fd_json_reader*)reader;
    if (fd_json_reader->tok != NULL) {
        json_tokener_free(fd_json_reader->tok);
        fd_json_reader->tok = NULL;
    }
    free(fd_json_reader->buf);
    fd_json_reader->buf = NULL;
    if (fd_json_reader->fd_owned) {
        close(fd_json_reader->fd);
        fd_json_reader->fd_owned = false;
    }
}
示例#27
0
/** Query a Couchbase design document view
 *
 * Setup and execute a Couchbase view request and wait for the result.
 *
 * @param  instance Couchbase connection instance.
 * @param  cookie   Couchbase cookie for returning information from callbacks.
 * @param  path     The fully qualified view path including the design document and view name.
 * @param  post     The post payload (NULL for none).
 * @return          Couchbase error object.
 */
lcb_error_t couchbase_query_view(lcb_t instance, const void *cookie, const char *path, const char *post)
{
	cookie_u cu;                         /* union of const and non const pointers */
	cu.cdata = cookie;                   /* set const union member to cookie passed from couchbase */
	cookie_t *c = (cookie_t *) cu.data;  /* set our cookie struct using non-const member */
	lcb_error_t error;                   /* couchbase command return */
	lcb_http_cmd_t cmd;                  /* http command struct */
	const lcb_http_cmd_t *commands;      /* http commands array */

	commands = &cmd;
	memset(&cmd, 0, sizeof(cmd));

	/* populate command struct */
	cmd.v.v0.path = path;
	cmd.v.v0.npath = strlen(cmd.v.v0.path);
	cmd.v.v0.body = post;
	cmd.v.v0.nbody = post ? strlen(post) : 0;
	cmd.v.v0.method = post ? LCB_HTTP_METHOD_POST : LCB_HTTP_METHOD_GET;
	cmd.v.v0.chunked = 1;
	cmd.v.v0.content_type = "application/json";

	/* clear cookie */
	memset(c, 0, sizeof(cookie_t));

	/* init tokener error */
	c->jerr = json_tokener_success;

	/* create token */
	c->jtok = json_tokener_new();

	/* debugging */
	DEBUG3("rlm_couchbase: fetching view %s", path);

	/* query the view */
	if ((error = lcb_make_http_request(instance, c, LCB_HTTP_TYPE_VIEW, commands, NULL)) == LCB_SUCCESS) {
		/* enter event loop on success */
		lcb_wait(instance);
	}

	/* free token */
	json_tokener_free(c->jtok);

	/* return error */
	return error;
}
示例#28
0
    enum http_rc_e
action_cs_put (struct req_args_s *args)
{
    struct json_tokener *parser;
    struct json_object *jbody;
    enum http_rc_e rc;

    parser = json_tokener_new ();
    jbody = json_tokener_parse_ex (parser, (char *) args->rq->body->data,
            args->rq->body->len);
    if (!json_object_is_type (jbody, json_type_object))
        rc = _reply_format_error (args, BADREQ ("Invalid srv"));
    else
        rc = _registration (args, REGOP_PUSH, jbody);
    json_object_put (jbody);
    json_tokener_free (parser);
    return rc;
}
示例#29
0
struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error) {
	struct json_tokener* tok;
	struct json_object* obj;

	tok = json_tokener_new();
	if (!tok)
		return NULL;
	obj = json_tokener_parse_ex(tok, str, -1);
	*error = tok->err;
	if(tok->err != json_tokener_success) {
		if (obj != NULL)
			json_object_put(obj);
		obj = NULL;
	}

	json_tokener_free(tok);
	return obj;
}
/**
 * To be called by each thread of user program that will use this library,
 * after last other use of this library.
 * To be called once per successful call to keystone_start by that thread.
 * Thread-safe and re-entrant.
 */
void
keystone_end(keystone_context_t *context)
{
	assert(context != NULL);
	assert(context->pvt.curl != NULL);

	curl_easy_cleanup(context->pvt.curl);
	context->pvt.curl = NULL;
	if (context->pvt.auth_token != NULL) {
		context->pvt.auth_token = context->allocator(context->pvt.auth_token, 0);
	}
	if (context->pvt.auth_payload != NULL) {
		context->pvt.auth_payload = context->allocator(context->pvt.auth_payload, 0);
	}
	if (context->pvt.json_tokeniser != NULL) {
		json_tokener_free(context->pvt.json_tokeniser);
		context->pvt.json_tokeniser = NULL;
	}
}