From efebfe44e1a1995b4562a7b0ac779aee71db9f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Sun, 8 Sep 2019 17:03:03 +0800 Subject: 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. --- rtclient.c | 30 +++++++++++++++++++++++++++--- 1 file 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; } -- cgit v1.2.3