*/
int http_request_post(const char *url, const char *json, char **response, long *response_code);
-#endif
\ No newline at end of file
+char *http_request_get_url(char *default_api, char *api_key);
+
+#endif
#include <glib.h>
#include <gio/gio.h>
#include <string.h>
+#include <stdlib.h>
#include "log.h"
-#define BASE_URL "http://son.tizen.online"
#define PATH_API_LAP "/api/lap"
+#define CONFIG_LAP_API_KEY "lap"
typedef struct {
char *ap_mac;
lap_api_post_request_response_t *response = g_new0(lap_api_post_request_response_t, 1);
char *json = lap_info_serializer_serialize(context->lap);
- int retval = http_request_post(BASE_URL""PATH_API_LAP, json, &(response->response_msg), &(response->response_code));
+
+ char *url = http_request_get_url(PATH_API_LAP, CONFIG_LAP_API_KEY);
+
+ int retval = http_request_post(url, json, &(response->response_msg), &(response->response_code));
+
+ _D("URL FROM CONFIG (LAP POST): %s", url);
+ free(url);
g_free(json);
if (retval != 0) {
lap_api_get_request_response_t *response = g_new0(lap_api_get_request_response_t, 1);
char *response_json = NULL;
+ char *url_with_api = http_request_get_url(PATH_API_LAP, CONFIG_LAP_API_KEY);
- GString *url = g_string_new(BASE_URL""PATH_API_LAP"?apMac=");
+ GString *url = g_string_new(url_with_api);
+ g_string_append(url, "?apMac=");
g_string_append(url, context->ap_mac);
+ free(url_with_api);
+ _D("URL FROM CONFIG (LAP GET): %s", url);
+
int retval = http_request_get(url->str, &response_json, &(response->response_code));
g_string_free(url, TRUE);
#include <glib.h>
#include <gio/gio.h>
#include <string.h>
+#include <stdlib.h>
#include "log.h"
-#define BASE_URL "http://son.tizen.online"
#define PATH_API_RACING "/api/racing"
+#define CONFIG_CAR_API_KEY "car"
typedef struct {
char *ap_mac;
car_api_post_request_response_t *response = g_new0(car_api_post_request_response_t, 1);
char *json = car_info_serializer_serialize(context->car);
- int retval = http_request_post(BASE_URL""PATH_API_RACING, json, &(response->response_msg), &(response->response_code));
+
+ char *url = http_request_get_url(PATH_API_RACING, CONFIG_CAR_API_KEY);
+
+ int retval = http_request_post(url, json, &(response->response_msg), &(response->response_code));
g_free(json);
+ _D("URL FROM CONFIG (RACING POST): %s", url);
+ free(url);
+
if (retval != 0) {
GError *err = g_error_new(G_ERROR_DOMAIN, retval, "http_request_post failed!");
g_task_return_error(task, err);
car_api_get_request_response_t *response = g_new0(car_api_get_request_response_t, 1);
char *response_json = NULL;
- GString *url = g_string_new(BASE_URL""PATH_API_RACING"?apMac=");
+ char *url_with_api = http_request_get_url(PATH_API_RACING, CONFIG_CAR_API_KEY);
+
+ GString *url = g_string_new(url_with_api);
+ g_string_append(url, "?apMac=");
g_string_append(url, context->ap_mac);
+ free(url_with_api);
+ _D("URL FROM CONFIG (RACING GET): %s", url);
+
int retval = http_request_get(url->str, &response_json, &(response->response_code));
g_string_free(url, TRUE);
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
+#include <stdbool.h>
#include "log.h"
+#include "config.h"
+
+#define BASE_URL "http://son.tizen.online"
+#define CONFIG_CLOUD_GROUP "cloud"
+#define CONFIG_URL "url"
static size_t _response_write(void *ptr, size_t size, size_t nmemb, void *data);
return real_size;
}
+
+char *http_request_get_url(char *default_api, char *api_key)
+{
+ char *url;
+ char *api;
+ char *url_with_api = calloc(PATH_MAX, sizeof(char));
+
+ bool modified = config_get_string_or_set_default(CONFIG_CLOUD_GROUP, CONFIG_URL, BASE_URL, &url);
+ modified |= config_get_string_or_set_default(CONFIG_CLOUD_GROUP, api_key, default_api, &api);
+
+ snprintf(url_with_api, PATH_MAX, "%s%s", url, api);
+
+ if (modified) {
+ config_save();
+ }
+
+ return url_with_api;
+}