int getApiKeySipUserPass(const char *pSipUN, const char *pSipPWD, void (*cb)(void *p, int ok, const char *pMsg), void *cbRet){ /* /v1/me/device/[device_id]/ http://sccps.silentcircle.com/provisioning/silent_phone/tivi_cfg.xml?api_key=12345 http://sccps.silentcircle.com/provisioning/silent_phone/settings.txt?api_key=12345 http://sccps.silentcircle.com/provisioning/silent_phone/tivi_cfg_glob.txt?api_key=12345 */ char bufReq[1024]; char bufContent[1024]; const char *t_getDevID_md5(); const char *dev_id=t_getDevID_md5(); #define CHK_BUF \ if(l+100>sizeof(bufReq)){\ return -1;\ } int l=snprintf(bufReq,sizeof(bufReq)-10,"%s/v1/me/device/%s/api-key/",provisioningLink,dev_id); CHK_BUF char locPassword[128]; copyJSON_value(locPassword, pSipPWD, sizeof(locPassword)-1); char locUN[128]; copyJSON_value(locUN, pSipUN, sizeof(locUN)-1); l = snprintf(bufContent, sizeof(bufContent), "{\r\n" "\"username\": \"%s\",\r\n" "\"sip_password\": \"%s\"\r\n" "}\r\n",locUN, locPassword);//TODO encode pwd #undef CHK_BUF int r=getToken(&bufReq[0], &bufAPIKey[0],255,cb,cbRet,"POST",bufContent); if(r<0){ return -1; } cb(cbRet,1,"Configuration code ok"); return 0; }
static int t_addJSON(int canTrim, char *pos, int iSize, const char *tag, const char *value){ char bufJSonValue[1024]; copyJSON_value(bufJSonValue, value, sizeof(bufJSonValue)-1); if(canTrim)trim(bufJSonValue); if(!bufJSonValue[0] || iSize < 120 || strlen(value) > 80)return 0; return snprintf(pos, iSize, "\"%s\":\"%s\",", tag, bufJSonValue); }
int checkProvUserPass(const char *pUN, const char *pPWD, void (*cb)(void *p, int ok, const char *pMsg), void *cbRet){ /* /v1/me/device/[device_id]/ http://sccps.silentcircle.com/provisioning/silent_phone/tivi_cfg.xml?api_key=12345 http://sccps.silentcircle.com/provisioning/silent_phone/settings.txt?api_key=12345 http://sccps.silentcircle.com/provisioning/silent_phone/tivi_cfg_glob.txt?api_key=12345 */ char bufReq[1024]; char bufContent[1024]; const char *t_getDevID_md5(); const char *t_getDev_name(); const char *t_getVersion(); const char *dev_id=t_getDevID_md5(); const char *dev_name=t_getDev_name(); #define CHK_BUF \ if(l+100>sizeof(bufReq)){\ return -1;\ } int l=snprintf(bufReq,sizeof(bufReq)-10,"%s/v1/me/device/%s/",provisioningLink,dev_id); CHK_BUF #ifdef __APPLE__ const char *dev_class = "ios"; #endif #if defined(_WIN32) || defined(_WIN64) const char *dev_class = "windows"; #endif #if defined(ANDROID_NDK) const char *dev_class = "android"; #endif #if defined(__linux__) && !defined(ANDROID_NDK) const char *dev_class = "Linux"; #endif char locPassword[128]; copyJSON_value(locPassword, pPWD, sizeof(locPassword)-1); char locUN[128]; copyJSON_value(locUN, pUN, sizeof(locUN)-1); l = snprintf(bufContent, sizeof(bufContent), "{\r\n" "\"username\": \"%s\",\r\n" "\"password\": \"%s\",\r\n" "\"device_name\": \"%s\",\r\n" #if defined (_WIN32) || defined(_WIN64) "\"app\": \"silent_phone_free\",\r\n" #else "\"app\": \"silent_phone\",\r\n" #endif "\"device_class\": \"%s\",\r\n" "\"version\": \"%s\"\r\n" "}\r\n",locUN, locPassword, dev_name, dev_class, t_getVersion());//TODO encode pwd CHK_BUF #undef CHK_BUF int r=getToken(&bufReq[0], &bufAPIKey[0],255,cb,cbRet,"PUT",bufContent); if(r<0){ return -1; } cb(cbRet,1,"Configuration code ok"); return checkProvWithAPIKey(&bufAPIKey[0],cb, cbRet);; }