mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-18 01:50:32 -04:00
[misc_json] New function jparse_obj_from_evbuffer
This commit is contained in:
parent
89fc1fa5b8
commit
9b84150f6e
@ -22,6 +22,8 @@
|
|||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <event2/buffer.h>
|
||||||
|
#include <event2/event.h>
|
||||||
#include <json.h>
|
#include <json.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -123,3 +125,21 @@ jparse_str_from_array(json_object *array, int index, const char *key)
|
|||||||
item = json_object_array_get_idx(array, index);
|
item = json_object_array_get_idx(array, index);
|
||||||
return jparse_str_from_obj(item, key);
|
return jparse_str_from_obj(item, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_object *
|
||||||
|
jparse_obj_from_evbuffer(struct evbuffer *evbuf)
|
||||||
|
{
|
||||||
|
char *json_str;
|
||||||
|
|
||||||
|
// 0-terminate for safety
|
||||||
|
evbuffer_add(evbuf, "", 1);
|
||||||
|
|
||||||
|
json_str = (char *) evbuffer_pullup(evbuf, -1);
|
||||||
|
if (!json_str || (strlen(json_str) == 0))
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_MISC, "Failed to parse JSON from input buffer\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return json_tokener_parse(json_str);
|
||||||
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#define SRC_MISC_JSON_H_
|
#define SRC_MISC_JSON_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <event2/event.h>
|
||||||
#include <json.h>
|
#include <json.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -53,5 +54,7 @@ jparse_time_from_obj(json_object *haystack, const char *key);
|
|||||||
const char *
|
const char *
|
||||||
jparse_str_from_array(json_object *array, int index, const char *key);
|
jparse_str_from_array(json_object *array, int index, const char *key);
|
||||||
|
|
||||||
|
json_object *
|
||||||
|
jparse_obj_from_evbuffer(struct evbuffer *evbuf);
|
||||||
|
|
||||||
#endif /* SRC_MISC_JSON_H_ */
|
#endif /* SRC_MISC_JSON_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user