int gb28181_init_env(pSipEnv *env) { TRACE("Init GB28181 env\n"); //constly SYSCONF_t *sysconf = SYSCONF_dup(); pSipEnv p = (pSipEnv)calloc(1,sizeof(sSipEnv)); *env = p; char devip[20]; SOCK_gethostname(devip); GB_ASSERT(*env,"Calloc env Node failed\n"); printf("calloc env hdr node %p\n",*env); SIP_ENV_insert(p,"Model",sysconf->ipcam.info.device_model); SIP_ENV_insert(p,"UserAgent",sysconf->ipcam.info.device_name); SIP_ENV_insert(p,"Firmware",sysconf->ipcam.info.software_version); SIP_ENV_insert(p,"MaxAlarm","1"); SIP_ENV_insert(p,"MaxCamera","1"); SIP_ENV_insert(p,"Manufacturer","JUAN"); // variable Gb28181Conf_t gb_conf; memset(&gb_conf, 0, sizeof(Gb28181Conf_t)); gb28181_read_env(&gb_conf,sizeof(Gb28181Conf_t)); if(strlen(gb_conf.SipServerId) > 0) //if(0) { TRACE("use the env in the flash,SipServerId:%s:%d\n",gb_conf.SipServerId, strlen(gb_conf.SipServerId)); SIP_ENV_insert(p,"Realm",gb_conf.LoginDomain); SIP_ENV_insert(p,"SipServerId",gb_conf.SipServerId); SIP_ENV_insert(p,"SipServerIp",gb_conf.SipServerIp); SIP_ENV_insert(p,"SipServerPort",ITOA(gb_conf.SipServerPort)); SIP_ENV_insert(p,"UserId",gb_conf.UserId); SIP_ENV_insert(p,"UserPwd",gb_conf.UserPwd); SIP_ENV_insert(p,"DevPort",ITOA(GB28181_DEFAULT_DEV_PORT)); SIP_ENV_insert(p,"DevIp",devip); SIP_ENV_insert(p,"AliveTime",ITOA(gb_conf.AliveTime)); SIP_ENV_insert(p,"HeartBeatTime",ITOA(gb_conf.HeartBeatTime)); SIP_ENV_insert(p,"Alarm1",gb_conf.AlarmId[0]); SIP_ENV_insert(p,"Video1",gb_conf.VideoId[0]); } else{ // use the default gb28181 env TRACE("NULL gb28181 env ,use default env\n"); gb28181_write_env(&def_gb_conf,sizeof(Gb28181Conf_t)); SIP_ENV_insert(p,"Realm",def_gb_conf.LoginDomain); SIP_ENV_insert(p,"SipServerId",def_gb_conf.SipServerId); SIP_ENV_insert(p,"SipServerIp",def_gb_conf.SipServerIp); SIP_ENV_insert(p,"SipServerPort",ITOA(def_gb_conf.SipServerPort)); SIP_ENV_insert(p,"UserId",def_gb_conf.UserId); SIP_ENV_insert(p,"UserPwd",def_gb_conf.UserPwd); SIP_ENV_insert(p,"DevIp",devip); SIP_ENV_insert(p,"DevPort",ITOA(GB28181_DEFAULT_DEV_PORT)); SIP_ENV_insert(p,"AliveTime",ITOA(def_gb_conf.AliveTime)); SIP_ENV_insert(p,"HeartBeatTime",ITOA(def_gb_conf.HeartBeatTime)); SIP_ENV_insert(p,"Alarm1",def_gb_conf.AlarmId[0]); SIP_ENV_insert(p,"Video1",def_gb_conf.VideoId[0]); } return 0; }
char *itoa(unsigned n) { int sign = 0; int i = -1; char *p = NULL; p = malloc(CHAR_BUF); if ((sign = n) < 0) { p[0] = '-'; sign = -1; i = 0; n = -n; } do { p[++i] = ITOA(n%10); } while (n = n/10); p[++i] = '\0'; if (sign == -1) { reverse(p, 1, i-1); return p; } reverse(p, 0, i-1); return p; }
//============================================================================= // Return the length of the given track //============================================================================= int CCDAudio::GetTrackLength(const int nTrack) { if(IsMediaInsert()) { const int nBuffSize = 64; TCHAR szTrack[10]; TCHAR szReqBuff[nBuffSize]; TCHAR szBuff[nBuffSize]; ITOA( nTrack, szTrack, 10 ); lstrcpy( szReqBuff, _T("status cdaudio length track ") ); lstrcat( szReqBuff, szTrack ); m_nErrorCode = mciSendString( szReqBuff, szBuff, nBuffSize, NULL ); if( m_nErrorCode != 0 ) { return 0; } TCHAR szMin[3], szSec[3]; STRNCPY( szMin, szBuff, 2 ); STRNCPY( szSec, (szBuff + 3), 2 ); return ((ATOI(szMin) * 60) + ATOI(szSec)); } return 0; }
void time_to_string(Time *t,char *out){ //sprintf("%d:%02d'%02d\"%02d",t->hour,t->min,t->sec,t->ms); out[0] = ITOA(t->hour); out[1] = ':'; out[2] = ITOA(t->min/10); out[3] = ITOA(t->min%10); out[4] = '\''; out[5] = ITOA(t->sec/10); out[6] = ITOA(t->sec%10); out[7] = '\"'; out[8] = ITOA(t->ms/100); out[9] = ITOA(t->ms%100/10); }
static inline char *_itoa(char *bufend, uintmax_t value) { const char *digits = "0123456789"; ITOA(bufend, value, 10, digits); return bufend; }
void CCalcFrameDlg::OnBnClickedBtJiecheng() { UpdateData(TRUE); InsertRecord(en_Record_fact); if ( (m_strOutPut.Find('.') != -1) || (m_strOutPut.Find('-') != -1) ) { m_strOutPut = TEXT("无效输入"); return; } int nInput = atoi(m_strOutPut); if ( nInput*5 > 10000 ) { m_strOutPut = TEXT("溢出"); UpdateData(FALSE); return; } int *pArray = new int[nInput*5]; for (int i=0;i<nInput*5;i++) pArray[i] = 1; int i=0,c=0,m=0; for(;nInput;nInput--) { for(c=i=0;i<=m;i++) pArray[i]=(c+=pArray[i]*nInput)%10,c/=10; while(c)pArray[++m]=c%10,c/=10; } m_strOutPut = TEXT(""); int nValue=0; //数字大于28位,用科学表示法显示 if( m>=32 ) { for (int i=0;i<=32;i++) { nValue = pArray[m--]; m_strOutPut.Insert(i,ITOA(nValue)); } m_strOutPut.Insert(1,'.'); m_strOutPut+=TEXT("e+"); CString str; str.Format(TEXT("%d"),m+33); m_strOutPut+=str; } else { for(int nIndex=0;m>=0;nIndex++) { nValue = pArray[m--]; m_strOutPut.Insert(nIndex,ITOA(nValue)); } } SafeDeleteArray(pArray); UpdateData(FALSE); }
bool CDataBase::Query(const char *query, CVarDefMap &mapQueryResult) { ADDTOCALLSTACK("CDataBase::Query"); mapQueryResult.Empty(); mapQueryResult.SetNumNew("NUMROWS", 0); if ( !m_connected ) return false; // Connection can only handle one query at a time, so lock the thread until the query finishes SimpleThreadLock lock(m_connectionMutex); int resultCode = mysql_query(m_socket, query); if ( resultCode == 0 ) { MYSQL_RES *result = mysql_store_result(m_socket); if ( !result ) return false; unsigned int num_fields = mysql_num_fields(result); char key[64]; if ( num_fields > COUNTOF(key) ) { // This check is not really needed, MySQL client should be able to handle the same columns amount of MySQL server (4096). // But since this value is too big and create an 4096 char array at -every- query call is not performance-friendly, maybe // it's better just use an smaller array to prioritize performance. g_Log.EventError("MySQL query returned too many columns [Max: %" FMTSIZE_T " / Cmd: \"%s\"]\n", COUNTOF(key), query); mysql_free_result(result); return false; } MYSQL_FIELD *fields = mysql_fetch_fields(result); mapQueryResult.SetNum("NUMROWS", mysql_num_rows(result)); mapQueryResult.SetNum("NUMCOLS", num_fields); int rownum = 0; char **row = NULL; char *pszKey = Str_GetTemp(); char *pszVal = NULL; while ( (row = mysql_fetch_row(result)) != NULL ) { for ( unsigned int i = 0; i < num_fields; i++ ) { pszVal = row[i]; if ( !rownum ) { mapQueryResult.SetStr(ITOA(i, key, 10), true, pszVal); mapQueryResult.SetStr(fields[i].name, true, pszVal); } sprintf(pszKey, "%d.%u", rownum, i); mapQueryResult.SetStr(pszKey, true, pszVal); sprintf(pszKey, "%d.%s", rownum, fields[i].name); mapQueryResult.SetStr(pszKey, true, pszVal); } rownum++; } mysql_free_result(result); return true; } else { g_Log.EventError("MySQL error #%u: %s [Cmd: \"%s\"]\n", mysql_errno(m_socket), mysql_error(m_socket), query); if ( (resultCode == CR_SERVER_GONE_ERROR) || (resultCode == CR_SERVER_LOST) ) Close(); return false; } }