diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-08 22:42:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-08 22:42:13 +0000 |
commit | 039d3555ffc5b7f5174dddb1a93399b1fb64aa13 (patch) | |
tree | 6ce88b1ea0e9a2427e6a3e060e5c1100d488af68 /src/namestore/namestore_api_monitor.c | |
parent | c8b184df65f4ce954ab571a2a174db3ea0d5c1d6 (diff) | |
download | gnunet-039d3555ffc5b7f5174dddb1a93399b1fb64aa13.tar.gz gnunet-039d3555ffc5b7f5174dddb1a93399b1fb64aa13.zip |
-finishing monitor API on client-side
Diffstat (limited to 'src/namestore/namestore_api_monitor.c')
-rw-r--r-- | src/namestore/namestore_api_monitor.c | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index e2caea8a5..5eb3e6803 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -127,20 +127,73 @@ handle_updates (void *cls, | |||
127 | const struct GNUNET_MessageHeader *msg) | 127 | const struct GNUNET_MessageHeader *msg) |
128 | { | 128 | { |
129 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 129 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
130 | const struct LookupNameResponseMessage *lrm; | ||
131 | size_t lrm_len; | ||
132 | size_t exp_lrm_len; | ||
133 | size_t name_len; | ||
134 | size_t rd_len; | ||
135 | unsigned rd_count; | ||
136 | const char *name_tmp; | ||
137 | const char *rd_ser_tmp; | ||
138 | struct GNUNET_TIME_Absolute expire; | ||
130 | 139 | ||
131 | if (NULL == msg) | 140 | if (NULL == msg) |
132 | { | 141 | { |
133 | reconnect (zm); | 142 | reconnect (zm); |
134 | return; | 143 | return; |
135 | } | 144 | } |
136 | // FIXME: parse, validate | 145 | if ( (ntohs (msg->size) < sizeof (struct LookupNameResponseMessage)) || |
146 | (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE != ntohs (msg->type) ) ) | ||
147 | { | ||
148 | GNUNET_break (0); | ||
149 | reconnect (zm); | ||
150 | return; | ||
151 | } | ||
152 | lrm = (const struct LookupNameResponseMessage *) msg; | ||
153 | lrm_len = ntohs (lrm->gns_header.header.size); | ||
154 | rd_len = ntohs (lrm->rd_len); | ||
155 | rd_count = ntohs (lrm->rd_count); | ||
156 | name_len = ntohs (lrm->name_len); | ||
157 | expire = GNUNET_TIME_absolute_ntoh (lrm->expire); | ||
158 | exp_lrm_len = sizeof (struct LookupNameResponseMessage) + name_len + rd_len; | ||
159 | if (lrm_len != exp_lrm_len) | ||
160 | { | ||
161 | GNUNET_break (0); | ||
162 | reconnect (zm); | ||
163 | return; | ||
164 | } | ||
165 | if (0 == name_len) | ||
166 | { | ||
167 | GNUNET_break (0); | ||
168 | reconnect (zm); | ||
169 | return; | ||
170 | } | ||
171 | name_tmp = (const char *) &lrm[1]; | ||
172 | if ((name_tmp[name_len -1] != '\0') || (name_len > MAX_NAME_LEN)) | ||
173 | { | ||
174 | GNUNET_break (0); | ||
175 | reconnect (zm); | ||
176 | return; | ||
177 | } | ||
178 | rd_ser_tmp = (const char *) &name_tmp[name_len]; | ||
179 | { | ||
180 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | ||
137 | 181 | ||
138 | GNUNET_CLIENT_receive (zm->h, | 182 | if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)) |
139 | &handle_updates, | 183 | { |
140 | zm, | 184 | GNUNET_break (0); |
141 | GNUNET_TIME_UNIT_FOREVER_REL); | 185 | reconnect (zm); |
142 | // FIXME: call 'monitor'. | 186 | return; |
143 | // zm->monitor (zm->monitor_cls, ...); | 187 | } |
188 | GNUNET_CLIENT_receive (zm->h, | ||
189 | &handle_updates, | ||
190 | zm, | ||
191 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
192 | zm->monitor(zm->monitor_cls, | ||
193 | &lrm->public_key, expire, | ||
194 | name_tmp, | ||
195 | rd_count, rd, &lrm->signature); | ||
196 | } | ||
144 | } | 197 | } |
145 | 198 | ||
146 | 199 | ||