summaryrefslogtreecommitdiff
path: root/src/webutil.c
diff options
context:
space:
mode:
authorJeonghoon Park <jh1979.park@samsung.com>2017-11-02 12:53:27 +0900
committerJeonghoon Park <jh1979.park@samsung.com>2017-11-02 12:53:27 +0900
commit6463cb147cbfe6eba68b24571b082481a6b3fbf6 (patch)
treeb40d029fb61eaadc548794b10823aba9861d60a1 /src/webutil.c
parent0ce860cd380923fa6092d41641bfe385108d74af (diff)
downloadrcc-6463cb147cbfe6eba68b24571b082481a6b3fbf6.tar.gz
rcc-6463cb147cbfe6eba68b24571b082481a6b3fbf6.tar.bz2
rcc-6463cb147cbfe6eba68b24571b082481a6b3fbf6.zip
add new functions for json strings
Change-Id: I1004ab14a7b8339664ff40d7393f75c0069a6e29
Diffstat (limited to 'src/webutil.c')
-rw-r--r--src/webutil.c133
1 files changed, 125 insertions, 8 deletions
diff --git a/src/webutil.c b/src/webutil.c
index d1fed79..ea5ae9b 100644
--- a/src/webutil.c
+++ b/src/webutil.c
@@ -141,7 +141,7 @@ int web_util_json_fini(void)
return 0;
}
-int web_util_json_data_array_begin(void)
+int web_util_json_begin(void)
{
retv_if(Json_h.builder == NULL, -1);
retv_if(Json_h.is_begin == true, -1);
@@ -149,13 +149,131 @@ int web_util_json_data_array_begin(void)
Json_h.is_begin = true;
- /*
- {
- SensorsDataList : [ SensorData ]
+ json_builder_begin_object(Json_h.builder);
+
+ return 0;
+}
+
+int web_util_json_end(void)
+{
+ retv_if(Json_h.builder == NULL, -1);
+ retv_if(Json_h.is_begin == false, -1);
+ retv_if(Json_h.is_end == true, -1);
+
+ json_builder_end_object(Json_h.builder);
+ Json_h.is_end = true;
+
+ return 0;
+}
+
+int web_util_json_add_int(const char* key, long long int value)
+{
+ retv_if(!key, -1);
+
+ if (Json_h.builder == NULL) {
+ _E("Handle for json is not initialized, call web_util_json_init() first");
+ return -1;
}
- */
- json_builder_begin_object(Json_h.builder);
+ if (Json_h.is_begin == false) {
+ _E("json object has not begun, call web_util_json_begin() first");
+ return -1;
+ }
+
+ if (Json_h.is_end == true) {
+ _E("json object has already ended, call web_util_json_begin() first");
+ return -1;
+ }
+
+ json_builder_set_member_name(Json_h.builder, key);
+ json_builder_add_int_value(Json_h.builder, value);
+
+ return 0;
+}
+
+int web_util_json_add_double(const char* key, double value)
+{
+ retv_if(!key, -1);
+
+ if (Json_h.builder == NULL) {
+ _E("Handle for json is not initialized, call web_util_json_init() first");
+ return -1;
+ }
+
+ if (Json_h.is_begin == false) {
+ _E("json object has not begun, call web_util_json_begin() first");
+ return -1;
+ }
+
+ if (Json_h.is_end == true) {
+ _E("json object has already ended, call web_util_json_begin() first");
+ return -1;
+ }
+
+ json_builder_set_member_name(Json_h.builder, key);
+ json_builder_add_double_value(Json_h.builder, value);
+
+ return 0;
+}
+
+int web_util_json_add_boolean(const char* key, bool value)
+{
+ retv_if(!key, -1);
+
+ if (Json_h.builder == NULL) {
+ _E("Handle for json is not initialized, call web_util_json_init() first");
+ return -1;
+ }
+
+ if (Json_h.is_begin == false) {
+ _E("json object has not begun, call web_util_json_begin() first");
+ return -1;
+ }
+
+ if (Json_h.is_end == true) {
+ _E("json object has already ended, call web_util_json_begin() first");
+ return -1;
+ }
+
+ json_builder_set_member_name(Json_h.builder, key);
+ json_builder_add_boolean_value(Json_h.builder, value);
+
+ return 0;
+}
+
+int web_util_json_add_string(const char* key, const char *value)
+{
+ retv_if(!key, -1);
+
+ if (Json_h.builder == NULL) {
+ _E("Handle for json is not initialized, call web_util_json_init() first");
+ return -1;
+ }
+
+ if (Json_h.is_begin == false) {
+ _E("json object has not begun, call web_util_json_begin() first");
+ return -1;
+ }
+
+ if (Json_h.is_end == true) {
+ _E("json object has already ended, call web_util_json_begin() first");
+ return -1;
+ }
+
+ json_builder_set_member_name(Json_h.builder, key);
+ json_builder_add_string_value(Json_h.builder, value);
+
+ return 0;
+}
+
+int web_util_json_data_array_begin(void)
+{
+ int ret = 0;
+ retv_if(Json_h.builder == NULL, -1);
+
+ ret = web_util_json_begin();
+ retv_if(ret, -1);
+
json_builder_set_member_name(Json_h.builder, "SensorDataList");
json_builder_begin_array(Json_h.builder);
@@ -169,8 +287,7 @@ int web_util_json_data_array_end(void)
retv_if(Json_h.is_end == true, -1);
json_builder_end_array(Json_h.builder);
- json_builder_end_object(Json_h.builder);
- Json_h.is_end = true;
+ web_util_json_end();
return 0;
}