diff options
author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-08 17:03:03 +0800 |
---|---|---|
committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-09-08 17:03:03 +0800 |
commit | efebfe44e1a1995b4562a7b0ac779aee71db9f77 (patch) | |
tree | fae0f59b4b20649a55b6a3806a2867f3b4f720ad | |
parent | 244a0959705dbbef1ad3741ed0ae4edba81f1480 (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.c | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -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; } |