Esempio n. 1
0
int sql_find_buddy_fd(cs_request_t *req, sqlite3 *db)
{
    if (req == NULL || req->name == NULL || 
        req->buddy_name == NULL || db == NULL) {
        E("parameter error.");
        return -1;
    }

    char *query_line = (char *)cs_malloc(sizeof(char) * QUERY_LEN_MAX);
    if (query_line == NULL) {
        E("cs_malloc() failed.");
        return -1;
    }

    sprintf(query_line, "select * from users where name='%s'", 
            req->buddy_name);
    DS(query_line);

    int fd = 0;
    int ret = sqlite3_exec(db, query_line, sql_buddy_fd_cb, &fd, NULL);
    if (ret != SQLITE_OK || fd < 0) {
        E("sqlite3_exec() failed.");
        DD(fd);
        cs_free(&query_line);
        return -1;
    }

    cs_free(&query_line);

    D(GREEN"user %s fd is %d.", req->buddy_name, fd);
    return fd;
}
Esempio n. 2
0
/* Called by:  zxid_soap_call_hdr_body, zxid_wsc_call */
struct zx_root_s* zxid_soap_call_raw(zxid_conf* cf, struct zx_str* url, struct zx_e_Envelope_s* env, char** ret_enve)
{
#ifdef USE_CURL
  struct zx_root_s* r;
  struct zx_str* ret;
  struct zx_str* ss;
  char soap_action_buf[1024];
  char* soap_act;
  const char* env_start;

  ss = zx_easy_enc_elem_opt(cf, &env->gg);
  DD("ss(%.*s) len=%d", ss->len, ss->s, ss->len);

  if (cf->soap_action_hdr && strcmp(cf->soap_action_hdr,"#inhibit")) {
    if (!strcmp(cf->soap_action_hdr,"#same")) {
      if (env->Header && env->Header->Action && ZX_GET_CONTENT_S(env->Header->Action)) {
	snprintf(soap_action_buf,sizeof(soap_action_buf), "SOAPAction: \"%.*s\"", ZX_GET_CONTENT_LEN(env->Header->Action), ZX_GET_CONTENT_S(env->Header->Action));
	soap_action_buf[sizeof(soap_action_buf)-1] = 0;
	soap_act = soap_action_buf;
	D("SOAPaction(%s)", soap_action_buf);
      } else {
	ERR("e:Envelope/e:Headers/a:Action SOAP header is malformed %p", env->Header);
      }
    } else {
      snprintf(soap_action_buf,sizeof(soap_action_buf), "SOAPAction: \"%s\"", cf->soap_action_hdr);
      soap_action_buf[sizeof(soap_action_buf)-1] = 0;
      soap_act = soap_action_buf;
    }
  } else
    soap_act = 0;
  
  ret = zxid_http_post_raw(cf, url->len, url->s, ss->len, ss->s, soap_act);
  zx_str_free(cf->ctx, ss);
  if (ret_enve)
    *ret_enve = ret?ret->s:0;
  if (!ret)
    return 0;
  
  env_start = zxid_locate_soap_Envelope(ret->s);
  if (!env_start) {
    ERR("SOAP response does not have Envelope element url(%.*s)", url->len, url->s);
    D_XML_BLOB(cf, "NO ENVELOPE SOAP RESPONSE", ret->len, ret->s);
    ZX_FREE(cf->ctx, ret);
    return 0;
  }

  cf->ctx->top1 = 1;  /* Stop parsing after first toplevel <e:Envelope> */
  r = zx_dec_zx_root(cf->ctx, ret->len - (env_start - ret->s), env_start, "soap_call");
  if (!r || !r->Envelope || !r->Envelope->Body) {
    ERR("Failed to parse SOAP response url(%.*s)", url->len, url->s);
    D_XML_BLOB(cf, "BAD SOAP RESPONSE", ret->len, ret->s);
    ZX_FREE(cf->ctx, ret);
    return 0;
  }
  return r;
#else
  ERR("This copy of zxid was compiled to NOT use libcurl. SOAP calls (such as Artifact profile and WSC) are not supported. Add -DUSE_CURL (make ENA_CURL=1) and recompile. %d", 0);
  return 0;
#endif
}
Esempio n. 3
0
void uv_orb::fillDeltagrids(const std::string& file){

	E_delta.clear();L_delta.clear();Delta.clear();
    E_delta = create_range(E0,Emax,NE);
    L_delta = std::vector<VecDoub>(NE,VecDoub(NL,0.));
    Delta = std::vector<VecDoub>(NE,VecDoub(NL,0.));
    #pragma omp parallel for schedule (dynamic)
    for(int i=0; i<NE;i++){
        double R = Pot->R_E(E_delta[i]);
        for(double j=0;j<NL;j++){
            L_delta[i][j] = Pot->L_circ(R)*(j*0.8/(double)(NL-1)+0.001);
            find_best_delta DD(Pot, E_delta[i], L_delta[i][j]);
            Delta[i][j]=DD.delta(R*.9);
            if(Delta[i][j]<0. or Delta[i][j]!=Delta[i][j])
            	Delta[i][j]=R/5.;
            std::cerr<<"DeltaGrid: "
            	<<OUTPUT(E_delta[i])
            	<<OUTPUT(L_delta[i][j])
            	<<OUTPUT(R)
            	<<OUTPUTE(Delta[i][j]);
        }
    }
    std::cerr<<"DeltaGrid calculated: NE = "<<NE<<", NL = "<<NL<<std::endl;

    std::ofstream outfile; outfile.open(file);
	for(int i=0;i<NE;++i)
		for(int j=0;j<NL;++j)
		outfile<<E_delta[i]<<" "<<L_delta[i][j]<<" "<<Delta[i][j]<<std::endl;
	outfile.close();

}
Esempio n. 4
0
struct zx_str* zxid_oauth_dynclireg_client(zxid_conf* cf, zxid_cgi* cgi, zxid_ses* ses, const char* as_uri)
{
  struct zx_str* res;
  char* azhdr;
  char* req = zxid_mk_oauth2_dyn_cli_reg_req(cf);
  char* url = zxid_oauth_get_well_known_item(cf, as_uri, "\"dynamic_client_endpoint\"");
  char* p;
  if (iat) {
    azhdr = zx_alloc_sprintf(cf->ctx, 0, "Authorization: Bearer %s", iat);
  } else
    azhdr = 0;
  DD("url(%s) req(%s) iat(%s)", url, req, STRNULLCHKD(azhdr));
  if (_uma_authn) {
    p = url;
    url = zx_alloc_sprintf(cf->ctx, 0, "%s%c_uma_authn=%s", url, strchr(url,'?')?'&':'?', _uma_authn);
    ZX_FREE(cf->ctx, p);
  }
  D("url(%s) req(%s) iat(%s)", url, req, STRNULLCHKD(azhdr));
  res = zxid_http_cli(cf, -1, url, -1, req, ZXID_JSON_CONTENT_TYPE, azhdr, 0);
  ZX_FREE(cf->ctx, url);
  if (azhdr) ZX_FREE(cf->ctx, azhdr);
  ZX_FREE(cf->ctx, req);
  D("%.*s", res->len, res->s);
  ses->client_id = zx_json_extract_dup(cf->ctx, res->s, "\"client_id\"");
  ses->client_secret = zx_json_extract_dup(cf->ctx, res->s, "\"client_secret\"");
  return res;
}
Esempio n. 5
0
static void * slab_get_obj(kmem_cache_t *cachep, struct slab *slabp)
{
    if(cachep == NULL || slabp == NULL)
    {
        return NULL;
    }

    struct list_head *item = NULL;

    if(slabp->free == BUFCTL_END)
    {
        DD("not free obj.");
        return NULL;
    }
    void *objp = index_to_obj(cachep, slabp, slabp->free);
    uint32_t next = slab_bufctl(slabp)[slabp->free];
    inc_slab_use(slabp);
    set_slab_free(slabp, next);

    /* move to the full list*/
    if(slabp->inuse == cachep->obj_num)
    {
        item = &(slabp->list);
        list_del(item);
        list_add(item, &(cachep->kmem_lists.full));
    }

    dec_cache_free(cachep);

    return objp;
}
Esempio n. 6
0
void HelloWorld::update (float delta)
{
    CCLayer::update (delta);

    static double thinginterval =0;
    thinginterval+= delta;

    for (int i=0; i < bads.size(); ++i)
    {
        DD (bads[i]->GetID(), Telegram_AI, {   });
        DD (bads[i]->GetID(), Telegram_UPDATE, { delta });
    }
    thinginterval=0;


}
Esempio n. 7
0
/* Parse a given config.ini file and extract the list of SDK search paths
 * from it. Returns the number of valid paths stored in 'searchPaths', or -1
 * in case of problem.
 *
 * Relative search paths in the config.ini will be stored as full pathnames
 * relative to 'sdkRootPath'.
 *
 * 'searchPaths' must be an array of char* pointers of at most 'maxSearchPaths'
 * entries.
 */
static int
_getSearchPaths( IniFile*    configIni,
                 const char* sdkRootPath,
                 int         maxSearchPaths,
                 char**      searchPaths )
{
    char  temp[PATH_MAX], *p = temp, *end= p+sizeof temp;
    int   nn, count = 0;

    for (nn = 0; nn < maxSearchPaths; nn++) {
        char*  path;

        p = bufprint(temp, end, "%s%d", SEARCH_PREFIX, nn+1 );
        if (p >= end)
            continue;

        path = iniFile_getString(configIni, temp, NULL);
        if (path != NULL) {
            DD("    found image search path: %s", path);
            if (!path_is_absolute(path)) {
                p = bufprint(temp, end, "%s/%s", sdkRootPath, path);
                AFREE(path);
                path = ASTRDUP(temp);
            }
            searchPaths[count++] = path;
        }
    }
    return count;
}
void EsqCurto (ApontadorNo *Ap, short *Fim){
    ApontadorNo Ap1;
    if ((*Ap)->BitE == Horizontal){
        (*Ap)->BitE = Vertical;
        *Fim = TRUE;
        return;
    }
    if ((*Ap)->BitD == Horizontal){
        Ap1 = (*Ap)->Dir;
        (*Ap)->Dir = Ap1->Esq;
        Ap1->Esq = *Ap;
        *Ap = Ap1;
        if ((*Ap)->Esq->Dir->BitE == Horizontal){
            DE(&(*Ap)->Esq);
            (*Ap)->BitE = Horizontal;
        }
        *Fim = TRUE;
        return;
    }
    (*Ap)->BitD = Horizontal;
    if ((*Ap)->Dir->BitE == Horizontal){
        DE(Ap);
        *Fim = TRUE;
        return;
    }
    if ((*Ap)->Dir->BitD == Horizontal){
        DD(Ap);
        *Fim == TRUE;
    }
}
int buscarIzquierdaAVL( AVL *a, int dato, int *band )
{
   int retAux;
   
   retAux = eliminaAVL( &(*a)->izq, dato, band );
   
   if( *band )
   {
      if( (*a) -> fe == 0 )
      {
         (*a) -> fe = 1;
         *band = 0;
      }else
          if( (*a) -> fe == -1 )
               (*a) -> fe = 0;
          else
             {
               if( (*a) -> der -> fe >= 0 )
               {
                  if( (*a) -> der -> fe == 0 )
                      *band = 0;
                  
                   DD( a );
               }else
                   DI( a );   
             }
   }
   
   return( retAux );
}
int eliminaAVL( AVL *a, int dato, int *band )
{
 int ret;
 AVL aux;
 
 if( !*a )
   *band = ret = 0;
 else
    {
      if( dato == (*a) -> info )
      {
        ret = *band = 1;
        aux = *a;
        
        if( !(*a) -> izq )
           *a = (*a)-> der;
        else
          if( !(*a) -> der )
            *a = (*a) -> izq;
          else
             {
               recorreIzqDerAVL( &(*a) -> izq, &aux, band );
               (*a) -> info = aux -> info;
               
               if( *band )
               {
                 if( (*a) -> fe == 0 )
                 {
                   (*a) -> fe = 1;
                   *band = 0;
                 }else
                     if( (*a) -> fe == -1 )
                        (*a) -> fe = 0;
                     else
                        {
                          if( (*a) -> der -> fe >= 0 )
                          {
                            if( (*a) -> der -> fe == 0 )
                              *band = 0;
                       
                               DD( a );
                    
                          }else
                               DI( a );   
                        } 
                }
            }  
        
        free( aux );
        
       }else
           if( dato < (*a) -> info )
              ret = buscarIzquierdaAVL( a, dato, band );
            else
              if( dato > (*a) -> info )
                 ret=  buscarDerechaAVL( a, dato, band );
    }
   
   return( ret ); 
}
  int GaussianProcessNormal::precomputePrediction()
  {
    size_t n = mGPXX.size();
    size_t p = mMean->nFeatures();

    mKF = trans(mFeatM);
    inplace_solve(mL,mKF,ublas::lower_tag());
    //TODO: make one line
    matrixd DD(p,p);
    DD = prod(trans(mKF),mKF);
    utils::addToDiagonal(DD,mInvVarW);
    utils::cholesky_decompose(DD,mD);

    vectord vn = mGPY;
    inplace_solve(mL,vn,ublas::lower_tag());
    mWMap = prod(mFeatM,vn) + utils::ublas_elementwise_prod(mInvVarW,mW0);
    utils::cholesky_solve(mD,mWMap,ublas::lower());

    mVf = mGPY - prod(trans(mFeatM),mWMap);
    inplace_solve(mL,mVf,ublas::lower_tag());

    if (boost::math::isnan(mWMap(0)))
      {
	FILE_LOG(logERROR) << "Error in precomputed prediction. NaN found.";
	return -1;
      }
    return 0;
  }
Esempio n. 12
0
void IInsere(TipoReg x, TipoApont *Ap,TipoInclinacao *IAp, short *Fim)
{ if (*Ap == NULL)
  { *Ap = (TipoApont)malloc(sizeof(TipoNo));
    *IAp = Horizontal;  (*Ap)->Reg = x;
    (*Ap)->BitE = Vertical;  (*Ap)->BitD = Vertical;
    (*Ap)->Esq = NULL; (*Ap)->Dir = NULL; *Fim = FALSE;
    return;
  }
  if (x.Chave < (*Ap)->Reg.Chave)
  { IInsere(x, &(*Ap)->Esq, &(*Ap)->BitE, Fim);
    if (*Fim) return;
    if ((*Ap)->BitE != Horizontal) { *Fim = TRUE; return; }
    if ((*Ap)->Esq->BitE == Horizontal)
    { EE(Ap); *IAp = Horizontal; return; }
    if ((*Ap)->Esq->BitD == Horizontal) { ED(Ap); *IAp = Horizontal; }
    return;
  }
  //COMPARA플O AQUI
  if (x.Chave <= (*Ap)->Reg.Chave)
  { printf("Erro: Chave ja esta na arvore\n");
    *Fim = TRUE;
    return;
  }
  IInsere(x, &(*Ap)->Dir, &(*Ap)->BitD, Fim);
  if (*Fim) return;
  if ((*Ap)->BitD != Horizontal) { *Fim = TRUE;  return; }
  if ((*Ap)->Dir->BitD == Horizontal)
  { DD(Ap); *IAp = Horizontal; return;}
  if ((*Ap)->Dir->BitE == Horizontal) { DE(Ap); *IAp = Horizontal; }
}
Esempio n. 13
0
int InitTinyHashTable(HashTable *pstHashTable, key_t key , int iCreateFlags)
{
    int ret = 0;

    if(pstHashTable == NULL)
    {
        return -1;
    }

    if((ret = SequenceShmInit(&gstShm, CACHE_SEQ_KEY + key, 0666 | IPC_CREAT )) < 0)
    {   
        printf("SequenceShmInit error.ret = %d\n", ret);
        return -2; 
    } 
    
    if((ret = InitHashtable(pstHashTable, CACHE_HASHTABLE_BASE_KEY + key, HASH_MAX_ROW, sizeof(IndexNode),auNodeNums, auMods, iCreateFlags, compare)) < 0)
    {
        DD("_InitHashtable error.ret = %d\n", ret);
        return -3; 
    }

    /**ppstHashTable = g_pstHashTable;*/

    return 0;
}
//This method is call to compute solution
ERMsg CYHSSModel::OnExecuteDaily()
{
    ERMsg msg;

    //	if (!m_weather.IsHourly() )
    //m_weather.ComputeHourlyVariables();

    static const double THRESHOLD = 0;

    CDegreeDays DD(CDegreeDays::DAILY_AVERAGE, THRESHOLD);


    CYHSSStatVector stat(m_weather.GetEntireTPeriod(CTM(CTM::DAILY)));

    for (size_t y = 0; y < m_weather.size(); y++)
    {
        CTPeriod p = m_weather[y].GetEntireTPeriod();

        double tot_adult[366] = { 0 };
        double dd = 0;
        double cum_adult = 0;

        for (size_t jd = 0; jd < 90; jd++)
        {
            CTRef TRef = p.Begin() + jd;
            stat[TRef][O_L1] = 100;
            stat[TRef][O_AI] = 1;
        }

        for (size_t jd = 89; jd < m_weather[y].GetNbDays(); jd++)
        {
            CTRef TRef = p.Begin() + jd;
            const CWeatherDay& wDay = m_weather.GetDay(TRef);
            dd += DD.GetDD(wDay);

            double freq[9] = { 0 };
            double ai = ComputeStageFrequencies(dd, freq);

            //		adults alive
            tot_adult[jd] = freq[0];
            cum_adult += (tot_adult[jd] - tot_adult[jd - m_adultLongevity]) / m_adultLongevity;


            stat[TRef][O_DEGREE_DAY] = dd;

            stat[TRef][O_ADULT] = freq[0];
            stat[TRef][O_TRAP_CATCH] = cum_adult;

            for (size_t i = 0; i < 6; i++)
                stat[TRef][O_L1 + i] = freq[i + 3];

            stat[TRef][O_AI] = ai;
        }
    }

    SetOutput(stat);

    return msg;
}
Esempio n. 15
0
static void close_if(int handle)
{
    if(close(handle) < 0)  
    {
        DD("error in file %s line %d:\n", __FILE__, __LINE__);
        error(2,0L);
    }
} 
Esempio n. 16
0
/* A callback that is invoked when ADB debugging guest disconnects from the
 * service. */
static void
_adb_dbg_client_close(void* opaque)
{
    AdbDbgClient* const adb_dbg_client = (AdbDbgClient*)opaque;

    DD("ADB debugging client %p is disconnected from the guest.", adb_dbg_client);
    _adb_dbg_client_free(adb_dbg_client);
}
Esempio n. 17
0
/* Called by:  zxbus_load_acks, zxbus_load_ch_subs, zxbus_login_ent, zxbus_login_subj_hash */
struct hi_ent* zxbus_load_ent(struct hiios* shf, int len, const char* eid)
{
  char eid_buf[256];
  char sha1_name[28];
  char u_path[ZXID_MAX_BUF];
  struct hi_ent* ent;
  struct stat st;

  if (len == -1)
    len = strlen(eid);
  
  /* Check if already loaded */
  
  for (ent = shf->ents; ent; ent = ent->n) {
    DD("Checking eid(%.*s) against ent_%p->eid(%s)", len, eid, ent, ent->eid);
    if (!memcmp(ent->eid, eid, len) && !ent->eid[len]) {
      DD("Found ent_%p->eid(%s) io(%x) ache_%p", ent, ent->eid, ent->io?ent->io->fd:0xdeadbeef, ent->acks);
      return ent;
    }
  }
  
  /* Seems not. Prepare path and check if user directory exists. */

  if (len > sizeof(eid_buf)-2) {
    ERR("Entity ID too long (%.*s) len=%d", len, eid, len);
    return 0;
  }
  memcpy(eid_buf, eid, len);
  eid_buf[len] = 0;
  
  sha1_safe_base64(sha1_name, len, eid_buf);
  sha1_name[27] = 0;

  name_from_path(u_path, sizeof(u_path), "%s" ZXID_UID_DIR "/%s/", zxbus_path, sha1_name);
  if (stat(u_path, &st)==-1) {
    D("Entity(%.*s) does not exit. path(%s)", len, eid, u_path);
    return 0;
  }

  /* Add newly allocated entity to the list. */
  
  ent = zxbus_new_ent(shf, len, eid);
  D("Loaded ent_%p->eid(%s) io(%x) ache_%p",ent,ent->eid,ent->io?ent->io->fd:0xdeadbeef,ent->acks);
  return ent;
}
Esempio n. 18
0
int
http_client_init(void)
{
	if (http_redirect_url) {
		if ((http_c.url = strdup(http_redirect_url)) == NULL)
			return -1;
	}
	else {
		if ((http_c.url = strdup(config->acs->url)) == NULL)
			return -1;
	}

	DDF("+++ HTTP CLIENT CONFIGURATION +++\n");
	DD("url: %s\n", http_c.url);
	if (config->acs->ssl_cert)
		DD("ssl_cert: %s\n", config->acs->ssl_cert);
	if (config->acs->ssl_cacert)
		DD("ssl_cacert: %s\n", config->acs->ssl_cacert);
	if (!config->acs->ssl_verify)
		DD("ssl_verify: SSL certificate validation disabled.\n");
	DDF("--- HTTP CLIENT CONFIGURATION ---\n");

	curl = curl_easy_init();
	if (!curl) return -1;
	curl_easy_setopt(curl, CURLOPT_URL, http_c.url);
	curl_easy_setopt(curl, CURLOPT_USERNAME, config->acs->username ? config->acs->username : "");
	curl_easy_setopt(curl, CURLOPT_PASSWORD, config->acs->password ? config->acs->password : "");
	curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http_get_response);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
# ifdef DEVEL
	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
# endif /* DEVEL */
	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, fc_cookies);
	curl_easy_setopt(curl, CURLOPT_COOKIEJAR, fc_cookies);
	if (config->acs->ssl_cert)
		curl_easy_setopt(curl, CURLOPT_SSLCERT, config->acs->ssl_cert);
	if (config->acs->ssl_cacert)
		curl_easy_setopt(curl, CURLOPT_CAINFO, config->acs->ssl_cacert);
	if (!config->acs->ssl_verify)
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);

	log_message(NAME, L_NOTICE, "configured acs url %s\n", http_c.url);
	return 0;
}
Esempio n. 19
0
/* change passwd */
int sql_change_passwd(cs_request_t *req, sqlite3 *db, buf_t *wbuf)
{
    if (req == NULL || req->name == NULL || req->passwd == NULL ||
        db == NULL || wbuf == NULL || wbuf->data == NULL) {
        E("parameter error.");
        return -1;
    }

    char *query_line = (char *)cs_malloc(sizeof(char) * QUERY_LEN_MAX);
    if (query_line == NULL) {
        E("cs_malloc() failed.");
        DPSTR(wbuf);
        return -1;
    }

    /* check identify */
    sprintf(query_line, "select * from users where name='%s' and passwd='%s'", 
            req->name, req->passwd);
    DS(query_line);

    int sql_select_num = 0;
    int ret = sqlite3_exec(db, query_line, sql_check_identity_cb, 
                &sql_select_num, NULL);
    if (ret != SQLITE_OK || sql_select_num != 1) {
        /* no this user & passwd */
        E("sqlite3_exec() failed.");
        DD(sql_select_num);
        cs_free(&query_line);

        strncpy(wbuf->data, "err", 3);
        wbuf->len = 3;
        return -1;
    }

    /* update user info in users table */
    memset(query_line, '\0', QUERY_LEN_MAX);
    sprintf(query_line, "update users set passwd='%s' where name='%s'", req->content, req->name);
    DS(query_line);

    ret = sqlite3_exec(db, query_line, NULL, NULL, NULL);
    if (ret != SQLITE_OK) {
        E("sqlite3_exec() failed.");
        cs_free(&query_line);

        strncpy(wbuf->data, "err", 3);
        wbuf->len = 3;
        return -1;
    }

    strncpy(wbuf->data, "ok", 2);
    wbuf->len = 2;

    cs_free(&query_line);

    D(GREEN"user %s change passwd success.", req->name);
    return 0;
}
Esempio n. 20
0
cs_request_t cs_parse_request(char *buf)
{
    cs_request_t req;
    request_init(&req);

    if (buf == NULL) {
        E("parameter error.");
        return req;
    }

    char *buf_copy = strdup(buf);
    if (buf_copy == NULL) {
        E("strncup() failed.");
        return req;
    }

    char *str = buf_copy;
    char *token = NULL;
    char *saveptr = NULL;
    int i = 0;
    while (1) {
        token = strtok_r(str, ":", &saveptr);
        if (token == NULL)
            break;

        switch (i) {
            case 0:
                req.req_type = atoi(token);
                break;
            case 1:
                req.name = strdup(token);
                break;
            case 2:
                req.passwd = strdup(token);
                break;
            case 3:
                req.buddy_name = strdup(token);
                break;
            case 4:
                req.content = strdup(token);
                break;
            case 5:
                req.datetime = strdup(token);
                break;
            default:
                DD(i);
                break;
        }

        str = NULL;
        i++;
    }
    //request_dump(&req);

    cs_free(&buf_copy);
    return req;
}
Esempio n. 21
0
void EsqCurto(TipoApont *Ap, short *Fim)
{ /* Folha esquerda retirada => arvore curta na altura esquerda */
  TipoApont Ap1;
  if ((*Ap)->BitE == Horizontal)
  { (*Ap)->BitE = Vertical; *Fim = TRUE; return; }
  if ((*Ap)->BitD == Horizontal)
  { Ap1 = (*Ap)->Dir; (*Ap)->Dir = Ap1->Esq; Ap1->Esq = *Ap; *Ap = Ap1;
    if ((*Ap)->Esq->Dir->BitE == Horizontal)
    { DE(&(*Ap)->Esq); (*Ap)->BitE = Horizontal;}
    else if ((*Ap)->Esq->Dir->BitD == Horizontal)
         { DD(&(*Ap)->Esq); (*Ap)->BitE = Horizontal; }
    *Fim = TRUE;
    return;
  }
  (*Ap)->BitD = Horizontal;
  if ((*Ap)->Dir->BitE == Horizontal) { DE(Ap); *Fim = TRUE; return; }
  if ((*Ap)->Dir->BitD == Horizontal) {  DD(Ap); *Fim = TRUE; }
}
Esempio n. 22
0
/*-----------------------------------------------------------------------------
 *  初始化
 *-----------------------------------------------------------------------------*/
int InitRouter()
{
    int ret = 0;
    if((ret = _InitRouteTable(ROUTETABLE_BASE_KEY,1)) < 0)
    {
        DD("InitRouteTableShm ret = %d\n", ret);
        return -1;
    }
    return 0;
}
Esempio n. 23
0
void dijkstra(int source) {//源点为source
    for (int i = 0; i < MAXN; i++) dis[i] = inf;
    priority_queue <DD> pq;
    dis[source] = 0;
    pq.push(DD(source, 0));
    while (!pq.empty()) {
        DD temp = pq.top();
        pq.pop();
        int u = temp.v;
        if (temp.dis > dis[u]) continue; //之前扩展过
        for (int p = 0; p < (int) adj[u].size(); p++) {
            int v = adj[u][p].first;
            if (dis[v] > dis[u] + adj[u][p].second) {
                dis[v] = dis[u] + adj[u][p].second;
                pq.push(DD(v, dis[v]));
            }
        }
    }
}
static void
netPipe_wakeOn( void* opaque, int flags )
{
    NetPipe*  pipe = opaque;

    DD("%s: flags=%d", __FUNCTION__, flags);

    pipe->wakeWanted |= flags;
    netPipe_resetState(pipe);
}
Esempio n. 25
0
/* Returns path to the core hardware .ini file. This contains the
 * hardware configuration that is read by the core. The content of this
 * file is auto-generated before launching a core, but we need to know
 * its path before that.
 */
static int
_avdInfo_getCoreHwIniPath( AvdInfo* i, const char* basePath )
{
    i->coreHardwareIniPath = _getFullFilePath(basePath, CORE_HARDWARE_INI);
    if (i->coreHardwareIniPath == NULL) {
        DD("Path too long for %s: %s", CORE_HARDWARE_INI, basePath);
        return -1;
    }
    D("using core hw config path: %s", i->coreHardwareIniPath);
    return 0;
}
Esempio n. 26
0
/*-----------------------------------------------------------------------------
 *  初始化hash table
 *-----------------------------------------------------------------------------*/
int InitHashtable(HashTable *pstHashTable,key_t key, size_t uRowNum, size_t uNodeSize, size_t auNodeNums[], size_t auMods[], int iCreateFlags, Compare compare)
{
    int ret = 0;
    volatile char *pTable = NULL;

    if(pstHashTable == NULL || uRowNum == 0)
    {
        return -1;
    }

    /*key_t uShmKey =  CACHE_HASHTABLE_BASE_KEY + key;*/
    /*printf("uRowNum = %d uNodeSize = %d \n", uRowNum, uNodeSize);*/
    size_t dwTableSize = HashTableEvalTableSize(uRowNum, uNodeSize, auNodeNums);
    DD("HashTable size = %d\n", (int)dwTableSize);
    if(dwTableSize == 0)
    {
        return -2;
    }

    pTable =  GetShm(key, dwTableSize, 0666);
    if(pTable == NULL)
    {
        if(iCreateFlags == 0)
        {
            printf("shm not existd.should create! shmkey = 0x%x\n", key);
            return -3;
        }
        else if(iCreateFlags == 1)
        {
            if((ret = GetShm2((volatile void **)&pTable, key, dwTableSize, 0666 | IPC_CREAT)) < 0)
            {
                printf("GetShm2 error. %s\n", strerror(errno));
                return -4;
            }
            /*printf("first GetShm2 ret = %d\n", ret);*/
            bzero((void *)pTable,dwTableSize);
        }
        else 
        {
            return -5;
        }
    }
    /*printf("pTable = 0x%x\n", pTable);*/
    /*g_pstHashTable = (HashTable *)pTable;*/
    /*pTable += sizeof(HashTable);*/

    if((ret = HashTableInit(pstHashTable,(void *)pTable, uNodeSize,uRowNum, auNodeNums, auMods, iCreateFlags, compare)) < 0)
    {
        return -5;
    }

    /**ppstHashTable = g_pstHashTable;*/
    return 0;
}
Esempio n. 27
0
static void registerUnregisterFds() {
  int fd, fdMax;

  FD_ZERO(&curlSrc->fdRead);
  FD_ZERO(&curlSrc->fdWrite);
  FD_ZERO(&curlSrc->fdExc);
  curlSrc->fdMax = -1;
  /* What fds does libcurl want us to poll? */
  curl_multi_fdset(curlSrc->multiHandle, &curlSrc->fdRead,
                   &curlSrc->fdWrite, &curlSrc->fdExc, &curlSrc->fdMax);
  if ((curlSrc->fdMax < -1) || (curlSrc->fdMax > GLIBCURL_FDMAX)) {
	  DEBUG_FAILURE(("registerUnregisterFds: fdMax=%d\n", curlSrc->fdMax));
  }
  /*fprintf(stderr, "registerUnregisterFds: fdMax=%d\n", curlSrc->fdMax);*/
  assert(curlSrc->fdMax >= -1 && curlSrc->fdMax <= GLIBCURL_FDMAX);

  fdMax = curlSrc->fdMax;
  if (fdMax < curlSrc->lastPollFdMax) fdMax = curlSrc->lastPollFdMax;

  /* Has the list of required events for any of the fds changed? */
  for (fd = 0; fd <= fdMax; ++fd) {
    gushort events = 0;
    if (FD_ISSET(fd, &curlSrc->fdRead))  events |= GLIBCURL_READ;
    if (FD_ISSET(fd, &curlSrc->fdWrite)) events |= GLIBCURL_WRITE;
    if (FD_ISSET(fd, &curlSrc->fdExc))   events |= GLIBCURL_EXC;

    /* List of events unchanged => no (de)registering */
    if (events == curlSrc->lastPollFd[fd].events) continue;

    DD((stdout, "registerUnregisterFds: fd %d: old events %x, "
       "new events %x\n", fd, curlSrc->lastPollFd[fd].events, events));

    /* fd is already a lastPollFd, but event type has changed => do nothing.
       Due to the implementation of g_main_context_query(), the new event
       flags will be picked up automatically. */
    if (events != 0 && curlSrc->lastPollFd[fd].events != 0) {
      curlSrc->lastPollFd[fd].events = events;
      continue;
    }
    curlSrc->lastPollFd[fd].events = events;

    /* Otherwise, (de)register as appropriate */
    if (events == 0) {
      g_source_remove_poll(&curlSrc->source, &curlSrc->lastPollFd[fd]);
      curlSrc->lastPollFd[fd].revents = 0;
      D((stderr, "unregister fd %d\n", fd));
    } else {
      g_source_add_poll(&curlSrc->source, &curlSrc->lastPollFd[fd]);
      D((stderr, "register fd %d\n", fd));
    }
  }

  curlSrc->lastPollFdMax = curlSrc->fdMax;
}
int insAVL( AVL *a, int dato, int *band )
{
  int ret;
  
  if( !*a )
    ret = *band = creaNodoAVL( a , dato );
  else
    {
       if( dato < (*a) -> info )
       {
         ret = insAVL( &(*a) -> izq, dato, band );
         
         if( *band )
           if( (*a) -> fe == 0 )
              (*a) -> fe = -1;
           else
               if( (*a ) -> fe == 1 )
                  *band = (*a) -> fe = 0;
               else
                  {
                    if( (*a) -> izq -> fe > 0 )
                         ID( a );
                    else
                         II( a );
                    
                    *band = 0;
                  }
         }else
             if( dato > (*a) -> info )
             {
               ret = insAVL( &(*a) -> der, dato, band );
               
               if( *band )
                  if( (*a) -> fe == 0 )
                      (*a) -> fe = 1;
               else
                  if( (*a ) -> fe == -1 )
                      *band = (*a) -> fe = 0;
                  else
                     {
                       if( (*a) -> der -> fe >= 0 )
                            DD( a );
                       else
                            DI( a );
                       
                       *band = 0;
             }
         }else
               ret = *band = 0;
    }
    
    return( ret );
  
}
Esempio n. 29
0
void VideoCaptureNode::chooseDevice()
{
#if defined( VIDEOCAPTURE_SUPPORTED )
	DeviceDialog		DD( mDeviceIndex, mFormatIndex );

	if( DD.exec() == QDialog::Accepted )
	{
		setCurrentDevice( DD.deviceIdx(), DD.formatIdx() );
	}
#endif
}
Esempio n. 30
0
static pthread_t lthread_create(lthread_fn fn)
{
    int ret;
    pthread_t tid;

    ret = pthread_create(&tid, NULL,fn, NULL);

    DD("tid = %ld.",tid);

    return tid;
}