コード例 #1
0
int createUserOnWeb(const char *pUN, const char *pPWD,
                    const char *pEM, const char *pFN, const char *pLN,
                    void (*cb)(void *p, int ok, const char *pMsg), void *cbRet){

   int c, l = 0;
   int iRespContentLen=0;
   
   char bufResp[4096];
   char bufBody[4096];

   
   
   char url[1024];
   int ul = snprintf(url,sizeof(url)-10,"%s/v1/user/",provisioningLink);
   
   ul+=fixPostEncodingToken(&url[ul],sizeof(url)-10-ul,pUN,strlen(pUN));
   url[ul] = '/'; ul++; url[ul]=0;
 
   bufBody[0]='{';l = 1;
   
   c = t_addJSON(1, &bufBody[l], sizeof(bufBody)-l, "username", pUN);
   if(!c){
      cb(cbRet,0,"Please check Username field.");
      return -1;
   }
   l+=c;
   
   c = t_addJSON(0 , &bufBody[l], sizeof(bufBody)-l, "password", pPWD);
   if(!c){
      cb(cbRet,0,"Please check Password field.");
      return -1;
   }
   l+=c;
   
   c = t_addJSON(1 , &bufBody[l], sizeof(bufBody)-l, "email", pEM);
   if(!c){
      cb(cbRet,0,"Please check Email field.");
      return -1;
   }
   l+=c;
   
   c = t_addJSON(1 , &bufBody[l], sizeof(bufBody)-l, "first_name", pFN); l+=c;
   c = t_addJSON(1 , &bufBody[l], sizeof(bufBody)-l, "last_name", pLN); l+=c;

   bufBody[l - 1] = '}';//remove last , from JSON
   
   memset(bufResp,0,sizeof(bufResp));
   
   char *p=download_page2Loc(url, &bufResp[0], sizeof(bufResp)-50, iRespContentLen,cb,cbRet, "PUT", bufBody);
   
   if(!p){
      cb(cbRet,0,"Please check network connection.");//download json fail
      return -1;
   }
#ifdef PROV_TEST
   printf("rec[%.*s]\n",iRespContentLen,p);//rem
   printf("rec-t[%s]\n",bufResp);//rem
#endif
   
   /*
    {"last_name": "N", "hash": "7c4219a8bcdbfe71aaa7381a72c0b57d3471ee39", "keys": [], "active_st_device": null, "country_code": "", "silent_text": true, "subscription": {"expires": "1900-01-01T00:00:00Z", "has_expired": true}, "first_name": "J", "display_name": "J N", "avatar_url": null, "silent_phone": false, "force_password_change": false, "permissions": {"can_send_media": true, "silent_text": true, "can_receive_voicemail": false, "silent_desktop": false, "silent_phone": false, "conference_create"
    */
   
   char bufJSonValue[1024];
   l=findJSonToken(p,iRespContentLen,"result",&bufJSonValue[0],1023);
   if(l<=0){
      cb(cbRet,0,"ERR: Result is not found");
      return -1;
   }
   if(strcmp(&bufJSonValue[0],"success")){
      l=findJSonToken(p,iRespContentLen,"error_msg",&bufJSonValue[0],1023);
      if(l>0)
         cb(cbRet,-1,&bufJSonValue[0]);
      else{
         cb(cbRet,-1,"Could not download configuration!");
      }
      return -1;
   }
   
   void saveCfgFile(const char *fn, void *p, int iLen);
   saveCfgFile("userData.json", bufResp, iRespContentLen);

   return 0;
}
コード例 #2
0
ファイル: prov.cpp プロジェクト: ak-67/silent-phone-android
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);

      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;
}
コード例 #3
0
ファイル: Context.cpp プロジェクト: DarkMagicCK/UKN
    void Context::loadCfgFile(const UknString& name) {
        ContextCfg cfg;
        cfg.render_cfg.width = 800;
        cfg.render_cfg.height = 600;
        cfg.render_cfg.top = 0;
        cfg.render_cfg.left = 0;
        cfg.render_cfg.color_fmt = EF_RGBA8;
        cfg.render_cfg.depth_stencil_fmt = EF_D16;
        cfg.render_cfg.resizable = false;
        cfg.render_cfg.full_screen = false;
        cfg.render_cfg.show_mouse = true;
        cfg.render_cfg.sample_count = 0;
        cfg.render_cfg.sample_quality = 0;
        
        ConfigParserPtr configParser = AssetManager::Instance().load<ConfigParser>(name);
        if(configParser) {            
            if(configParser->toNode(L"/cfg/graphics")) {
                cfg.render_cfg.width        = configParser->getInt(L"width", cfg.render_cfg.width);
                cfg.render_cfg.height       = configParser->getInt(L"height", cfg.render_cfg.height);
                cfg.render_cfg.top          = configParser->getInt(L"top", cfg.render_cfg.top);
                cfg.render_cfg.left         = configParser->getInt(L"left", cfg.render_cfg.left);
                
                cfg.render_cfg.resizable    = configParser->getBool(L"resizable", cfg.render_cfg.resizable);
                cfg.render_cfg.show_mouse   = configParser->getBool(L"show_mouse", cfg.render_cfg.show_mouse);
                cfg.render_cfg.full_screen  = configParser->getBool(L"full_screen", cfg.render_cfg.full_screen);
                
                cfg.render_cfg.sample_count     = configParser->getInt(L"sample_count", cfg.render_cfg.sample_count);
                cfg.render_cfg.sample_quality   = configParser->getInt(L"sample_quality", cfg.render_cfg.sample_quality);
                
                UknString fmt_string;
                int fmt_id;
                
                fmt_string = configParser->getString(L"color_fmt", L"EF_ARGB8");
                fmt_id = fmt_string_to_element_format(fmt_string);
                if(fmt_id == -1) {
                    log_warning(format_string("ukn::Context::loadCfgFile: unknown color format %s, using EF_ARGB8", fmt_string.c_str()));
                    
                    cfg.render_cfg.color_fmt = (ElementFormat)fmt_id;
                }
                
                fmt_string = configParser->getString(L"depth_stencil_fmt", L"EF_D16");
                fmt_id = fmt_string_to_element_format(fmt_string);
                if(fmt_id == -1) {
                    log_warning(format_string("ukn::Context::loadCfgFile: unknown depth stencil format %s, using EF_D16", fmt_string.c_str()));
                    
                    cfg.render_cfg.depth_stencil_fmt = (ElementFormat)fmt_id;
                }
            }
            
            if(configParser->toNode(L"/cfg/plugins")) {
                cfg.graphic_factory_name = configParser->getString(L"graphic_factory", L"");
            }
        } else {
            log_warning(L"ukn::Context::loadCfgFile: unable to open config file " + name);
        }
        
        setCfg(cfg);

		
		if(!configParser) {
			saveCfgFile(L"config.xml");
		}
    }