diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-25 22:54:02 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-25 22:54:02 +0200 |
commit | 07d451f79110dd98bb2ff8c1cf107745edbe92ce (patch) | |
tree | 2689759b9fa9b420844f60847b2ec673cf22bb53 /src/json | |
parent | e62d669865e9ce03f924d2b12401dfbe42f3b886 (diff) | |
download | gnunet-07d451f79110dd98bb2ff8c1cf107745edbe92ce.tar.gz gnunet-07d451f79110dd98bb2ff8c1cf107745edbe92ce.zip |
NAMESTORE/JSON: fix parsing exp and flags
Diffstat (limited to 'src/json')
-rw-r--r-- | src/json/json_gnsrecord.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c index 83ea367d5..2adf3c777 100644 --- a/src/json/json_gnsrecord.c +++ b/src/json/json_gnsrecord.c | |||
@@ -45,11 +45,12 @@ | |||
45 | */ | 45 | */ |
46 | static int | 46 | static int |
47 | parse_gnsrecordobject (void *cls, | 47 | parse_gnsrecordobject (void *cls, |
48 | json_t *root, | 48 | json_t *root, |
49 | struct GNUNET_JSON_Specification *spec) | 49 | struct GNUNET_JSON_Specification *spec) |
50 | { | 50 | { |
51 | struct GNUNET_GNSRECORD_Data *gnsrecord_object; | 51 | struct GNUNET_GNSRECORD_Data *gnsrecord_object; |
52 | struct GNUNET_TIME_Absolute abs_expiration_time; | 52 | struct GNUNET_TIME_Absolute abs_expiration_time; |
53 | struct GNUNET_TIME_Absolute rel_expiration_time; | ||
53 | int unpack_state=0; | 54 | int unpack_state=0; |
54 | const char *value; | 55 | const char *value; |
55 | const char *expiration_time; | 56 | const char *expiration_time; |
@@ -63,21 +64,21 @@ parse_gnsrecordobject (void *cls, | |||
63 | if(!json_is_object(root)) | 64 | if(!json_is_object(root)) |
64 | { | 65 | { |
65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 66 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
66 | "Error json is not array nor object!\n"); | 67 | "Error json is not array nor object!\n"); |
67 | return GNUNET_SYSERR; | 68 | return GNUNET_SYSERR; |
68 | } | 69 | } |
69 | //interpret single gns record | 70 | //interpret single gns record |
70 | unpack_state = json_unpack(root, | 71 | unpack_state = json_unpack(root, |
71 | "{s:s, s:s, s:s, s?:i, s:s!}", | 72 | "{s:s, s:s, s:s, s?:i, s:s!}", |
72 | GNUNET_JSON_GNSRECORD_VALUE, &value, | 73 | GNUNET_JSON_GNSRECORD_VALUE, &value, |
73 | GNUNET_JSON_GNSRECORD_TYPE, &record_type, | 74 | GNUNET_JSON_GNSRECORD_TYPE, &record_type, |
74 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time, | 75 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, &expiration_time, |
75 | GNUNET_JSON_GNSRECORD_FLAG, &flag, | 76 | GNUNET_JSON_GNSRECORD_FLAG, &flag, |
76 | GNUNET_JSON_GNSRECORD_RECORD_NAME, &name); | 77 | GNUNET_JSON_GNSRECORD_RECORD_NAME, &name); |
77 | if (0 != unpack_state) | 78 | if (0 != unpack_state) |
78 | { | 79 | { |
79 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 80 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
80 | "Error json object has a wrong format!\n"); | 81 | "Error json object has a wrong format!\n"); |
81 | return GNUNET_SYSERR; | 82 | return GNUNET_SYSERR; |
82 | } | 83 | } |
83 | gnsrecord_object = GNUNET_new (struct GNUNET_GNSRECORD_Data); | 84 | gnsrecord_object = GNUNET_new (struct GNUNET_GNSRECORD_Data); |
@@ -90,9 +91,9 @@ parse_gnsrecordobject (void *cls, | |||
90 | } | 91 | } |
91 | if (GNUNET_OK | 92 | if (GNUNET_OK |
92 | != GNUNET_GNSRECORD_string_to_value (gnsrecord_object->record_type, | 93 | != GNUNET_GNSRECORD_string_to_value (gnsrecord_object->record_type, |
93 | value, | 94 | value, |
94 | &rdata, | 95 | &rdata, |
95 | &rdata_size)) | 96 | &rdata_size)) |
96 | { | 97 | { |
97 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Value invalid for record type\n"); | 98 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Value invalid for record type\n"); |
98 | GNUNET_free(gnsrecord_object); | 99 | GNUNET_free(gnsrecord_object); |
@@ -107,25 +108,20 @@ parse_gnsrecordobject (void *cls, | |||
107 | gnsrecord_object->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 108 | gnsrecord_object->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
108 | } | 109 | } |
109 | else if (GNUNET_OK | 110 | else if (GNUNET_OK |
110 | == GNUNET_STRINGS_fancy_time_to_absolute (expiration_time, | 111 | == GNUNET_STRINGS_fancy_time_to_absolute (expiration_time, |
111 | &abs_expiration_time)) | 112 | &abs_expiration_time)) |
112 | { | 113 | { |
113 | gnsrecord_object->expiration_time = abs_expiration_time.abs_value_us; | 114 | gnsrecord_object->expiration_time = abs_expiration_time.abs_value_us; |
114 | } | 115 | } |
115 | else | 116 | else if (GNUNET_OK |
117 | == GNUNET_STRINGS_fancy_time_to_relative (expiration_time, | ||
118 | &rel_expiration_time)) | ||
116 | { | 119 | { |
117 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid\n"); | 120 | gnsrecord_object->expiration_time = rel_expiration_time.rel_value_us; |
118 | GNUNET_free_non_null(rdata); | ||
119 | GNUNET_free(gnsrecord_object); | ||
120 | return GNUNET_SYSERR; | ||
121 | } | 121 | } |
122 | // check if flag is a valid enum value | 122 | else |
123 | if ((GNUNET_GNSRECORD_RF_NONE != flag) | ||
124 | && (GNUNET_GNSRECORD_RF_PRIVATE != flag) | ||
125 | && (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION != flag) | ||
126 | && (GNUNET_GNSRECORD_RF_SHADOW_RECORD) != flag) | ||
127 | { | 123 | { |
128 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flag invalid\n"); | 124 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid\n"); |
129 | GNUNET_free_non_null(rdata); | 125 | GNUNET_free_non_null(rdata); |
130 | GNUNET_free(gnsrecord_object); | 126 | GNUNET_free(gnsrecord_object); |
131 | return GNUNET_SYSERR; | 127 | return GNUNET_SYSERR; |