int checkProvWithAPIKey(const char *pAPIKey, void (*cb)(void *p, int ok, const char *pMsg), void *cbRet){
   

   char bufReq[1024];
   char bufCfg[4096];
   
   const char *pFN_to_download[]   = {"settings.txt","tivi_cfg_glob.txt","tivi_cfg.xml","tivi_cfg1.xml",NULL};

   const char *pFNErr[]={"D-Err1","D-Err2","D-Err3","D-Err4","D-Err5","D-Err6",NULL};
   
   const char *p10_200ok="HTTP/1.0 200 OK";
   const char *p11_200ok="HTTP/1.1 200 OK";
   
   int iLen200ok=strlen(p10_200ok);
   
   int iCfgPos=0;
   
   for(int i=0;;i++){
      if(!pFN_to_download[i] || !pFN_to_save[i])break;
      snprintf(bufReq,sizeof(bufReq)-1,"%s/provisioning/silent_phone/%s?api_key=%s",provisioningLink,pFN_to_download[i],pAPIKey);
#ifdef ANDROID
      androidLog("++++ Provisioning request: %s", bufReq);
#endif
      int iRespContentLen=0;
      char* p=download_page2(&bufReq[0], &bufCfg[0], sizeof(bufCfg)-100, iRespContentLen,cb,cbRet);
      if(!p && i>2){
         // we have 1 account
         break;
      }

      if(!p || (strncmp(&bufCfg[0],p10_200ok,iLen200ok) && strncmp(&bufCfg[0],p11_200ok,iLen200ok))){
         if(i>2){
            // we have 1 account
            break;
         }
         char b[1000]; snprintf(b, sizeof(b), "Cannot load: %s, code: %.*s", pFN_to_download[i], 990, bufCfg);
        cb(cbRet,0, b);
//         cb(cbRet,0,pFNErr[i]);
         return -2;
      }
      cb(cbRet,1,pFN_to_save[i]);

      void saveCfgFile(const char *fn, void *p, int iLen);
      int saveCfgFile(int iNextPosToTest, void *p, int iLen);
#if 0
#ifndef PROV_TEST
      saveCfgFile(pFN_to_save[i],p,iRespContentLen);
#endif

      printf("Saving %s content=[%.*s]\n",pFN_to_save[i], iRespContentLen,p);
#else
      
      if(strncmp("tivi_cfg", pFN_to_save[i],8) || 0==strcmp("tivi_cfg_glob.txt", pFN_to_download[i])){
#ifndef PROV_TEST
         saveCfgFile(pFN_to_save[i],p,iRespContentLen);
#endif
         
       //  printf("Saving %s content=[%.*s]\n",pFN_to_save[i], iRespContentLen,p);
      }
      else{
         iCfgPos=saveCfgFile(iCfgPos, p,iRespContentLen);
         //printf("Saving pos=%d content=[%.*s]\n",iCfgPos-1, iRespContentLen,p);
      }
      
#endif
   }
   cb(cbRet,1,"OK");
   iProvisioned=1;
   return 0;
}
Esempio n. 2
0
void error(const FunctionCallbackInfo<Value>& args) {
    androidLog(ANDROID_LOG_ERROR, args);
}
Esempio n. 3
0
void info(const FunctionCallbackInfo<Value>& args) {
    androidLog(ANDROID_LOG_INFO, args);
}
Esempio n. 4
0
void warn(const FunctionCallbackInfo<Value>& args) {
    androidLog(ANDROID_LOG_WARN, args);
}
Esempio n. 5
0
void log(const FunctionCallbackInfo<Value>& args) {
    androidLog(ANDROID_LOG_DEBUG, args);
}