sc_result utils_collect_identifiers_initialize() { utils_redis_host = sc_config_get_value_string(str_group_redis, str_key_redis_host); if (utils_redis_host == 0) utils_redis_host = "127.0.0.1"; utils_redis_port = sc_config_get_value_int(str_group_redis, str_key_redis_port); if (utils_redis_port == 0) utils_redis_port = 6379; utils_redis_timeout = sc_config_get_value_int(str_group_redis, str_key_redis_timeout); if (utils_redis_timeout == 0) utils_redis_timeout = 1500; // connect to redis redisCtx = connectToRedis(); // initialize agents event_add_idtf = sc_event_new(keynode_nrel_idtf, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_append_idtf, (fDeleteCallback)0); if (event_add_idtf == 0) return SC_RESULT_ERROR; event_add_main_idtf = sc_event_new(keynode_nrel_main_idtf, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_append_idtf, (fDeleteCallback)0); if (event_add_main_idtf == 0) return SC_RESULT_ERROR; event_add_sys_idtf = sc_event_new(keynode_nrel_system_identifier, SC_EVENT_ADD_OUTPUT_ARC, 0, agent_append_idtf, (fDeleteCallback)0); if (event_add_sys_idtf == 0) return SC_RESULT_ERROR; return SC_RESULT_OK; }
float sc_config_get_value_float(const char *group, const char *key) { const char *str_value = sc_config_get_value_string(group, key); if (str_value == 0) return SC_FALSE; return (float)atof(str_value); }
int sc_config_get_value_int(const char *group, const char *key) { const char *str_value = sc_config_get_value_string(group, key); if (str_value == 0) return 0; return atoi(str_value); }
sc_bool sc_config_get_value_boolean(const char *group, const char *key) { const char *str_value = sc_config_get_value_string(group, key); if (str_value == 0) return SC_FALSE; if (g_str_equal(str_value, "true") || g_str_equal(str_value, "1")) return SC_TRUE; return SC_FALSE; }
void sc_redis_config_initialize() { config_redis_host = sc_config_get_value_string(str_group_redis, str_key_redis_host); if (config_redis_host == 0) config_redis_host = g_strdup_printf("127.0.0.1"); else config_redis_host = g_strdup(config_redis_host); config_redis_port = sc_config_get_value_int(str_group_redis, str_key_redis_port); if (config_redis_port == 0) config_redis_port = 6379; config_redis_timeout = sc_config_get_value_int(str_group_redis, str_key_redis_timeout); if (config_redis_timeout == 0) config_redis_timeout = 1500; }
bool perform(ApiAiRequestParams const & params) { bool result = false; std::string responseString; /// TODO: add support of timezone and location std::string const postData = getPostJSON(params); curl_easy_setopt(m_curl, CURLOPT_POST, 1L); curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, postData.c_str()); curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYHOST, 0L); std::string const accessToken = sc_config_get_value_string("apiai", "access_token"); std::stringstream headersString; headersString << "Authorization: Bearer " << accessToken; curl_slist * headers = nullptr; headers = curl_slist_append(headers, headersString.str().c_str()); headers = curl_slist_append(headers, "Content-Type: application/json; charset=utf-8"); curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, CurlWrite_CallbackFunc_StdString); curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &responseString); // perform request CURLcode resultCode = curl_easy_perform(m_curl); std::string const error = curl_easy_strerror(resultCode); if (resultCode == CURLE_OK) { result = parseResponseJSON(responseString); } curl_slist_free_all(headers); return result; }