summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-08 17:03:03 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-08 17:03:03 +0800
commitefebfe44e1a1995b4562a7b0ac779aee71db9f77 (patch)
treefae0f59b4b20649a55b6a3806a2867f3b4f720ad
parent244a0959705dbbef1ad3741ed0ae4edba81f1480 (diff)
Break down the user properties key-value pairs
But somehow strtok takes ": " as ":" and " " separately? So for now we have space prepended values. We'll fix that.
-rw-r--r--rtclient.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/rtclient.c b/rtclient.c
index d8b8003..46db370 100644
--- a/rtclient.c
+++ b/rtclient.c
@@ -72,18 +72,42 @@ user_callback(void *contents, size_t size, size_t nmemb, void *writedata)
char response[realsize + 1];
memcpy(&response[0], contents, realsize);
response[realsize] = '\0';
- char *lines[24];
+
+ static const unsigned short nproperties = 24;
+ char *lines[nproperties];
char *line = strtok(response, "\n");
if (strstr(line, "200 Ok")) {
rt_user *user = (rt_user *)writedata;
user = malloc(sizeof(rt_user));
line = strtok(NULL, "\n");
- while (line) {
- printf("Line:\n%s\n", line);
+ unsigned short i = 0;
+ while (line && i < nproperties) {
+ lines[i++] = line;
line = strtok(NULL, "\n");
}
+ for (unsigned short i = 0; i < nproperties; i++) {
+ char *token = strtok(lines[i], ":");
+#ifdef DEBUG
+#ifdef ANDROID
+ __android_log_print(ANDROID_LOG_DEBUG, "librtclient.so"
+ , "Key: %s", token);
+#else
+ fprintf(stderr, "Key: %s\n", token);
+#endif // ANDROID
+#endif // DEBUG
+ token = strtok(NULL, ":");
+#ifdef DEBUG
+#ifdef ANDROID
+ __android_log_print(ANDROID_LOG_DEBUG, "librtclient.so"
+ , "Value: %s", token);
+#else
+ fprintf(stderr, "Value: %s\n", token);
+#endif // ANDROID
+#endif // DEBUG
+ }
free(user);
}
+
return realsize;
}