inline void setupUpscalingConditions(const GridInterface& g, int bct, int pddir, double pdrop, double bdy_sat, bool twodim_hack, BCs& bcs) { // Caution: This enum is copied from Upscaler.hpp. enum BoundaryConditionType { Fixed = 0, Linear = 1, Periodic = 2, PeriodicSingleDirection = 3, Noflow = 4 }; if (bct < 0 || bct > 2) { THROW("Illegal boundary condition type (0-2 are legal): " << bct); // Later on, we may allow 3 and 4. } BoundaryConditionType bctype = static_cast<BoundaryConditionType>(bct); ASSERT(pddir >=0 && pddir <= 2); // Flow conditions. switch (bctype) { case Fixed: { // ASSERT(!g.uniqueBoundaryIds()); bcs.clear(); bcs.resize(7); bcs.flowCond(2*pddir + 1) = FlowBC(FlowBC::Dirichlet, pdrop); bcs.flowCond(2*pddir + 2) = FlowBC(FlowBC::Dirichlet, 0.0); bcs.satCond(2*pddir + 1) = SatBC(SatBC::Dirichlet, bdy_sat); // The only possible inflow location. for (int i = 0; i < 7; ++i) { bcs.setCanonicalBoundaryId(i, i); } break; } case Linear: { // ASSERT(g.uniqueBoundaryIds()); createLinear(bcs, g, pdrop, pddir, bdy_sat, twodim_hack); break; } case Periodic: { // ASSERT(g.uniqueBoundaryIds()); FlowBC fb(FlowBC::Periodic, 0.0); boost::array<FlowBC, 6> fcond = {{ fb, fb, fb, fb, fb, fb }}; fcond[2*pddir] = FlowBC(FlowBC::Periodic, pdrop); fcond[2*pddir + 1] = FlowBC(FlowBC::Periodic, -pdrop); SatBC sb(SatBC::Periodic, 0.0); boost::array<SatBC, 6> scond = {{ sb, sb, sb, sb, sb, sb }}; if (twodim_hack) { // fcond[2] = FlowBC(FlowBC::Neumann, 0.0); // fcond[3] = FlowBC(FlowBC::Neumann, 0.0); fcond[4] = FlowBC(FlowBC::Neumann, 0.0); fcond[5] = FlowBC(FlowBC::Neumann, 0.0); // scond[2] = SatBC(SatBC::Dirichlet, 1.0); // scond[3] = SatBC(SatBC::Dirichlet, 1.0); scond[4] = SatBC(SatBC::Dirichlet, 1.0); scond[5] = SatBC(SatBC::Dirichlet, 1.0); } createPeriodic(bcs, g, fcond, scond); break; } default: THROW("Error in switch statement, should never be here."); } // Default transport boundary conditions are used. }
void ep2_curve_set_twist(int type) { char str[2 * FP_BYTES + 1]; ctx_t *ctx = core_get(); ep2_t g; fp2_t a; fp2_t b; bn_t r; ep2_null(g); fp2_null(a); fp2_null(b); bn_null(r); ctx->ep2_is_twist = 0; if (type == EP_MTYPE || type == EP_DTYPE) { ctx->ep2_is_twist = type; } else { return; } TRY { ep2_new(g); fp2_new(a); fp2_new(b); bn_new(r); switch (ep_param_get()) { #if FP_PRIME == 158 case BN_P158: ASSIGN(BN_P158); break; #elif FP_PRIME == 254 case BN_P254: ASSIGN(BN_P254); break; #elif FP_PRIME == 256 case BN_P256: ASSIGN(BN_P256); break; #elif FP_PRIME == 382 case BN_P382: ASSIGN(BN_P382); break; #elif FP_PRIME == 455 case B12_P455: ASSIGN(B12_P455); break; #elif FP_PRIME == 638 case BN_P638: ASSIGN(BN_P638); break; case B12_P638: ASSIGN(B12_P638); break; #endif default: (void)str; THROW(ERR_NO_VALID); break; } fp2_zero(g->z); fp_set_dig(g->z[0], 1); g->norm = 1; ep2_copy(&(ctx->ep2_g), g); fp_copy(ctx->ep2_a[0], a[0]); fp_copy(ctx->ep2_a[1], a[1]); fp_copy(ctx->ep2_b[0], b[0]); fp_copy(ctx->ep2_b[1], b[1]); bn_copy(&(ctx->ep2_r), r); bn_set_dig(&(ctx->ep2_h), 1); /* I don't have a better place for this. */ fp_prime_calc(); #if defined(EP_PRECO) ep2_mul_pre((ep2_t *)ep2_curve_get_tab(), &(ctx->ep2_g)); #endif } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { ep2_free(g); fp2_free(a); fp2_free(b); bn_free(r); } }
Thread::Thread(int pri, size_t stack): _cancel(cancelDefault), _start(NULL), priv(new ThreadImpl(threadTypeNormal)) { #ifdef WIN32 if(!_main) { _self.setKey(NULL); _main = this; setName("main()"); } else #ifdef WIN32 _name[0] = 0; #else snprintf(_name, sizeof(_name), "%d", getId()); #endif _parent = Thread::get(); if(_parent) priv->_throw = _parent->priv->_throw; else _parent = this; priv->_cancellation = CreateEvent(NULL, TRUE, FALSE, NULL); if(!priv->_cancellation) THROW(this); if(stack <= _autostack) priv->_stack = 0; else priv->_stack = stack; if(pri > 2) pri = 2; if(pri < -2) pri = -2; if(Process::isRealtime() && pri < 0) pri = 0; switch(pri) { case 1: priv->_priority = THREAD_PRIORITY_ABOVE_NORMAL; break; case -1: priv->_priority = THREAD_PRIORITY_BELOW_NORMAL; break; case 2: priv->_priority = THREAD_PRIORITY_HIGHEST; break; case -2: priv->_priority = THREAD_PRIORITY_LOWEST; break; default: priv->_priority = THREAD_PRIORITY_NORMAL; } #else int salign; pthread_attr_init(&priv->_attr); pthread_attr_setdetachstate(&priv->_attr, PTHREAD_CREATE_JOINABLE); #ifdef PTHREAD_STACK_MIN if(stack && stack <= _autostack) pthread_attr_setstacksize(&priv->_attr, _autostack); else if(stack > _autostack) { if(stack < PTHREAD_STACK_MIN) stack = PTHREAD_STACK_MIN; else // align to nearest min boundry { salign = stack / PTHREAD_STACK_MIN; if(stack % PTHREAD_STACK_MIN) ++salign; stack = salign * PTHREAD_STACK_MIN; } if(stack && pthread_attr_setstacksize(&priv->_attr, stack)) { #ifdef CCXX_EXCEPTIONS switch(Thread::getException()) { case throwObject: throw(this); return; #ifdef COMMON_STD_EXCEPTION case throwException: throw(ThrException("no stack space")); return; #endif default: return; } #else return; #endif } } #endif #ifndef __FreeBSD__ #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING #ifdef HAVE_SCHED_GETSCHEDULER #define __HAS_PRIORITY_SCHEDULING__ if(pri < 0 && Process::isRealtime()) pri = 0; if(pri) { struct sched_param sched; int policy; policy = sched_getscheduler(0); if(policy < 0) { #ifdef CCXX_EXCEPTIONS switch(Thread::getException()) { case throwObject: throw(this); return; #ifdef COMMON_STD_EXCEPTION case throwException: throw(ThrException("invalid scheduler")); return; #endif default: return; } #else return; #endif } sched_getparam(0, &sched); pri = sched.sched_priority - pri; if(pri > sched_get_priority_max(policy)) pri = sched_get_priority_max(policy); if(pri < sched_get_priority_min(policy)) pri = sched_get_priority_min(policy); sched.sched_priority = pri; pthread_attr_setschedpolicy(&priv->_attr, policy); pthread_attr_setschedparam(&priv->_attr, &sched); } #endif // ifdef HAVE_SCHED_GETSCHEDULER #endif // ifdef _POSIX_THREAD_PRIORITY_SCHEDULING #endif // ifndef __FreeBSD__ #ifdef __HAS_PRIORITY_SCHEDULING__ if(!pri) pthread_attr_setinheritsched(&priv->_attr, PTHREAD_INHERIT_SCHED); #else pthread_attr_setinheritsched(&priv->_attr, PTHREAD_INHERIT_SCHED); #endif _parent = getThread(); priv->_throw = _parent->priv->_throw; _cancel = cancelInitial; #endif // WIN32 }
void LoneFallibleBase::throwErr() const { THROW (LoneFallibleBase::UsedInInvalidStateErr()); }
void ParseRuleMgr::initRule () { DEFINE_QUERY (qry); for (int i=1; i<=MAX_TLV_FLAGS; i++) m_pParseRule[i] = 0; qry.setSQL (" Select nvl(Max(parse_rule_group_id),0) " " From B_PROCESS_PARSE_COMBINE Where process_id = :ProcID " ); qry.setParameter ("ProcID", m_iProcessID); qry.open (); qry.next (); int iGroupID = qry.field(0).asInteger(); qry.close(); //检查是否有默认解析规则组0 if (iGroupID == 0) { qry.setSQL (" select count(*) from B_PARSE_RULE_GROUP " " where parse_rule_group_id = 0" ); qry.open (); qry.next (); if (!qry.field(0).asInteger()) { Log::log (0, "当前进程(%d)未定义解析规则组,也未找到默认(即ID=0的)解析规则组",m_iProcessID); Log::log (0, "相关配置表有:B_PARSE_RULE_GROUP,B_PROCESS_PARSE_COMBINE,B_PARSE_RULE"); THROW (100100003); } qry.close (); } qry.setSQL (" Select tlv_tag_id, begin_pos, DATA_LEN, " " parse_func_id, attr_id, bit_position " " From b_parse_rule " " Where parse_rule_group_id = :GrpID " " Order By tlv_tag_id, begin_pos " ); qry.setParameter ("GrpID",iGroupID); qry.open (); while (qry.next ()) { ParseRule **ppRule; int iTag = qry.field ("tlv_tag_id").asInteger(); int iBeginPos = qry.field ("begin_pos").asInteger(); int iDataLen = qry.field ("DATA_LEN").asInteger(); int iFuncID = qry.field ("parse_func_id").asInteger(); int iAttrID = qry.field ("attr_id").asInteger(); int iBitPos = qry.field ("bit_position").asInteger(); //# 当bit位有效时, 转换函数强行使用3, 数据长度强行置为1个字节 if (iBitPos>=1 && iBitPos<=8) { iFuncID = 3; iDataLen = 1; } if (iTag<1 || iTag>MAX_TLV_FLAGS) { Log::log (0,"上载解析规则异常, 系统定义TAG位范围(1--%d) \n" "当前参数配置的TAG标识为: %d ", MAX_TLV_FLAGS, iTag ); THROW (100100004); } for (ppRule=&(m_pParseRule[iTag]); *ppRule; ppRule=&((*ppRule)->m_pNext)); *ppRule = new ParseRule; (*ppRule)->m_iTag = iTag; (*ppRule)->m_iBeginPos = iBeginPos; (*ppRule)->m_iDataLen = iDataLen; (*ppRule)->m_iFuncID = iFuncID; (*ppRule)->m_iAttrID = iAttrID; (*ppRule)->m_iBitPosition = iBitPos; (*ppRule)->m_pNext = 0; } qry.close (); }
void SettingsManager::installMt() { LOCK_FOR_SCOPE(*this); CppUtils::String path_s = CppUtils::getStartupDir(); for(auto it = sesttings_m.mtSettingsMap_m.begin(); it != sesttings_m.mtSettingsMap_m.end(); it++) { MTSettings const & settings_i = it->second; //for(int i = 0; i < mtinstances; i++) { // autonistall if (settings_i.getStartUpSettings().autoInstall_m) { CppUtils::String const& path_mt = it->second.getStartUpSettings().mtPath; // ------------------ CppUtils::String mq4LibName = path_s + NAME_MT4_MQL_COMPILED; CppUtils::String mq4LibName_dest = path_mt + PATH_MT4_MQL + NAME_MT4_MQL_COMPILED; if (!CppUtils::fileExists(mq4LibName)) THROW(CppUtils::OperationFailed, "exc_FileNotExist", "ctx_installMt", mq4LibName ); LOG(MSG_DEBUG, SETTINGS_MAN, "Copying file: " << mq4LibName << " to: " << mq4LibName_dest); if (!CppUtils::copyFile(mq4LibName, mq4LibName_dest, true )) THROW(CppUtils::OperationFailed, "exc_CannotCopyFile", "ctx_installMt", CppUtils::getOSError()); // ------------------- CppUtils::String mq4LibNameSrc = path_s + NAME_MT4_MQL_SOURCE; CppUtils::String mq4LibNameSrc_dest = path_mt + PATH_MT4_MQL + NAME_MT4_MQL_SOURCE; if (!CppUtils::fileExists(mq4LibNameSrc)) THROW(CppUtils::OperationFailed, "exc_FileNotExist", "ctx_installMt", mq4LibNameSrc ); LOG(MSG_DEBUG, SETTINGS_MAN, "Copying file: " << mq4LibNameSrc << " to: " << mq4LibNameSrc_dest); if (!CppUtils::copyFile(mq4LibNameSrc, mq4LibNameSrc_dest, true )) THROW(CppUtils::OperationFailed, "exc_CannotCopyFile", "ctx_installMt", CppUtils::getOSError()); // ------------------- // create and save ini file CppUtils::String mq4InitConf_dest = path_mt + CppUtils::pathDelimiter() +PATH_MT4_CONF + NAME_MT4_MQL_INIT_CONFIG; CppUtils::String inifile_cont; if (it->second.getStartUpSettings().fstruct_m.rows_m.size() <= 0) { inifile_cont = MtCommonHelpers::createMTIniContent(); } else { auto const& row_first = it->second.getStartUpSettings().fstruct_m.rows_m[0]; inifile_cont = MtCommonHelpers::createMTIniContent(row_first.user_m.c_str(), row_first.pass_m.c_str(), row_first.srv_m.c_str()); } if(!CppUtils::saveContentInFile2(mq4InitConf_dest, inifile_cont )) THROW(CppUtils::OperationFailed, "exc_CannotSaveFile", "ctx_installMt", mq4InitConf_dest << " - " << CppUtils::getOSError()); LOG(MSG_DEBUG, SETTINGS_MAN, "Saved MT ini file: " << mq4InitConf_dest ); // check dll // ------------ CppUtils::String fullMt4ProxyDllName = path_s + SOURCE_NAME_MT4_PROXY_DLL_BASE; // destination file must be always CppUtils::String fullMt4ProxyDllName_dest = path_mt + CppUtils::pathDelimiter() + TARGET_NAME_MT4_PROXY_DLL_BASE; if (!CppUtils::fileExists(fullMt4ProxyDllName)) THROW(CppUtils::OperationFailed, "exc_FileNotExist", "ctx_installMt", fullMt4ProxyDllName ); LOG(MSG_DEBUG, SETTINGS_MAN, "Copying file: " << fullMt4ProxyDllName << " to: " << fullMt4ProxyDllName_dest); if (!CppUtils::copyFile(fullMt4ProxyDllName, fullMt4ProxyDllName_dest, true )) THROW(CppUtils::OperationFailed, "exc_CannotCopyFile", "ctx_installMt", CppUtils::getOSError()); // ------------------ // set file CppUtils::String setFile_dest = path_mt + PATH_MT4_PRESETS + NAME_MT4_MQL_INIT_PARAMS; CppUtils::String setFile_dest_content = MtCommonHelpers::createMtParameterContent( settingsFile_m.c_str(), CHILD_MT_LOG_LEVEL, settings_i.getStartUpSettings().tmpResultPath_m.c_str() ); if(!CppUtils::saveContentInFile2(setFile_dest, setFile_dest_content )) THROW(CppUtils::OperationFailed, "exc_CannotSaveFile", "ctx_autoInstLibToMt", setFile_dest << " - " << CppUtils::getOSError()); LOG(MSG_DEBUG, SETTINGS_MAN, "Saved MT set file: " << setFile_dest ); } // END LOOP }; }
// ======================================================= void CExt2Part::readBitmap(COptions *options) // FULLY WORKING { BEGIN; DWORD i, j; CExt2GroupDesc *desc; int nRes; DWORD dwBootBlocks; char *cTempBitmap; DWORD dwBit, dwByte; DWORD dwExt2DataBlock; char *cPtr; int group = 0; // debug DWORD dwUsed; DWORD dwFree; dwBootBlocks = m_info.dwFirstBlock / m_info.dwLogicalBlocksPerExt2Block; //debugWin("dwBootBlocks=%lu and m_info.dwLogicalBlocksPerExt2Block=%lu",dwBootBlocks,m_info.dwLogicalBlocksPerExt2Block); cTempBitmap = new char[((m_info.dwTotalBlocksCount+7)/8)+4096]; if (!cTempBitmap) { showDebug(1, "CExt2Part::readBitmap(): Error 001\n"); goto error_readBitmap; } // init bitmap size nRes = m_bitmap.init(m_header.qwBitmapSize); showDebug(1, "m_bitmap.init(m_header.qwBitmapSize = %lu)\n", m_header.qwBitmapSize); if (nRes == -1) { showDebug(1, "CExt2Part::readBitmap(): Error 002\n"); goto error_readBitmap; } // load group descriptors desc = new CExt2GroupDesc[m_info.dwGroupsCount+m_info.dwDescPerBlock]; showDebug(1, "dwGroupsCount = %lu, m_info.dwDescPerBlock = %lu\n",m_info.dwGroupsCount, m_info.dwDescPerBlock); if (!desc) { showDebug(1, "CExt2Part::readBitmap(): Error 003\n"); goto error_readBitmap; } // for each descriptor BLOCK (not group descriptor!) showDebug(1, "readData m_info.dwBlockSize = %lu\n", m_info.dwBlockSize); for (cPtr=(char*)desc, i=0; i < m_info.dwDescBlocks; i++,cPtr+=m_info.dwBlockSize) { nRes = readData(cPtr, ((QWORD)m_info.dwBlockSize) * ((QWORD)(m_info.dwFirstBlock+1+i)), m_info.dwBlockSize); if (nRes == -1) { showDebug(1, "CExt2Part::readBitmap(): Error 004\n"); goto error_readBitmap; } } dwUsed=0; dwFree=0; showDebug(1, "m_info.dwBlocksPerGroup = %lu\n", m_info.dwBlocksPerGroup); for (i = 0; i < m_info.dwGroupsCount; i++) { if (Le32ToCpu(desc[i].bg_block_bitmap)) { // -- read the bitmap block errno = 0; nRes = readData(cTempBitmap+(i*(m_info.dwBlocksPerGroup/8)), ((QWORD)m_info.dwBlockSize) * ((QWORD)Le32ToCpu(desc[i].bg_block_bitmap)), (m_info.dwBlocksPerGroup/8)); if (nRes == -1) { showDebug(1, "CExt2Part::readBitmap(): Error 005\n"); showDebug(1, "CExt2Part::readBitmap(): err=%d=%d\n", errno, strerror(errno)); goto error_readBitmap; } } else { memset(cTempBitmap+(i*(m_info.dwBlocksPerGroup/8)), 0, (m_info.dwBlocksPerGroup/8)); } } // convert bitmap to little endian DWORD *dwPtr; DWORD dwLen; dwLen = sizeof(cTempBitmap) / sizeof(DWORD); dwPtr = (DWORD *)cTempBitmap; for (i=0; i < dwLen; i++, dwPtr++) *dwPtr = CpuToLe32(*dwPtr); // bitmap is full of 0 at init, then we just have to // write 1 for used blocks // the boot block of 1024 bytes = used for (i=0; i < dwBootBlocks; i++) m_bitmap.setBit(i, true); dwUsed=0; dwFree=0; for (i=dwBootBlocks, dwExt2DataBlock=0; dwExt2DataBlock < ( m_info.dwTotalBlocksCount- m_info.dwFirstBlock); dwExt2DataBlock++) { dwBit = dwExt2DataBlock % 8; dwByte = (dwExt2DataBlock - dwBit) / 8; group = (dwExt2DataBlock/m_info.dwBlocksPerGroup); if ((cTempBitmap[dwByte] & (1 << dwBit)) != 0) { for (j=0; j < m_info.dwLogicalBlocksPerExt2Block; j++, i++) m_bitmap.setBit(i, true); showDebug(3, "m_bitmap.setBit(%1u, true), g = %i\n", (i/4), group); dwUsed++; } else { for (j=0; j < m_info.dwLogicalBlocksPerExt2Block; j++, i++) m_bitmap.setBit(i, false); showDebug(3, "m_bitmap.setBit(%1u, false), g = %i\n", (i/4), group); dwFree++; } } showDebug(1,"used=%lu\nfree=%lu\ntotal=%lu\n",dwUsed,dwFree,dwUsed+dwFree); calculateSpaceFromBitmap(); //success_readBitmap: delete []cTempBitmap; showDebug(1, "end success\n"); RETURN; // auccess error_readBitmap: delete []cTempBitmap; showDebug(1, "end error\n"); g_interface->msgBoxError(i18n("There was an error while reading the bitmap")); THROW(ERR_READ_BITMAP); }
static void S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars, Obj **endpost) { uint32_t num_runs = VA_Get_Size(ivars->runs); Obj ***slice_starts = ivars->slice_starts; uint32_t *slice_sizes = ivars->slice_sizes; Class *klass = SortEx_Get_Class(self); CFISH_Sort_Compare_t compare = (CFISH_Sort_Compare_t)METHOD_PTR(klass, LUCY_SortEx_Compare); if (ivars->buf_max != 0) { THROW(ERR, "Can't refill unless empty"); } // Move all the elements in range into the main buffer as slices. for (uint32_t i = 0; i < num_runs; i++) { SortExternal *const run = (SortExternal*)VA_Fetch(ivars->runs, i); SortExternalIVARS *const run_ivars = SortEx_IVARS(run); uint32_t slice_size = S_find_slice_size(run, run_ivars, endpost); if (slice_size) { // Move slice content from run buffer to main buffer. if (ivars->buf_max + slice_size > ivars->buf_cap) { size_t cap = Memory_oversize(ivars->buf_max + slice_size, sizeof(Obj*)); SortEx_Grow_Buffer(self, cap); } memcpy(ivars->buffer + ivars->buf_max, run_ivars->buffer + run_ivars->buf_tick, slice_size * sizeof(Obj*)); run_ivars->buf_tick += slice_size; ivars->buf_max += slice_size; // Track number of slices and slice sizes. slice_sizes[ivars->num_slices++] = slice_size; } } // Transform slice starts from ticks to pointers. uint32_t total = 0; for (uint32_t i = 0; i < ivars->num_slices; i++) { slice_starts[i] = ivars->buffer + total; total += slice_sizes[i]; } // The main buffer now consists of several slices. Sort the main buffer, // but exploit the fact that each slice is already sorted. if (ivars->scratch_cap < ivars->buf_cap) { ivars->scratch_cap = ivars->buf_cap; ivars->scratch = (Obj**)REALLOCATE( ivars->scratch, ivars->scratch_cap * sizeof(Obj*)); } // Exploit previous sorting, rather than sort buffer naively. // Leave the first slice intact if the number of slices is odd. */ while (ivars->num_slices > 1) { uint32_t i = 0; uint32_t j = 0; while (i < ivars->num_slices) { if (ivars->num_slices - i >= 2) { // Merge two consecutive slices. const uint32_t merged_size = slice_sizes[i] + slice_sizes[i + 1]; Sort_merge(slice_starts[i], slice_sizes[i], slice_starts[i + 1], slice_sizes[i + 1], ivars->scratch, sizeof(Obj*), compare, self); slice_sizes[j] = merged_size; slice_starts[j] = slice_starts[i]; memcpy(slice_starts[j], ivars->scratch, merged_size * sizeof(Obj*)); i += 2; j += 1; } else if (ivars->num_slices - i >= 1) { // Move single slice pointer. slice_sizes[j] = slice_sizes[i]; slice_starts[j] = slice_starts[i]; i += 1; j += 1; } } ivars->num_slices = j; } ivars->num_slices = 0; }
/* Do a simple uri parse: return 0 if fail, 1 otherwise*/ int ncuriparse(const char* uri0, NCURI** durip) { NCURI* duri = NULL; char* uri = NULL; char* p; struct NC_ProtocolInfo* proto; int i,nprotos; /* accumulate parse points*/ char* protocol = NULL; char* host = NULL; char* port = NULL; char* constraint = NULL; char* user = NULL; char* pwd = NULL; char* file = NULL; char* prefixparams = NULL; char* suffixparams = NULL; if(uri0 == NULL || strlen(uri0) == 0) {THROW(1); goto fail;} duri = (NCURI*)calloc(1,sizeof(NCURI)); if(duri == NULL) {THROW(2); goto fail;} /* save original uri */ duri->uri = nulldup(uri0); /* make local copy of uri */ uri = (char*)malloc(strlen(uri0)+1+PADDING); /* +1 for trailing null, +PADDING for shifting */ if(uri == NULL) {THROW(3); goto fail;} /* strings will be broken into pieces with intermixed '\0; characters; first char is guaranteed to be '\0' */ duri->strings = uri; uri++; /* dup the incoming url */ strcpy(uri,uri0); /* Walk the uri and do the following: 1. remove all whitespace 2. remove all '\\' (Temp hack to remove escape characters inserted by Windows or MinGW) */ for(p=uri;*p;p++) { if(*p == '\\' || *p < ' ') nclshift1(p); /* compress out */ } p = uri; /* break up the uri string into big chunks: prefixparams, protocol, host section, and the file section (i.e. remainder) */ /* collect any prefix bracketed parameters */ if(*p == LBRACKET) { prefixparams = p+1; /* find end of the clientparams; convert LB,RB to '&' */ for(;*p;p++) { if(p[0] == RBRACKET && p[1] == LBRACKET) { p[0] = '&'; nclshift1(p+1); } else if(p[0] == RBRACKET && p[1] != LBRACKET) break; } if(*p == 0) {THROW(4); goto fail; /* malformed client params*/} terminate(p); /* nul term the prefixparams (overwrites the final RBRACKET) */ p++; /* move past the final RBRACKET */ } /* Tag the protocol */ protocol = p; p = strchr(p,':'); if(!p) {THROW(5); goto fail;} terminate(p); /*overwrite colon*/ p++; /* skip the colon */ /* verify that the uri starts with an acceptable protocol*/ nprotos = (sizeof(legalprotocols)/sizeof(struct NC_ProtocolInfo)); proto = NULL; for(i=0;i<nprotos;i++) { if(strcmp(protocol,legalprotocols[i].name)==0) { proto = &legalprotocols[i]; break; } } if(proto == NULL) {THROW(6); goto fail; /* illegal protocol*/} /* skip // */ if(p[0] != '/' && p[1] != '/') {THROW(7); goto fail;} p += 2; /* If this is all we have (proto://) then fail */ if(*p == EOFCHAR) {THROW(8); goto fail;} /* establish the start of the file section */ if(proto->filelike) {/* everything after proto:// */ file = p; host = NULL; /* and no host section */ } else { /*!proto->filelike => This means there should be a host section */ /* locate the end of the host section and therefore the start of the file section */ host = p; p = nclocate(p,"/?#"); if(p == NULL) { file = endof(host); /* there is no file section */ } else { ncrshift1(p); /* make room to terminate the host section without overwriting the leading character */ terminate(p); /* terminate the host section */ file = p+1; /* +1 becauseof the shift */ } } /* If you shift in the code below, you must reset file beginning */ if(host != NULL) {/* Parse the host section */ /* Check for leading user:pwd@ */ p = strchr(host,'@'); if(p) { if(p == host) {THROW(9); goto fail; /* we have proto://@ */} user = host; terminate(p); /* overwrite '@' */ host = p+1; /* start of host ip name */ p = strchr(user,':'); if(p == NULL) {THROW(10); goto fail; /* malformed */} terminate(p); /*overwrite colon */ pwd = p+1; } /* extract host and port */ p = host; p = strchr(p,':'); if(p != NULL) { terminate(p); p++; port = p; if(*port == EOFCHAR) {THROW(11); goto fail; /* we have proto://...:/ */} /* The port must look something like a number */ for(;*p;p++) { if(strchr("0123456789-",*p) == NULL) {THROW(12); goto fail; /* probably not a real port, fail */} } } /* else *p == NULL */ /* check for empty host section */ if(*host == EOFCHAR) {THROW(13); goto fail;} } assert(file != NULL); p = file; /* find the end of the file section and the start of the constraints and/or suffixparams */ p = nclocate(p,"?#"); if(p != NULL) { /* we have constraint and/or suffixparams */ char* fileend = p; /* save the end of the file section */ char* constraintend = NULL; if(*p == '?') constraint = p+1; else constraint = NULL; p = strchr(p,'#'); /* may repeat effect of nclocate above */ if(p != NULL) { constraintend = p; suffixparams = p+1; } else suffixparams = NULL; /* Ok, terminate the pieces */ terminate(fileend); /* terminate file section */ if(constraint != NULL && constraintend != NULL) terminate(constraintend); /* Suffix params are already terminated since they should be the last section of the original url */ } /* check for empty sections */ if(file != NULL && *file == EOFCHAR) file = NULL; /* empty file section */ if(constraint != NULL && *constraint == EOFCHAR) constraint = NULL; /* empty constraint section */ if(suffixparams != NULL && *suffixparams == EOFCHAR) suffixparams = NULL; /* empty suffixparams section */ if(suffixparams != NULL) { /* there really are suffix params; so rebuild the suffix params */ if(*suffixparams == LBRACKET) suffixparams++; p = suffixparams; /* convert RBRACKET LBRACKET to '&' */ for(;*p;p++) { if(p[0] == RBRACKET && p[1] == LBRACKET) { p[0] = '&'; nclshift1(p+1); } else if(p[0] == RBRACKET && p[1] != LBRACKET) { /* terminate suffixparams */ *p = EOFCHAR; break; } } if(*suffixparams == EOFCHAR) suffixparams = NULL; /* suffixparams are empty */ } /* do last minute empty check */ if(protocol != NULL && *protocol == EOFCHAR) protocol = NULL; if(user != NULL && *user == EOFCHAR) user = NULL; if(pwd != NULL && *pwd == EOFCHAR) pwd = NULL; if(host != NULL && *host == EOFCHAR) host = NULL; if(port != NULL && *port == EOFCHAR) port = NULL; if(file != NULL && *file == EOFCHAR) file = NULL; if(constraint != NULL && *constraint == EOFCHAR) constraint = NULL; /* assemble the component pieces */ duri->protocol = protocol; duri->user = user; duri->password = pwd; duri->host = host; duri->port = port; duri->file = file; ncurisetconstraints(duri,constraint); /* concat suffix and prefix params */ if(prefixparams != NULL || suffixparams != NULL) { int plen = prefixparams ? strlen(prefixparams) : 0; int slen = suffixparams ? strlen(suffixparams) : 0; int space = plen + slen + 1; /* add 1 for an extra ampersand if both are defined */ space++; duri->params = (char*)malloc(space); duri->params[0] = EOFCHAR; /* so we can use strcat */ if(plen > 0) { strcat(duri->params,prefixparams); if(slen > 0) strcat(duri->params,"&"); } if(slen > 0) strcat(duri->params,suffixparams); } #ifdef NCXDEBUG { fprintf(stderr,"duri:"); fprintf(stderr," params=|%s|",FIX(duri->params)); fprintf(stderr," protocol=|%s|",FIX(duri->protocol)); fprintf(stderr," host=|%s|",FIX(duri->host)); fprintf(stderr," port=|%s|",FIX(duri->port)); fprintf(stderr," file=|%s|",FIX(duri->file)); fprintf(stderr," constraint=|%s|",FIX(duri->constraint)); fprintf(stderr,"\n"); } #endif if(durip != NULL) *durip = duri; else ncurifree(duri); return 1; fail: if(duri != NULL) { ncurifree(duri); } return 0; }
void Interpreter::loadModuleRecursive (const string &moduleName) { debug ("Interpreter::loadModuleRecursive " "(moduleName = " << moduleName << ")"); if (moduleIsLoadedInternal (moduleName)) { debug ("\talready loaded"); return; } // // Using the module search path, locate the file that contains the // source code for the module. Open the file. // string fileName = findModule (moduleName); ifstream file (fileName.c_str()); if (!file) { THROW_ERRNO ("Cannot load CTL module \"" << moduleName << "\". " "Opening file \"" << fileName << "\" for reading " "failed (%T)."); } debug ("\tloading from file \"" << fileName << "\""); Module *module = 0; LContext *lcontext = 0; try { // // Create a Module, an Lcontext and a Parser // module = newModule (moduleName, fileName); _data->moduleSet.addModule (module); lcontext = newLContext (file, module, _data->symtab); Parser parser (*lcontext, *this); // // Parse the source code and generate executable code // for the module // debug ("\tparsing input"); SyntaxNodePtr syntaxTree = parser.parseInput (); if (syntaxTree && lcontext->numErrors() == 0) { debug ("\tgenerating code"); syntaxTree->generateCode (*lcontext); } if (lcontext->numErrors() > 0) { lcontext->printDeclaredErrors(); THROW (LoadModuleExc, "Failed to load CTL module \"" << moduleName << "\"."); } // // Run the module's initialization code // debug ("\trunning module initialization code"); module->runInitCode(); // // Cleanup: the LContext and the module's local symbols // are no longer needed, but we keep the global symbols. // debug ("\tcleanup"); delete lcontext; _data->symtab.deleteAllLocalSymbols (module); } catch (...) { // // Something went wrong while loading the module, clean up // delete lcontext; _data->symtab.deleteAllSymbols (module); _data->moduleSet.removeModule (moduleName); throw; } }
/** * Multiplies two binary field elements using recursive Karatsuba * multiplication. * * @param[out] c - the result. * @param[in] a - the first binary field element. * @param[in] b - the second binary field element. * @param[in] size - the number of digits to multiply. * @param[in] level - the number of Karatsuba steps to apply. */ static void fb_mul_karat_imp(dv_t c, const fb_t a, const fb_t b, int size, int level) { int i, h, h1; dv_t a1, b1, ab; dig_t *a0b0, *a1b1; dv_null(a1); dv_null(b1); dv_null(ab); /* Compute half the digits of a or b. */ h = size >> 1; h1 = size - h; TRY { /* Allocate the temp variables. */ dv_new(a1); dv_new(b1); dv_new(ab); a0b0 = ab; a1b1 = ab + 2 * h; /* a0b0 = a0 * b0 and a1b1 = a1 * b1 */ if (level <= 1) { #if FB_MUL == BASIC fb_mul_basic_imp(a0b0, a, b, h); fb_mul_basic_imp(a1b1, a + h, b + h, h1); #elif FB_MUL == LCOMB fb_mul_lcomb_imp(a0b0, a, b, h); fb_mul_lcomb_imp(a1b1, a + h, b + h, h1); #elif FB_MUL == RCOMB fb_mul_rcomb_imp(a0b0, a, b, h); fb_mul_rcomb_imp(a1b1, a + h, b + h, h1); #elif FB_MUL == INTEG || FB_MUL == LODAH fb_muld_low(a0b0, a, b, h); fb_muld_low(a1b1, a + h, b + h, h1); #endif } else { fb_mul_karat_imp(a0b0, a, b, h, level - 1); fb_mul_karat_imp(a1b1, a + h, b + h, h1, level - 1); } for (i = 0; i < 2 * size; i++) { c[i] = ab[i]; } /* c = c - (a0*b0 << h digits) */ fb_addd_low(c + h, c + h, a0b0, 2 * h); /* c = c - (a1*b1 << h digits) */ fb_addd_low(c + h, c + h, a1b1, 2 * h1); /* a1 = (a1 + a0) */ fb_addd_low(a1, a, a + h, h); /* b1 = (b1 + b0) */ fb_addd_low(b1, b, b + h, h); if (h1 > h) { a1[h1 - 1] = a[h + h1 - 1]; b1[h1 - 1] = b[h + h1 - 1]; } if (level <= 1) { /* a1b1 = (a1 + a0)*(b1 + b0) */ #if FB_MUL == BASIC fb_mul_basic_imp(a1b1, a1, b1, h1); #elif FB_MUL == LCOMB fb_mul_lcomb_imp(a1b1, a1, b1, h1); #elif FB_MUL == RCOMB fb_mul_rcomb_imp(a1b1, a1, b1, h1); #elif FB_MUL == INTEG || FB_MUL == LODAH fb_muld_low(a1b1, a1, b1, h1); #endif } else { fb_mul_karat_imp(a1b1, a1, b1, h1, level - 1); } /* c = c + [(a1 + a0)*(b1 + b0) << digits] */ fb_addd_low(c + h, c + h, a1b1, 2 * h1); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { dv_free(a1); dv_free(b1); dv_free(ab); } }
int flom_handle_init(flom_handle_t *handle) { enum Exception { G_TRY_MALLOC_ERROR1 , G_TRY_MALLOC_ERROR2 , CONFIG_INIT_ERROR , NONE } excp; int ret_cod = FLOM_RC_INTERNAL_ERROR; /* check flom library is initialized */ if (FLOM_RC_OK != (ret_cod = flom_init_check())) return ret_cod; FLOM_TRACE(("flom_handle_init\n")); TRY { /* memory reset */ memset(handle, 0, sizeof(flom_handle_t)); /* allocate memory for connection data structure */ if (NULL == (handle->conn_data = g_try_malloc0( sizeof(struct flom_conn_data_s)))) THROW(G_TRY_MALLOC_ERROR1); /* allocate memory for configuration data structure */ if (NULL == (handle->config = g_try_malloc0( sizeof(flom_config_t)))) THROW(G_TRY_MALLOC_ERROR2); /* initialize config object */ if (FLOM_RC_OK != (ret_cod = flom_config_clone(handle->config))) THROW(CONFIG_INIT_ERROR); /* clients can not fork a new flom daemon: this restriction is * necessary to avoid the side effects related to daemonization that * can affect a general purpose environment... This is a CLIENT!!! */ flom_config_set_lifespan(handle->config, 0); /* state reset */ handle->state = FLOM_HANDLE_STATE_INIT; THROW(NONE); } CATCH { switch (excp) { case G_TRY_MALLOC_ERROR1: case G_TRY_MALLOC_ERROR2: ret_cod = FLOM_RC_G_TRY_MALLOC_ERROR; break; case CONFIG_INIT_ERROR: break; case NONE: ret_cod = FLOM_RC_OK; break; default: ret_cod = FLOM_RC_INTERNAL_ERROR; } /* switch (excp) */ } /* TRY-CATCH */ /* clean memory if an error occurred */ if (NONE != excp) { if (NULL != handle->config) { flom_config_free(handle->config); g_free(handle->config); handle->config = NULL; } /* if (NULL != handle->config) */ if (NULL != handle->conn_data) { g_free(handle->conn_data); handle->conn_data = NULL; } /* if (NULL != handle->conn_data) */ } /* if (NONE != excp) */ FLOM_TRACE(("flom_handle_init/excp=%d/" "ret_cod=%d/errno=%d\n", excp, ret_cod, errno)); return ret_cod; }
int flom_handle_unlock(flom_handle_t *handle) { enum Exception { NULL_OBJECT , API_INVALID_SEQUENCE , OBJ_CORRUPTED , CLIENT_UNLOCK_ERROR , CLIENT_DISCONNECT_ERROR , NONE } excp; int ret_cod = FLOM_RC_INTERNAL_ERROR; /* check flom library is initialized */ if (FLOM_RC_OK != (ret_cod = flom_init_check())) return ret_cod; FLOM_TRACE(("flom_handle_unlock\n")); TRY { struct flom_conn_data_s *cd = NULL; /* check handle is not NULL */ if (NULL == handle) THROW(NULL_OBJECT); /* cast and retrieve conn_data fron the proxy object */ cd = (struct flom_conn_data_s *)handle->conn_data; /* check handle state */ if (FLOM_HANDLE_STATE_LOCKED != handle->state && FLOM_HANDLE_STATE_CONNECTED != handle->state) { FLOM_TRACE(("flom_handle_unlock: handle->state=%d\n", handle->state)); THROW(API_INVALID_SEQUENCE); } /* check the connection data pointer is not NULL (we can't be sure it's a valid pointer) */ if (NULL == handle->conn_data) THROW(OBJ_CORRUPTED); if (FLOM_HANDLE_STATE_LOCKED == handle->state) { /* lock release */ if (FLOM_RC_OK != (ret_cod = flom_client_unlock( handle->config, cd))) THROW(CLIENT_UNLOCK_ERROR); /* state update */ handle->state = FLOM_HANDLE_STATE_CONNECTED; } else { FLOM_TRACE(("flom_handle_unlock: resource already unlocked (%d), " "skipping...\n", handle->state)); } /* gracefully disconnect from daemon */ if (FLOM_RC_OK != (ret_cod = flom_client_disconnect(cd))) THROW(CLIENT_DISCONNECT_ERROR); /* state update */ handle->state = FLOM_HANDLE_STATE_DISCONNECTED; THROW(NONE); } CATCH { switch (excp) { case NULL_OBJECT: ret_cod = FLOM_RC_NULL_OBJECT; break; case API_INVALID_SEQUENCE: ret_cod = FLOM_RC_API_INVALID_SEQUENCE; break; case OBJ_CORRUPTED: ret_cod = FLOM_RC_OBJ_CORRUPTED; break; case CLIENT_UNLOCK_ERROR: case CLIENT_DISCONNECT_ERROR: break; case NONE: ret_cod = FLOM_RC_OK; break; default: ret_cod = FLOM_RC_INTERNAL_ERROR; } /* switch (excp) */ } /* TRY-CATCH */ FLOM_TRACE(("flom_handle_unlock/excp=%d/" "ret_cod=%d/errno=%d\n", excp, ret_cod, errno)); return ret_cod; }
bool operator()(T const& val) const { THROW(CppUtils::OperationFailed, "exc_NotImplemented", "ctx_Comparator", "" ); }
/* dissect a whole DCP PDU */ static void dissect_PNDCP_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *dcp_item) { guint8 service_id; guint8 service_type; guint32 xid; guint16 response_delay; guint16 data_length; int offset = 0; gchar *xid_str; gboolean is_response = FALSE; offset = dissect_pn_uint8 (tvb, offset, pinfo, tree, hf_pn_dcp_service_id, &service_id); offset = dissect_pn_uint8 (tvb, offset, pinfo, tree, hf_pn_dcp_service_type, &service_type); offset = dissect_pn_uint32(tvb, offset, pinfo, tree, hf_pn_dcp_xid, &xid); if(service_id == PNDCP_SERVICE_ID_IDENTIFY && service_type == PNDCP_SERVICE_TYPE_REQUEST) { /* multicast header */ offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_response_delay, &response_delay); } else { /* unicast header */ offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_reserved16, NULL); } offset = dissect_pn_uint16(tvb, offset, pinfo, tree, hf_pn_dcp_data_length, &data_length); switch(service_id) { case(PNDCP_SERVICE_ID_GET): pn_append_info(pinfo, dcp_item, "Get"); break; case(PNDCP_SERVICE_ID_SET): pn_append_info(pinfo, dcp_item, "Set"); break; case(PNDCP_SERVICE_ID_IDENTIFY): pn_append_info(pinfo, dcp_item, "Ident"); break; case(PNDCP_SERVICE_ID_HELLO): pn_append_info(pinfo, dcp_item, "Hello"); break; default: offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, tvb_length_remaining(tvb, offset)); return; } switch(service_type) { case(PNDCP_SERVICE_TYPE_REQUEST): pn_append_info(pinfo, dcp_item, " Req"); break; case(PNDCP_SERVICE_TYPE_RESPONSE_SUCCESS): pn_append_info(pinfo, dcp_item, " Ok "); is_response = TRUE; break; case(PNDCP_SERVICE_TYPE_RESPONSE_UNSUPPORTED): pn_append_info(pinfo, dcp_item, " unsupported"); is_response = TRUE; break; default: offset = dissect_pn_undecoded(tvb, offset, pinfo, tree, tvb_length_remaining(tvb, offset)); return; } xid_str = ep_strdup_printf(", Xid:0x%x", xid); pn_append_info(pinfo, dcp_item, xid_str); /* dissect a number of blocks (depending on the remaining length) */ while(data_length) { int ori_offset = offset; if(service_id == PNDCP_SERVICE_ID_GET && service_type == PNDCP_SERVICE_TYPE_REQUEST) { /* Selectors */ offset = dissect_PNDCP_Option(tvb, offset, pinfo, tree, dcp_item, hf_pn_dcp_option, TRUE /* append_col */); } else { offset = dissect_PNDCP_Block(tvb, offset, pinfo, tree, dcp_item, service_id, is_response); } /* prevent an infinite loop */ if(offset <= ori_offset || data_length < (offset - ori_offset)) { THROW(ReportedBoundsError); } data_length -= (offset - ori_offset); } }
void SmsPluginTransport::msgInfoToSubmitData(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SUBMIT_DATA_S *pData, SMS_CODING_SCHEME_T *pCharType, int addrIndex) { // Destination Address pData->destAddress.ton = SMS_TON_UNKNOWN; pData->destAddress.npi = SMS_NPI_ISDN; memset(pData->destAddress.address, 0x00, MAX_ADDRESS_LEN+1); memcpy(pData->destAddress.address, pMsgInfo->addressList[addrIndex].addressVal, MAX_ADDRESS_LEN); MSG_DEBUG("ton [%d]", pData->destAddress.ton); MSG_DEBUG("npi [%d]", pData->destAddress.npi); MSG_DEBUG("address [%s]", pData->destAddress.address); int decodeLen = 0, bufSize = (MAX_GSM_7BIT_DATA_LEN*MAX_SEGMENT_NUM) + 1; // SMS_CHARSET_7BIT unsigned char decodeData[bufSize]; memset(decodeData, 0x00, sizeof(decodeData)); msg_encode_type_t encodeType = MSG_ENCODE_GSM7BIT; SMS_LANGUAGE_ID_T langId = SMS_LANG_ID_RESERVED; // User Data if (pMsgInfo->bTextSms == true) { if (*pCharType == SMS_CHARSET_7BIT) { decodeLen = SmsPluginTextConvert::instance()->convertUTF8ToGSM7bit(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, pMsgInfo->dataSize, &langId); } else if (*pCharType == SMS_CHARSET_8BIT) { memcpy(decodeData, pMsgInfo->msgText, pMsgInfo->dataSize); decodeLen = pMsgInfo->dataSize; } else if (*pCharType == SMS_CHARSET_UCS2) { decodeLen = SmsPluginTextConvert::instance()->convertUTF8ToUCS2(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, pMsgInfo->dataSize); } else if (*pCharType == SMS_CHARSET_AUTO) { decodeLen = SmsPluginTextConvert::instance()->convertUTF8ToAuto(decodeData, bufSize, (unsigned char*)pMsgInfo->msgText, pMsgInfo->dataSize, &encodeType); *pCharType = encodeType; } } else { int fileSize = 0; char* pFileData = NULL; AutoPtr<char> FileBuf(&pFileData); // Read Message Data from File if (MsgOpenAndReadFile(pMsgInfo->msgData, &pFileData, &fileSize) == false) THROW(MsgException::FILE_ERROR, "MsgOpenAndReadFile error"); MSG_DEBUG("file size : [%d] file data : [%s]", fileSize, pFileData); if (*pCharType == SMS_CHARSET_7BIT) { decodeLen = SmsPluginTextConvert::instance()->convertUTF8ToGSM7bit(decodeData, bufSize, (unsigned char*)pFileData, fileSize, &langId); } else if (*pCharType == SMS_CHARSET_8BIT) { memcpy(decodeData, pFileData, fileSize); decodeLen = fileSize; } else if (*pCharType == SMS_CHARSET_UCS2) { decodeLen = SmsPluginTextConvert::instance()->convertUTF8ToUCS2(decodeData, bufSize, (unsigned char*)pFileData, fileSize); } else if (*pCharType == SMS_CHARSET_AUTO) { decodeLen = SmsPluginTextConvert::instance()->convertUTF8ToAuto(decodeData, bufSize, (unsigned char*)pFileData, fileSize, &encodeType); *pCharType = encodeType; } // Delete File MsgDeleteFile(pMsgInfo->msgData); } MSG_DEBUG("decode length : [%d]", decodeLen); MSG_DEBUG("character type : [%d]", *pCharType); MSG_DEBUG("Language Identifier : [%d]", langId); MSG_DEBUG("reply address : [%s]", pMsgInfo->replyAddress); int addrLen = 0; char* encodedAddr = NULL; AutoPtr<char> addressBuf(&encodedAddr); if (strlen(pMsgInfo->replyAddress) > 0) { SMS_ADDRESS_S replyAddr = {}; replyAddr.ton = SMS_TON_NATIONAL; replyAddr.npi = SMS_NPI_ISDN; memset(replyAddr.address, 0x00, MAX_ADDRESS_LEN+1); memcpy(replyAddr.address, pMsgInfo->replyAddress, MAX_ADDRESS_LEN); addrLen = SmsPluginParamCodec::encodeAddress(&replyAddr, &encodedAddr); MSG_DEBUG("reply addr length : [%d]", addrLen); } int segSize = 0, index = 0; segSize = getSegmentSize(*pCharType, decodeLen, pMsgInfo->msgPort.valid, langId, addrLen); pData->segCount = ceil((double)decodeLen/(double)segSize); MSG_DEBUG("segment size : [%d], pData->segCount : [%d]", segSize, pData->segCount); if (pData->segCount > MAX_SEGMENT_NUM) THROW(MsgException::SMS_PLG_ERROR, "Segment Count is over maximum : %d", pData->segCount); int headerCnt = 0; for (unsigned int i = 0; i < pData->segCount; i++) { headerCnt = 0; if ((i + 1) == pData->segCount) pData->userData[i].length = decodeLen - (i*segSize); else pData->userData[i].length = segSize; memset(pData->userData[i].data, 0x00, MAX_USER_DATA_LEN+1); memcpy(pData->userData[i].data, &(decodeData[index]), pData->userData[i].length); pData->userData[i].data[pData->userData[i].length] = 0; MSG_DEBUG("user data len [%d]", pData->userData[i].length); MSG_DEBUG("user data [%s]", pData->userData[i].data); index += segSize; // Set User Data Header for Concatenated Message if (pData->segCount > 1) { pData->userData[i].header[headerCnt].udhType = SMS_UDH_CONCAT_8BIT; pData->userData[i].header[headerCnt].udh.concat8bit.msgRef = msgRef8bit; pData->userData[i].header[headerCnt].udh.concat8bit.totalSeg = pData->segCount; pData->userData[i].header[headerCnt].udh.concat8bit.seqNum = i + 1; headerCnt++; } // Set User Data Header Port Information if (pMsgInfo->msgPort.valid == true) { pData->userData[i].header[headerCnt].udhType = SMS_UDH_APP_PORT_16BIT; pData->userData[i].header[headerCnt].udh.appPort16bit.destPort = pMsgInfo->msgPort.dstPort; pData->userData[i].header[headerCnt].udh.appPort16bit.originPort = pMsgInfo->msgPort.srcPort; headerCnt++; } // Set User Data Header for Alternate Reply Address if (strlen(pMsgInfo->replyAddress) > 0) { pData->userData[i].header[headerCnt].udhType = SMS_UDH_ALTERNATE_REPLY_ADDRESS; pData->userData[i].header[headerCnt].udh.alternateAddress.ton = SMS_TON_NATIONAL; pData->userData[i].header[headerCnt].udh.alternateAddress.npi = SMS_NPI_ISDN; memset(pData->userData[i].header[headerCnt].udh.alternateAddress.address, 0x00, MAX_ADDRESS_LEN+1); memcpy(pData->userData[i].header[headerCnt].udh.alternateAddress.address, pMsgInfo->replyAddress, MAX_ADDRESS_LEN); headerCnt++; } // Set User Data Header for National Language Single Shift if (*pCharType == SMS_CHARSET_7BIT && langId != SMS_LANG_ID_RESERVED) { pData->userData[i].header[headerCnt].udhType = SMS_UDH_SINGLE_SHIFT; pData->userData[i].header[headerCnt].udh.singleShift.langId = langId; headerCnt++; } pData->userData[i].headerCnt = headerCnt; } msgRef8bit++; }
void SettingsManager::parse(CppUtils::String const& file) { LOCK_FOR_SCOPE(*this); sesttings_m.clear(); if (!CppUtils::fileExists(file)) THROW(CppUtils::OperationFailed, "exc_SettingsFileNotFound", "ctx_parseSettings", file); settingsFile_m = file; ScopedSoap< _ns1__settings, -1> sc(soap_new__ns1__settings); sc.loadXmlFromFile(file); LOG(MSG_DEBUG, SETTINGS_MAN, "Settings file loaded: " << file ); // read even plugin params _ns1__settings_generalparams_eventpluginparams const& eventPluginParams = sc.getBaseEntry()->generalparams.eventpluginparams; for(int i = 0; i < eventPluginParams.entry.size() ;i++) { CppUtils::String const& name = eventPluginParams.entry[i].name; CppUtils::String const& value = eventPluginParams.entry[i].value; auto itt = sesttings_m.eventPluginParams_m.find(name); if (itt != sesttings_m.eventPluginParams_m.end()) THROW(CppUtils::OperationFailed, "exc_DublicateEntry_EventPluginParams", "ctx_parseSettings", name); sesttings_m.eventPluginParams_m[ name ] = value; LOG(MSG_DEBUG, SETTINGS_MAN, "Read event plugin parameters: [" << name << "]-[" << value << "]"); } int mt4datareadintrvalsec_i = atoi(sc.getBaseEntry()->mt4datareadintrvalsec.c_str()); if (mt4datareadintrvalsec_i > 0) { sesttings_m.mt4datareadintrvalsec_m = mt4datareadintrvalsec_i; } LOG(MSG_DEBUG, SETTINGS_MAN, "Read MT output every: " << sesttings_m.mt4datareadintrvalsec_m << " sec"); int zombiemt4killersec_i = atoi(sc.getBaseEntry()->zombiemt4killer.c_str()); if (zombiemt4killersec_i > 0) { sesttings_m.zombiemt4killersec_m = zombiemt4killersec_i; } LOG(MSG_DEBUG, SETTINGS_MAN, "Zombie MT killer runs every: " << sesttings_m.mt4datareadintrvalsec_m << " sec"); sesttings_m.baseTmpMtPath_m = CppUtils::getTempPath() + CppUtils::pathDelimiter() + "__mt_ht_tmp"; sesttings_m.baseTmpMtPathFileMatch_m = sesttings_m.baseTmpMtPath_m; LOG(MSG_DEBUG, SETTINGS_MAN, "Base tmp MT output path: " << sesttings_m.baseTmpMtPath_m); //sesttings_m.serverPipe_m = sc.getBaseEntry()->servercollectorpipe; //if (sesttings_m.serverPipe_m.size() <=0) // THROW(CppUtils::OperationFailed, "exc_InvalidPipeName", "ctx_parseSettings", ""); sesttings_m.allowdebugEvents_m = ComparatorMt<CppUtils::String>()(*sc.getBaseEntry()->generalparams.htserver.debugconsole); int mtinstances = sc.getBaseEntry()->mtinstances.instance.size(); // read other settings for(int i = 0; i < mtinstances; i++) { MTSettings mtsetting; MtStartUp startUpEntry; _ns1__settings_mtinstances_instance const& sentry = sc.getBaseEntry()->mtinstances.instance[i]; startUpEntry.mtName = sentry.name; startUpEntry.mtPath = sentry.path; //startUpEntry.mtPipeName = sentry.mtpipe; //startUpEntry.useChildMtToReconnect_m = ComparatorMt<CppUtils::String>()(*sentry.usechildmttoreconnect); startUpEntry.loadBalanceEnabled = ComparatorMt<CppUtils::String>()(sentry.loadbalanced); //LOG(MSG_INFO, SETTINGS_MAN, "[" << startUpEntry.mtName << "] - use MT child for reconect: " << CppUtils::bool2String(startUpEntry.useChildMtToReconnect_m) ); LOG(MSG_INFO, SETTINGS_MAN, "[" << startUpEntry.mtName << "] - load balanced: " << CppUtils::bool2String(startUpEntry.loadBalanceEnabled) ); startUpEntry.tmpResultPath_m = sesttings_m.baseTmpMtPath_m + CppUtils::pathDelimiter() + startUpEntry.mtName + CppUtils::pathDelimiter(); CppUtils::removeDir(startUpEntry.tmpResultPath_m); CppUtils::makeDir(startUpEntry.tmpResultPath_m); LOG(MSG_INFO, SETTINGS_MAN, "[" << startUpEntry.mtName << "] - base temp path: " << startUpEntry.tmpResultPath_m); if (sentry.autoload != NULL) { startUpEntry.autoLoadPath_m = *sentry.autoload; AlgLib::AutoLoadFileStruct::loadFromFile(startUpEntry.autoLoadPath_m, startUpEntry.fstruct_m); LOG(MSG_INFO, SETTINGS_MAN, "Autoload path: " << startUpEntry.autoLoadPath_m << ", read OK" ); } if (sentry.autorecover!= NULL) { startUpEntry.autorecover = ComparatorMt<CppUtils::String>()(*sentry.autorecover); LOG(MSG_INFO, SETTINGS_MAN, "Autorecover strategy is: " << (startUpEntry.autorecover ? "true":"false") << " for "<< startUpEntry.mtName ); } // company ID startUpEntry.companyId_m = sentry.companyid; if (startUpEntry.companyId_m.size() <=0) THROW(CppUtils::OperationFailed, "exc_InvalidCompanyID", "ctx_parseSettings", startUpEntry.mtName); LOG(MSG_INFO, SETTINGS_MAN, "Company ID is: \"" << startUpEntry.companyId_m << "\" for \""<< startUpEntry.mtName << "\"" ); // autonistall if (sentry.autoinstall != NULL) { startUpEntry.autoInstall_m = ComparatorMt<CppUtils::String>()(*sentry.autoinstall); //autoInstLibToMt(startUpEntry); LOG(MSG_INFO, SETTINGS_MAN, "Will perform autoinstall of MT for: " << startUpEntry.mtName ); } // autostart /* if (sentry.autostart!= NULL) { startUpEntry.autostart = ComparatorMt<CppUtils::String>()(*sentry.autostart); LOG(MSG_INFO, SETTINGS_MAN, "Autostart is: " << CppUtils::bool2String(startUpEntry.autostart) << " for "<< startUpEntry.mtName ); //if (!startMtInstance(startUpEntry)) { // THROW(CppUtils::OperationFailed, "exc_CannotStartMtInstance", "ctx_parseSettings", startUpEntry.mtName); //} } */ mtsetting.setStartUpSettings(startUpEntry); auto it_mts = sesttings_m.mtSettingsMap_m.find(startUpEntry.mtName); if (it_mts != sesttings_m.mtSettingsMap_m.end()) THROW(CppUtils::OperationFailed, "exc_DublicateMTNameEntry", "ctx_parseSettings", startUpEntry.mtName); sesttings_m.mtSettingsMap_m[ startUpEntry.mtName ] = mtsetting; LOG(MSG_INFO, SETTINGS_MAN, "MT setting path: " << startUpEntry.mtPath /* << " pipe: " << startUpEntry.mtPipeName */ << " name: " << startUpEntry.mtName << ", broker layer initialized" ); } // end loop over instances // read heartbeat interval int hbt_int = atoi(sc.getBaseEntry()->heartbeatjavahtsec.c_str()); if (hbt_int > 0) sesttings_m.heartBeatJavaHTSec_m = hbt_int; LOG(MSG_DEBUG, SETTINGS_MAN, "Heartbeat interval to Java HT layer: " << sesttings_m.heartBeatJavaHTSec_m << " seconds" ); }
void SmsPluginTransport::submitRequest(SMS_REQUEST_INFO_S *pReqInfo) { MSG_BEGIN(); SMS_TPDU_S tpdu; tpdu.tpduType = SMS_TPDU_SUBMIT; // Set SMS Send Options - Setting setSmsSendOptions(&(tpdu.data.submit)); // Set SMS Send Options - Each Message if (pReqInfo->sendOptInfo.bSetting == true) { tpdu.data.submit.bStatusReport = pReqInfo->sendOptInfo.bDeliverReq; tpdu.data.submit.bReplyPath = pReqInfo->sendOptInfo.option.smsSendOptInfo.bReplyPath; } // Set Coding Scheme for apps that use port number if (pReqInfo->msgInfo.msgPort.valid == true) { tpdu.data.submit.dcs.codingScheme = (SMS_CODING_SCHEME_T)pReqInfo->msgInfo.encodeType; MSG_DEBUG("DCS is changed by application : [%d]", tpdu.data.submit.dcs.codingScheme); } // Set SMSC Options SMS_ADDRESS_S smsc; setSmscOptions(&smsc); int i = 0; int j = 0; MSG_DEBUG("pReqInfo->msgInfo.nAddressCnt [%d]", pReqInfo->msgInfo.nAddressCnt); for (i = 0; i < pReqInfo->msgInfo.nAddressCnt; i++) { // Make SMS_SUBMIT_DATA_S from MSG_REQUEST_INFO_S SMS_SUBMIT_DATA_S submitData = {{0},}; msgInfoToSubmitData(&(pReqInfo->msgInfo), &submitData, &(tpdu.data.submit.dcs.codingScheme), i); // Encode SMSC Address unsigned char smscAddr[MAX_SMSC_LEN]; memset(smscAddr, 0x00, sizeof(smscAddr)); int smscLen = SmsPluginParamCodec::encodeSMSC(&smsc, smscAddr); if (smscLen <= 0) return; for (j = 0; j < smscLen; j++) { MSG_DEBUG("pSCAInfo [%02x]", smscAddr[j]); } int bufLen = 0, reqId = 0; char buf[MAX_TPDU_DATA_LEN]; int addLen = strlen(submitData.destAddress.address); tpdu.data.submit.destAddress.ton = submitData.destAddress.ton; tpdu.data.submit.destAddress.npi = submitData.destAddress.npi; if (addLen < MAX_ADDRESS_LEN) { memcpy(tpdu.data.submit.destAddress.address, submitData.destAddress.address, addLen); tpdu.data.submit.destAddress.address[addLen] = '\0'; } else { memcpy(tpdu.data.submit.destAddress.address, submitData.destAddress.address, MAX_ADDRESS_LEN); tpdu.data.submit.destAddress.address[MAX_ADDRESS_LEN] = '\0'; } for (unsigned int segCnt = 0; segCnt < submitData.segCount; segCnt++) { if (submitData.userData[segCnt].headerCnt > 0) { tpdu.data.submit.bHeaderInd = true; } else { tpdu.data.submit.bHeaderInd = false; } memset(&(tpdu.data.submit.userData), 0x00, sizeof(SMS_USERDATA_S)); memcpy(&(tpdu.data.submit.userData), &(submitData.userData[segCnt]), sizeof(SMS_USERDATA_S)); // Encode SMS-SUBMIT TPDU memset(buf, 0x00, sizeof(buf)); bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf); // Make Telephony Structure TelSmsDatapackageInfo_t pkgInfo; // Set TPDU data memset((void*)pkgInfo.szData, 0x00, sizeof(pkgInfo.szData)); memcpy((void*)pkgInfo.szData, buf, bufLen); pkgInfo.szData[bufLen] = 0; pkgInfo.MsgLength = bufLen; // Set SMSC data memset(pkgInfo.Sca, 0x00, sizeof(pkgInfo.Sca)); memcpy((void*)pkgInfo.Sca, smscAddr, smscLen); pkgInfo.Sca[smscLen] = '\0'; SMS_SENT_INFO_S sentInfo = {}; bool bMoreMsg = FALSE; memcpy(&(sentInfo.reqInfo), pReqInfo, sizeof(SMS_REQUEST_INFO_S)); if ((segCnt+1) == submitData.segCount && (i+1)==pReqInfo->msgInfo.nAddressCnt) { sentInfo.bLast = true; bMoreMsg = FALSE; } else { sentInfo.bLast = false; bMoreMsg = TRUE; } SmsPluginEventHandler::instance()->SetSentInfo(&sentInfo); curStatus = MSG_NETWORK_SENDING; // Send SMS int tapiRet = TAPI_API_SUCCESS; tapiRet = tel_send_sms(pTapiHandle, &pkgInfo, bMoreMsg, TapiEventSentStatus, NULL); if (tapiRet == TAPI_API_SUCCESS) { MSG_DEBUG("######## TelTapiSmsSend Success !!! req Id : [%d] return : [%d] #######", reqId, tapiRet); } else { SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL); THROW(MsgException::SMS_PLG_ERROR, "######## TelTapiSmsSend Fail !!! req Id : [%d] return : [%d] #######", reqId, tapiRet); } msg_network_status_t retStatus = getNetStatus(); if (retStatus == MSG_NETWORK_SEND_SUCCESS) { MSG_DEBUG("######## Msg Sent was Successful !!! req Id : [%d] return : [%d] #######", reqId, retStatus); } else { SmsPluginEventHandler::instance()->handleSentStatus(MSG_NETWORK_SEND_FAIL); THROW(MsgException::SMS_PLG_ERROR, "######## Msg Sent was Failed !!! req Id : [%d] return : [%d] #######", reqId, retStatus); } if (tpdu.data.submit.userData.headerCnt > 0) tpdu.data.submit.userData.headerCnt--; } } MSG_END(); }
// ======================================================= void CExt2Part::readSuperBlock() { BEGIN; CExt2Super sb; int nRes; // init memset(&m_info, 0, sizeof(CInfoExt2Header)); // 0. go to the beginning of the super block nRes = fseek(m_fDeviceFile, 1024, SEEK_SET); if (nRes == -1) goto error_readSuperBlock; // 1. read and print important informations nRes = fread(&sb, sizeof(sb), 1, m_fDeviceFile); if (nRes != 1) goto error_readSuperBlock; // check partition has an ext2 file system if (sb.s_magic != Le16ToCpu(EXT2_SUPER_MAGIC)) goto error_readSuperBlock; // read and print important informations m_info.dwBlockSize = (EXT2_MIN_BLOCK_SIZE << Le32ToCpu(sb.s_log_block_size)); //sb.s_blocksize; //EXT2_BLOCK_SIZE(m_fs->super); showDebug(1, "blksize=%lu\n", m_info.dwBlockSize); m_info.dwFirstBlock = Le32ToCpu(sb.s_first_data_block); showDebug(1, "first=%lu\n", m_info.dwFirstBlock); m_info.dwTotalBlocksCount = Le32ToCpu(sb.s_blocks_count); showDebug(1, "total blocks=%lu\n", m_info.dwTotalBlocksCount); m_info.dwBlocksPerGroup = Le32ToCpu(sb.s_blocks_per_group); showDebug(1, "BlocksPerGroup=%lu\n", m_info.dwBlocksPerGroup); m_info.dwGroupsCount = (m_info.dwTotalBlocksCount - m_info.dwFirstBlock + m_info.dwBlocksPerGroup - 1) / Le32ToCpu(sb.s_blocks_per_group); showDebug(1, "groups=%lu\n", m_info.dwGroupsCount); m_info.dwLogicalBlocksPerExt2Block = m_info.dwBlockSize / LOGICAL_EXT2_BLKSIZE; showDebug(1, "m_info.dwLogicalBlocksPerExt2Block=%lu\n",m_info.dwLogicalBlocksPerExt2Block); showDebug(1, "logperblok=%lu\n", m_info.dwLogicalBlocksPerExt2Block); m_info.dwDescPerBlock = m_info.dwBlockSize / sizeof(CExt2GroupDesc); m_info.dwDescBlocks = (m_info.dwGroupsCount + m_info.dwDescPerBlock - 1) / m_info.dwDescPerBlock; //debugWin("m_info.dwDescBlocks=%lu",(DWORD)m_info.dwDescBlocks); // virtual blocks used in the abstract CFSBase m_header.qwBlocksCount = m_info.dwTotalBlocksCount * m_info.dwLogicalBlocksPerExt2Block; m_header.qwBlockSize = LOGICAL_EXT2_BLKSIZE; m_header.qwBitmapSize = ((m_header.qwBlocksCount+7) / 8)+16; m_header.qwUsedBlocks = (m_info.dwTotalBlocksCount - Le32ToCpu(sb.s_free_blocks_count)) * m_info.dwLogicalBlocksPerExt2Block; //debugWin("freeblks=%lu", sb.s_free_blocks_count); strncpy(m_header.szLabel, sb.s_volume_name, 64); // features m_info.dwFeatureCompat = Le32ToCpu(sb.s_feature_compat); m_info.dwFeatureIncompat = Le32ToCpu(sb.s_feature_incompat); m_info.dwFeatureRoCompat = Le32ToCpu(sb.s_feature_ro_compat); // misc infos m_info.dwRevLevel = Le32ToCpu(sb.s_rev_level); // Revision level memcpy(m_info.cUuid, sb.s_uuid, 16); // 128-bit uuid for volume //success_readSuperBlock: setSuperBlockInfos(true, true, m_header.qwUsedBlocks*m_header.qwBlockSize, ((QWORD)Le32ToCpu(sb.s_free_blocks_count)) * ((QWORD)m_info.dwBlockSize)); showDebug(1, "end success\n"); RETURN; error_readSuperBlock: g_interface -> ErrorReadingSuperblock(errno); THROW(ERR_WRONG_FS); }
void fp3_mul_basic(fp3_t c, fp3_t a, fp3_t b) { dv_t t, t0, t1, t2, t3, t4, t5, t6; dv_null(t); dv_null(t0); dv_null(t1); dv_null(t2); dv_null(t3); dv_null(t4); dv_null(t5); dv_null(t6); TRY { dv_new(t); dv_new(t0); dv_new(t1); dv_new(t2); dv_new(t3); dv_new(t4); dv_new(t5); dv_new(t6); /* Karatsuba algorithm. */ /* t0 = a_0 * b_0, t1 = a_1 * b_1, t2 = a_2 * b_2. */ fp_muln_low(t0, a[0], b[0]); fp_muln_low(t1, a[1], b[1]); fp_muln_low(t2, a[2], b[2]); /* t3 = (a_1 + a_2) * (b_1 + b_2). */ fp_add(t3, a[1], a[2]); fp_add(t4, b[1], b[2]); fp_muln_low(t, t3, t4); fp_addd_low(t6, t1, t2); fp_subc_low(t4, t, t6); fp_subc_low(t3, t0, t4); for (int i = -1; i > fp_prime_get_cnr(); i--) { fp_subc_low(t3, t3, t4); } fp_add(t4, a[0], a[1]); fp_add(t5, b[0], b[1]); fp_muln_low(t, t4, t5); fp_addd_low(t4, t0, t1); fp_subc_low(t4, t, t4); fp_subc_low(t4, t4, t2); for (int i = -1; i > fp_prime_get_cnr(); i--) { fp_subc_low(t4, t4, t2); } fp_add(t5, a[0], a[2]); fp_add(t6, b[0], b[2]); fp_muln_low(t, t5, t6); fp_addd_low(t6, t0, t2); fp_subc_low(t5, t, t6); fp_addc_low(t5, t5, t1); /* c_0 = t3 mod p. */ fp_rdc(c[0], t3); /* c_1 = t4 mod p. */ fp_rdc(c[1], t4); /* c_2 = t5 mod p. */ fp_rdc(c[2], t5); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { dv_free(t); dv_free(t0); dv_free(t1); dv_free(t2); dv_free(t3); dv_free(t4); dv_free(t5); dv_free(t6); } }
//=========================================================================== void SplineInterpolator::interpolate(int num_points, int dimension, const double* param_start, const double* data_start, std::vector<double>& coefs) //=========================================================================== { // Check that we have reasonable conditions set and a good param sequence ALWAYS_ERROR_IF(ctype_ == None, "No end conditions set."); for (int i = 1; i < num_points; ++i) { ALWAYS_ERROR_IF(param_start[i] <= param_start[i-1], "Parameter sequence must be strictly increasing."); } ALWAYS_ERROR_IF(ctype_ == Hermite && (dimension != start_tangent_->dimension() || dimension != end_tangent_->dimension()), "In Hermite interpolation, the end tangents must have the " "same dimension as the interpolation data."); // First we make a knot vector and define the spline space int additional_coefs = (ctype_ == Free) ? 0 : (((ctype_ == NaturalAtStart && end_tangent_.get() == 0) || (ctype_ == NaturalAtEnd && start_tangent_.get() == 0)) ? 1 : 2); int num_coefs = num_points + additional_coefs; int order = std::min(4, num_coefs); ALWAYS_ERROR_IF(num_coefs < 2,"Insufficient number of points."); std::vector<double> knots; knots.reserve(num_coefs + order); knots.insert(knots.end(), order, param_start[0]); if (ctype_ == Free) { knots.insert(knots.end(), param_start + 2, param_start + num_points - 2); } else if (ctype_ == NaturalAtStart) { if (end_tangent_.get() != 0) knots.insert(knots.end(), param_start + 1, param_start + num_points - 1); else knots.insert(knots.end(), param_start + 1, param_start + num_points - 2); } else if (ctype_ == NaturalAtEnd) { if (start_tangent_.get() != 0) knots.insert(knots.end(), param_start + 1, param_start + num_points - 1); else knots.insert(knots.end(), param_start + 2, param_start + num_points - 1); } else { // ctype_ == Natural or Hermite knots.insert(knots.end(), param_start + 1, param_start + num_points - 1); } knots.insert(knots.end(), order, param_start[num_points-1]); basis_ = BsplineBasis(num_coefs, order, &knots[0]); // Create the interpolation matrix. // The first and last row (equation) depends on the boundary // conditions (for Hermite and Natural conditions) or are // nonexisting (for Free conditions, the matrix has two fewer // rows/equations). // The interpolation matrix is a tridiagonal matrix in the Free // and Hermite cases, and a tridiagonal matrix plus two elements // in the Natural case. // This code dates from the time when this code was dependent on the NEWMAT // library. This is no longer the case, and the code has been substituted with // the code below. However, it is kept here for reference reasons. //---------------------NEWMAT dependent----------------------------- // #if 0 // cerr << "NEWMAT DEPENDENT" << endl; // BandMatrix A(num_coefs, 2, 2); // A = 0; // ColumnVector c(num_coefs); // ColumnVector b(num_coefs); // // Boundary conditions // if (ctype_ == Hermite) { // // Derivative conditions // double tmp[8]; // basis_.computeBasisValues(param_start[0], tmp, 1); // A.element(0, 0) = tmp[1]; // derivative of first B-spline // A.element(0, 1) = tmp[3]; // derivative of second B-spline // basis_.computeBasisValues(param_start[num_points-1], tmp, 1); // A.element(num_coefs - 1, num_coefs - 2) = tmp[5]; // A.element(num_coefs - 1, num_coefs - 1) = tmp[7]; // // Boundary element conditions // A.element(1, 0) = 1.0; // A.element(num_coefs - 2, num_coefs - 1) = 1.0; // } else if (ctype_ == Natural) { // // Derivative conditions // double tmp[12]; // basis_.computeBasisValues(param_start[0], tmp, 2); // A.element(0, 0) = tmp[2]; // second derivative of first B-spline // A.element(0, 1) = tmp[5]; // A.element(0, 2) = tmp[8]; // basis_.computeBasisValues(param_start[num_points-1], tmp, 2); // A.element(num_coefs - 1, num_coefs - 3) = tmp[5]; // A.element(num_coefs - 1, num_coefs - 2) = tmp[8]; // A.element(num_coefs - 1, num_coefs - 1) = tmp[11]; // // Boundary element conditions // A.element(1, 0) = 1.0; // A.element(num_coefs - 2, num_coefs - 1) = 1.0; // } else if (ctype_ == NaturalAtStart) { // // Derivative condition // double tmp[12]; // basis_.computeBasisValues(param_start[0], tmp, 2); // A.element(0, 0) = tmp[2]; // second derivative of first B-spline // A.element(0, 1) = tmp[5]; // A.element(0, 2) = tmp[8]; // if (end_tangent_.get() != 0) { // double tmp[8]; // basis_.computeBasisValues(param_start[num_points-1], tmp, 1); // A.element(num_coefs - 1, num_coefs - 2) = tmp[5]; // A.element(num_coefs - 1, num_coefs - 1) = tmp[7]; // A.element(num_coefs - 2, num_coefs - 1) = 1.0; // } else { // A.element(num_coefs - 1, num_coefs - 1) = 1.0; // } // // Boundary element conditions // A.element(1, 0) = 1.0; // } else if (ctype_ == NaturalAtEnd) { // // Derivative condition // double tmp[12]; // basis_.computeBasisValues(param_start[num_points-1], tmp, 2); // A.element(num_coefs - 1, num_coefs - 3) = tmp[5]; // A.element(num_coefs - 1, num_coefs - 2) = tmp[8]; // A.element(num_coefs - 1, num_coefs - 1) = tmp[11]; // if (start_tangent_.get() != 0) { // basis_.computeBasisValues(param_start[0], tmp, 1); // A.element(0, 0) = tmp[1]; // derivative of first B-spline // A.element(0, 1) = tmp[3]; // derivative of second B-spline // A.element(1, 0) = 1.0; // } else { // A.element(0, 0) = 1.0; // } // // Boundary element conditions // A.element(num_coefs - 2, num_coefs - 1) = 1.0; // } else if (ctype_ == Free) { // // Boundary element conditions // A.element(0, 0) = 1.0; // A.element(num_coefs - 1, num_coefs - 1) = 1.0; // } else { // THROW("Unknown boundary condition type: " << ctype_); // } // // Interior conditions // int rowoffset = ((ctype_ == Free) || // ((ctype_ == NaturalAtEnd) && (start_tangent_.get() == 0)) ? 1 : 2); // int j; // for (j = 0; j < num_points-2; ++j) { // double tmp[4]; // basis_.computeBasisValues(param_start[j+1], tmp, 0); // int column = 1 + (basis_.lastKnotInterval() - 4); // A.element(j + rowoffset, column) = tmp[0]; // A.element(j + rowoffset, column + 1) = tmp[1]; // A.element(j + rowoffset, column + 2) = tmp[2]; // A.element(j + rowoffset, column + 3) = tmp[3]; // } // // Now we are ready to repeatedly solve Ac = b for # = dimension different // // right-hand-sides b. // BandLUMatrix ALUfact = A; // Computes LU factorization // ALWAYS_ERROR_IF(ALUfact.IsSingular(), // "Matrix is singular! This should never happen!"); // coefs.resize(dimension*num_coefs); // for (int dd = 0; dd < dimension; ++dd) { // // Make the b vector // int offset = (ctype_ == Free || // ((ctype_ == NaturalAtEnd) && start_tangent_.get() == 0) ? 0 : 1); // if (ctype_ == Hermite) { // b.element(0) = (*start_tangent_)[dd]; // b.element(num_coefs - 1) = (*end_tangent_)[dd]; // } else if (ctype_ == Natural) { // b.element(0) = 0; // b.element(num_coefs - 1) = 0; // } else if (ctype_ == NaturalAtStart) { // b.element(0) = 0; // if (end_tangent_.get() != 0) // b.element(num_coefs - 1) = (*end_tangent_)[dd]; // } else if (ctype_ == NaturalAtEnd) { // b.element(num_coefs - 1) = 0; // if (start_tangent_.get() != 0) // b.element(0) = (*start_tangent_)[dd]; // } // for (j = 0; j < num_points; ++j) { // b.element(j+offset) = data_start[j*dimension + dd]; // } // // Solve // c = ALUfact.i() * b; // // Copy results // for (j = 0; j < num_coefs; ++j) { // coefs[j*dimension + dd] = c.element(j); // } // } // -------------------NEWMAT INDEPENDENT------------------------------ //#else vector<vector<double> > A(num_coefs, vector<double>(num_coefs, 0)); vector<vector<double> > b(num_coefs, vector<double>(dimension)); double tmp[12]; // boundary conditions switch (ctype_) { case Hermite: basis_.computeBasisValues(param_start[0], tmp, 1); A[0][0] = tmp[1]; // derivative of first B-spline A[0][1] = tmp[3]; // derivative of second B-spline basis_.computeBasisValues(param_start[num_points-1], tmp, 1); A[num_coefs - 1][num_coefs - 2] = tmp[5]; A[num_coefs - 1][num_coefs - 1] = tmp[7]; // Boundary element conditions A[1][0] = 1.0; A[num_coefs - 2][num_coefs - 1] = 1.0; break; case Natural: // Derivative conditions basis_.computeBasisValues(param_start[0], tmp, 2); A[0][0] = tmp[2]; // second derivative of first B-spline A[0][1] = tmp[5]; A[0][2] = tmp[8]; basis_.computeBasisValues(param_start[num_points-1], tmp, 2); A[num_coefs - 1][num_coefs - 3] = tmp[5]; A[num_coefs - 1][num_coefs - 2] = tmp[8]; A[num_coefs - 1][num_coefs - 1] = tmp[11]; // Boundary element conditions A[1][0] = 1.0; A[num_coefs - 2][num_coefs - 1] = 1.0; break; case NaturalAtStart: basis_.computeBasisValues(param_start[0], tmp, 2); A[0][0] = tmp[2]; // second derivative of first B-spline A[0][1] = tmp[5]; A[0][2] = tmp[8]; if (end_tangent_.get() != 0) { double tmp[8]; basis_.computeBasisValues(param_start[num_points-1], tmp, 1); A[num_coefs - 1][num_coefs - 2] = tmp[5]; A[num_coefs - 1][num_coefs - 1] = tmp[7]; A[num_coefs - 2][num_coefs - 1] = 1.0; } else { A[num_coefs - 1][num_coefs - 1] = 1.0; } // Boundary element conditions A[1][0] = 1.0; break; case NaturalAtEnd: basis_.computeBasisValues(param_start[num_points-1], tmp, 2); A[num_coefs - 1][num_coefs - 3] = tmp[5]; A[num_coefs - 1][num_coefs - 2] = tmp[8]; A[num_coefs - 1][num_coefs - 1] = tmp[11]; if (start_tangent_.get() != 0) { basis_.computeBasisValues(param_start[0], tmp, 1); A[0][0] = tmp[1]; // derivative of first B-spline A[0][1] = tmp[3]; // derivative of second B-spline A[1][0] = 1.0; } else { A[0][0] = 1.0; } // Boundary element conditions A[num_coefs - 2][num_coefs - 1] = 1.0; break; case Free: // Boundary element conditions A[0][0] = 1.0; A[num_coefs - 1][num_coefs - 1] = 1.0; break; default: THROW("Unknown boundary condition type." << ctype_); } // interior conditions int rowoffset = ((ctype_ == Free) || ((ctype_ == NaturalAtEnd) && (start_tangent_.get() == 0)) ? 1 : 2); int j; for (j = 0; j < num_points-2; ++j) { basis_.computeBasisValues(param_start[j+1], tmp, 0); int column = 1 + (basis_.lastKnotInterval() - 4); A[j + rowoffset][column] = tmp[0]; A[j + rowoffset][column + 1] = tmp[1]; A[j + rowoffset][column + 2] = tmp[2]; A[j + rowoffset][column + 3] = tmp[3]; } // make the b vectors boundary condition int offset = (ctype_ == Free || ((ctype_ == NaturalAtEnd) && start_tangent_.get() == 0) ? 0 : 1); switch(ctype_) { case Hermite: copy(start_tangent_->begin(), start_tangent_->end(), b[0].begin()); copy(end_tangent_->begin(), end_tangent_->end(), b[num_coefs-1].begin()); break; case Natural: b[0] = b[num_coefs-1] = vector<double>(dimension, 0); break; case NaturalAtStart: b[0] = vector<double>(dimension, 0); if (end_tangent_.get() != 0) copy(end_tangent_->begin(), end_tangent_->end(), b[num_coefs-1].begin()); break; case NaturalAtEnd: b[num_coefs-1] = vector<double>(dimension, 0); if (start_tangent_.get() != 0) copy(start_tangent_->begin(), start_tangent_->end(), b[0].begin()); break; default: // do nothing break; } // fill in interior of the b vectors for (j = 0; j < num_points; ++j) { copy(&(data_start[j * dimension]), &(data_start[(j+1) * dimension]), b[j + offset].begin()); } // computing the unknown vector A c = b. b is overwritten by this unknown vector LUsolveSystem(A, num_coefs, &b[0]); // writing result to coefficients coefs.resize(dimension*num_coefs); for (int j = 0; j < num_coefs; ++j) { copy(b[j].begin(), b[j].end(), &coefs[j*dimension]); } //#endif }
/* See Table 6-52 in CM-SP-MULPIv3.0-I14-101008 */ static void dissect_cmstatus_tlv (tvbuff_t * tvb, proto_tree * tree, guint8 start, guint16 len) { proto_item *it; proto_tree *tlv_tree; guint8 pos = start + 1; guint8 type, length; it = proto_tree_add_protocol_format (tree, proto_docsis_cmstatus, tvb, 0, len, "TLV Data"); tlv_tree = proto_item_add_subtree (it, ett_docsis_cmstatus_tlv); while (pos < (len + start + 1)) { length = tvb_get_guint8 (tvb, pos++); type = tvb_get_guint8 (tvb, pos++); switch (type) { case EVENT_DS_CH_ID: if (length == 3) { proto_tree_add_item (tlv_tree, hf_docsis_cmstatus_ds_ch_id, tvb, pos + 1, 1, ENC_BIG_ENDIAN); } else { THROW (ReportedBoundsError); } break; case EVENT_US_CH_ID: if (length == 3) { proto_tree_add_item (tlv_tree, hf_docsis_cmstatus_us_ch_id, tvb, pos + 1, 1, ENC_BIG_ENDIAN); } else { THROW (ReportedBoundsError); } break; case EVENT_DSID: if (length == 5) { proto_tree_add_item (tlv_tree, hf_docsis_cmstatus_dsid, tvb, pos + 1, 3, ENC_BIG_ENDIAN); } else { THROW (ReportedBoundsError); } break; case EVENT_DESCR: if (length >= 3 && length <= 82) { proto_tree_add_item (tlv_tree, hf_docsis_cmstatus_descr, tvb, pos + 1, length - 2, ENC_NA); } else { THROW (ReportedBoundsError); } break; } /* switch */ pos = pos + length; } /* while */ }
void RawPost_Destroy_IMP(RawPosting *self) { UNUSED_VAR(self); THROW(ERR, "Illegal attempt to destroy RawPosting object"); }
void pp_dbl_k2_projc_lazyr(fp2_t l, ep_t r, ep_t p, ep_t q) { fp_t t0, t1, t2, t3, t4, t5; dv_t u0, u1; fp_null(t0); fp_null(t1); fp_null(t2); fp_null(t3); fp_null(t4); fp_null(t5); dv_null(u0); dv_null(u1); TRY { fp_new(t0); fp_new(t1); fp_new(t2); fp_new(t3); fp_new(t4); fp_new(t5); dv_new(u0); dv_new(u1); /* For these curves, we always can choose a = -3. */ /* dbl-2001-b formulas: 3M + 5S + 8add + 1*4 + 2*8 + 1*3 */ /* http://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b */ /* t0 = delta = z1^2. */ fp_sqr(t0, p->z); /* t1 = gamma = y1^2. */ fp_sqr(t1, p->y); /* t2 = beta = x1 * y1^2. */ fp_mul(t2, p->x, t1); /* t3 = alpha = 3 * (x1 - z1^2) * (x1 + z1^2). */ fp_sub(t3, p->x, t0); fp_add(t4, p->x, t0); fp_mul(t4, t3, t4); fp_dbl(t3, t4); fp_add(t3, t3, t4); /* t2 = 4 * beta. */ fp_dbl(t2, t2); fp_dbl(t2, t2); /* z3 = (y1 + z1)^2 - gamma - delta. */ fp_add(r->z, p->y, p->z); fp_sqr(r->z, r->z); fp_sub(r->z, r->z, t1); fp_sub(r->z, r->z, t0); /* l0 = 2 * gamma - alpha * (delta * xq + x1). */ fp_dbl(t1, t1); fp_mul(t5, t0, q->x); fp_add(t5, t5, p->x); fp_mul(t5, t5, t3); fp_sub(l[0], t1, t5); /* x3 = alpha^2 - 8 * beta. */ fp_dbl(t5, t2); fp_sqr(r->x, t3); fp_sub(r->x, r->x, t5); /* y3 = alpha * (4 * beta - x3) - 8 * gamma^2. */ fp_sqrn_low(u0, t1); fp_addc_low(u0, u0, u0); fp_subm_low(r->y, t2, r->x); fp_muln_low(u1, r->y, t3); fp_subc_low(u1, u1, u0); fp_rdcn_low(r->y, u1); /* l1 = - z3 * delta * yq. */ fp_mul(l[1], r->z, t0); fp_mul(l[1], l[1], q->y); r->norm = 0; } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t0); fp_free(t1); fp_free(t2); fp_free(t3); fp_free(t4); fp_free(t5); dv_free(u0); dv_free(u1); } }
size_t FileEntitySchemeInputStream::Read(void* data, size_t size) { BEGIN_TRY(); if(ended) return 0; char* dataPtr = (char*)data; // don't allow to read more than remaining size if((bigsize_t)size > remainingSize) size = (size_t)remainingSize; while(size) { if(!currentBlockFile || currentBlockOffset >= currentBlockFile->GetSize()) { // read next block // reset offset currentBlockOffset = 0; // get the block currentBlockFile = entity->ReadData(GetBlockName(currentBlockIndex)); if(!currentBlockFile) THROW("Can't read next block"); // increment index for next block ++currentBlockIndex; // write it into total hash stream totalHashStream->Write(currentBlockFile); // read and check the hash size_t hashSize = hashStream->GetHashSize(); ptr<File> hashFromDescriptor = descriptorReader->Read(hashSize); hashStream->Reset(); hashStream->Write(currentBlockFile); hashStream->End(); ptr<File> hashFromBlock = NEW(MemoryFile(hashSize)); hashStream->GetHash(hashFromBlock->GetData()); if(memcmp(hashFromDescriptor->GetData(), hashFromBlock->GetData(), hashSize) != 0) THROW("Wrong hash"); } size_t sizeToCopy = currentBlockFile->GetSize() - currentBlockOffset; if(sizeToCopy > size) sizeToCopy = size; memcpy(dataPtr, (const char*)currentBlockFile->GetData() + currentBlockOffset, sizeToCopy); dataPtr += sizeToCopy; size -= sizeToCopy; currentBlockOffset += sizeToCopy; remainingSize -= sizeToCopy; } // if there is no more data, check that data is actually ends if(remainingSize <= 0) { ended = true; // check total hash totalHashStream->End(); size_t hashSize = totalHashStream->GetHashSize(); ptr<File> totalHash = NEW(MemoryFile(hashSize)); totalHashStream->GetHash(totalHash->GetData()); if(memcmp(totalHash->GetData(), totalHashFromDescriptor->GetData(), hashSize) != 0) THROW("Wrong total hash"); // check that last block is over if(currentBlockFile && currentBlockOffset < currentBlockFile->GetSize()) THROW("Last block is not over"); // check that last block is last descriptorReader->ReadEnd(); } return dataPtr - (char*)data; END_TRY("Can't read data from file entity"); }
void pp_dbl_k12_projc_lazyr(fp12_t l, ep2_t r, ep2_t q, ep_t p) { fp2_t t0, t1, t2, t3, t4, t5, t6; dv2_t u0, u1; int one = 1, zero = 0; fp2_null(t0); fp2_null(t1); fp2_null(t2); fp2_null(t3); fp2_null(t4); fp2_null(t5); fp2_null(t6); dv2_null(u0); dv2_null(u1); TRY { fp2_new(t0); fp2_new(t1); fp2_new(t2); fp2_new(t3); fp2_new(t4); fp2_new(t5); fp2_new(t6); dv2_new(u0); dv2_new(u1); if (ep2_curve_is_twist() == EP_MTYPE) { one ^= 1; zero ^= 1; } if (ep_curve_opt_b() == RLC_TWO) { /* C = z1^2. */ fp2_sqr(t0, q->z); /* B = y1^2. */ fp2_sqr(t1, q->y); /* t5 = B + C. */ fp2_add(t5, t0, t1); /* t3 = E = 3b'C = 3C * (1 - i). */ fp2_dbl(t3, t0); fp2_add(t0, t0, t3); fp_add(t2[0], t0[0], t0[1]); fp_sub(t2[1], t0[1], t0[0]); /* t0 = x1^2. */ fp2_sqr(t0, q->x); /* t4 = A = (x1 * y1)/2. */ fp2_mul(t4, q->x, q->y); fp_hlv(t4[0], t4[0]); fp_hlv(t4[1], t4[1]); /* t3 = F = 3E. */ fp2_dbl(t3, t2); fp2_add(t3, t3, t2); /* x3 = A * (B - F). */ fp2_sub(r->x, t1, t3); fp2_mul(r->x, r->x, t4); /* G = (B + F)/2. */ fp2_add(t3, t1, t3); fp_hlv(t3[0], t3[0]); fp_hlv(t3[1], t3[1]); /* y3 = G^2 - 3E^2. */ fp2_sqrn_low(u0, t2); fp2_addd_low(u1, u0, u0); fp2_addd_low(u1, u1, u0); fp2_sqrn_low(u0, t3); fp2_subc_low(u0, u0, u1); /* H = (Y + Z)^2 - B - C. */ fp2_add(t3, q->y, q->z); fp2_sqr(t3, t3); fp2_sub(t3, t3, t5); fp2_rdcn_low(r->y, u0); /* z3 = B * H. */ fp2_mul(r->z, t1, t3); /* l11 = E - B. */ fp2_sub(l[1][1], t2, t1); /* l10 = (3 * xp) * t0. */ fp_mul(l[one][zero][0], p->x, t0[0]); fp_mul(l[one][zero][1], p->x, t0[1]); /* l01 = F * (-yp). */ fp_mul(l[zero][zero][0], t3[0], p->y); fp_mul(l[zero][zero][1], t3[1], p->y); } else { /* A = x1^2. */ fp2_sqr(t0, q->x); /* B = y1^2. */ fp2_sqr(t1, q->y); /* C = z1^2. */ fp2_sqr(t2, q->z); /* D = 3bC, for general b. */ fp2_dbl(t3, t2); fp2_add(t3, t3, t2); ep2_curve_get_b(t4); fp2_mul(t3, t3, t4); /* E = (x1 + y1)^2 - A - B. */ fp2_add(t4, q->x, q->y); fp2_sqr(t4, t4); fp2_sub(t4, t4, t0); fp2_sub(t4, t4, t1); /* F = (y1 + z1)^2 - B - C. */ fp2_add(t5, q->y, q->z); fp2_sqr(t5, t5); fp2_sub(t5, t5, t1); fp2_sub(t5, t5, t2); /* G = 3D. */ fp2_dbl(t6, t3); fp2_add(t6, t6, t3); /* x3 = E * (B - G). */ fp2_sub(r->x, t1, t6); fp2_mul(r->x, r->x, t4); /* y3 = (B + G)^2 -12D^2. */ fp2_add(t6, t6, t1); fp2_sqr(t6, t6); fp2_sqr(t2, t3); fp2_dbl(r->y, t2); fp2_dbl(t2, r->y); fp2_dbl(r->y, t2); fp2_add(r->y, r->y, t2); fp2_sub(r->y, t6, r->y); /* z3 = 4B * F. */ fp2_dbl(r->z, t1); fp2_dbl(r->z, r->z); fp2_mul(r->z, r->z, t5); /* l00 = D - B. */ fp2_sub(l[one][one], t3, t1); /* l10 = (3 * xp) * A. */ fp_mul(l[one][zero][0], p->x, t0[0]); fp_mul(l[one][zero][1], p->x, t0[1]); /* l01 = F * (-yp). */ fp_mul(l[zero][zero][0], t5[0], p->y); fp_mul(l[zero][zero][1], t5[1], p->y); } r->norm = 0; } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp2_free(t0); fp2_free(t1); fp2_free(t2); fp2_free(t3); fp2_free(t4); fp2_free(t5); fp2_free(t6); dv2_free(u0); dv2_free(u1); } }
void CRCFile::ProcessDialog(UINT uiDialogID, std::vector<CString>::iterator *init) { element_map* pElementMap = GetElementMap(uiDialogID); if(!pElementMap) return; CString str; for (; (*init) != m_vInRCFile.end(); (*init)++) { str=**init; str.TrimLeft(_T(" ")); str.TrimRight(_T(" ")); // check for exit if ( str == _T("END") ) { // add the line to the outrc wo changes m_vOutRCFile.push_back(**init); return; } else if ( str.Left(7) == _T("CAPTION") ) { // read the caption CString strText=str.Mid(7); strText.TrimLeft(_T(" \t\"")); strText.TrimRight(_T(" \t\"")); pElementMap->insert(std::make_pair(0, strText)); // save to rc wo title str=**init; str.Replace(_T("\"")+strText+_T("\""), _T("\"\"")); m_vOutRCFile.push_back(str); } else if ( str.Left(5) == _T("LTEXT") || str.Left(5) == _T("CTEXT") || str.Left(5) == _T("RTEXT") || str.Left(13) == _T("DEFPUSHBUTTON") || str.Left(10) == _T("PUSHBUTTON") || str.Left(7) == _T("CONTROL") || str.Left(8) == _T("GROUPBOX") ) { // needed only 2 commas (outside the '\"') if ( GetCommasCount(str) < 3 ) str+=*((*init)+1); // the first thing after LTEXT(and other) is the caption CString strText; bool bControl = false; if (str.Left(5) == _T("LTEXT") || str.Left(5) == _T("CTEXT") || str.Left(5) == _T("RTEXT")) str=str.Mid(5); else if (str.Left(13) == _T("DEFPUSHBUTTON")) str=str.Mid(13); else if (str.Left(10) == _T("PUSHBUTTON")) str=str.Mid(10); else if (str.Left(7) == _T("CONTROL")) { bControl = true; str=str.Mid(7); } else if (str.Left(8) == _T("GROUPBOX")) str=str.Mid(8); str=str.Mid(str.Find(_T("\""))+1); int iPos=str.Find(_T("\""), 0); if (iPos != -1) strText=str.Left(iPos); else THROW(_T("Error: cannot find a comma in processed text"), 0, 0, 0); str = str.Mid(iPos+1); // after the first comma there is an ID iPos=str.Find(_T(","), 0); CString strID; if (iPos != -1) { str=str.Mid(iPos+1); iPos=str.Find(_T(","), 0); if (iPos != -1) strID=str.Left(iPos); else THROW(_T("Error: cannot find a comma in processed text"), 0, 0, 0); strID.TrimLeft(_T(" \t")); strID.TrimRight(_T(" \t")); } else THROW(_T("Error: cannot find a comma in processed text"), 0, 0, 0); bool bSkip = false; if(bControl) { str = str.Mid(iPos+1); iPos = str.Find(_T(","), 0); if(iPos == -1) THROW(_T("Error: cannot find a comma in processed text"), 0, 0, 0); CString strType = str.Left(iPos); strType.Trim(_T("\"")); if(strType == _T("SysListView32") || strType == _T("msctls_progress32") || strType == _T("ComboBoxEx32") || strType == _T("msctls_updown32") || strType == _T("SysDateTimePick32")) { bSkip = true; } } if(!bSkip) { // find id UINT uiID = GetResourceID(strID); CString out; pElementMap->insert(std::make_pair(uiID, strText)); } // now add the data to output rc str=**init; str.Replace(_T("\"")+strText+_T("\""), _T("\"\"")); m_vOutRCFile.push_back(str); } else m_vOutRCFile.push_back(**init); } }
void pp_dbl_lit_k12(fp12_t l, ep_t r, ep_t p, ep2_t q) { fp_t t0, t1, t2, t3, t4, t5, t6; int one = 1, zero = 0; fp_null(t0); fp_null(t1); fp_null(t2); fp_null(t3); fp_null(t4); fp_null(t5); fp_null(t6); TRY { fp_new(t0); fp_new(t1); fp_new(t2); fp_new(t3); fp_new(t4); fp_new(t5); fp_new(t6); fp_sqr(t0, p->x); fp_sqr(t1, p->y); fp_sqr(t2, p->z); fp_mul(t4, ep_curve_get_b(), t2); fp_dbl(t3, t4); fp_add(t3, t3, t4); fp_add(t4, p->x, p->y); fp_sqr(t4, t4); fp_sub(t4, t4, t0); fp_sub(t4, t4, t1); fp_add(t5, p->y, p->z); fp_sqr(t5, t5); fp_sub(t5, t5, t1); fp_sub(t5, t5, t2); fp_dbl(t6, t3); fp_add(t6, t6, t3); fp_sub(r->x, t1, t6); fp_mul(r->x, r->x, t4); fp_add(r->y, t1, t6); fp_sqr(r->y, r->y); fp_sqr(t4, t3); fp_dbl(t6, t4); fp_add(t6, t6, t4); fp_dbl(t6, t6); fp_dbl(t6, t6); fp_sub(r->y, r->y, t6); fp_mul(r->z, t1, t5); fp_dbl(r->z, r->z); fp_dbl(r->z, r->z); r->norm = 0; if (ep2_curve_is_twist() == EP_MTYPE) { one ^= 1; zero ^= 1; } fp2_dbl(l[zero][one], q->x); fp2_add(l[zero][one], l[zero][one], q->x); fp_mul(l[zero][one][0], l[zero][one][0], t0); fp_mul(l[zero][one][1], l[zero][one][1], t0); fp_sub(l[zero][zero][0], t3, t1); fp_zero(l[zero][zero][1]); fp_mul(l[one][one][0], q->y[0], t5); fp_mul(l[one][one][1], q->y[1], t5); } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { fp_free(t0); fp_free(t1); fp_free(t2); fp_free(t3); fp_free(t4); fp_free(t5); fp_free(t6); } }
uint32_t cfish_get_refcount(void *vself) { THROW(CFISH_ERR, "TODO"); UNREACHABLE_RETURN(uint32_t); }
static void check_relation_LHS_RANGE(dfwork_t *dfw, const char *relation_string, FtypeCanFunc can_func _U_, gboolean allow_partial_value, stnode_t *st_node, stnode_t *st_arg1, stnode_t *st_arg2) { stnode_t *new_st; sttype_id_t type2; stnode_t *entity1; header_field_info *hfinfo1, *hfinfo2; ftenum_t ftype1, ftype2; fvalue_t *fvalue; char *s; int len_range; DebugLog((" 5 check_relation_LHS_RANGE(%s)\n", relation_string)); type2 = stnode_type_id(st_arg2); entity1 = sttype_range_entity(st_arg1); if (entity1 && stnode_type_id(entity1) == STTYPE_FIELD) { hfinfo1 = (header_field_info *)stnode_data(entity1); ftype1 = hfinfo1->type; if (!ftype_can_slice(ftype1)) { dfilter_fail(dfw, "\"%s\" is a %s and cannot be sliced into a sequence of bytes.", hfinfo1->abbrev, ftype_pretty_name(ftype1)); THROW(TypeError); } } else if (entity1 && stnode_type_id(entity1) == STTYPE_FUNCTION) { df_func_def_t *funcdef = sttype_function_funcdef(entity1); ftype1 = funcdef->retval_ftype; if (!ftype_can_slice(ftype1)) { dfilter_fail(dfw, "Return value of function \"%s\" is a %s and cannot be converted into a sequence of bytes.", funcdef->name, ftype_pretty_name(ftype1)); THROW(TypeError); } check_function(dfw, entity1); } else { if (entity1 == NULL) { dfilter_fail(dfw, "Range is not supported, details: " G_STRLOC " entity: NULL"); } else { dfilter_fail(dfw, "Range is not supported, details: " G_STRLOC " entity: %p of type %d", (void *)entity1, stnode_type_id(entity1)); } THROW(TypeError); } check_drange_sanity(dfw, st_arg1); if (type2 == STTYPE_FIELD) { DebugLog((" 5 check_relation_LHS_RANGE(type2 = STTYPE_FIELD)\n")); hfinfo2 = (header_field_info*)stnode_data(st_arg2); ftype2 = hfinfo2->type; if (!is_bytes_type(ftype2)) { if (!ftype_can_slice(ftype2)) { dfilter_fail(dfw, "\"%s\" is a %s and cannot be converted into a sequence of bytes.", hfinfo2->abbrev, ftype_pretty_name(ftype2)); THROW(TypeError); } /* Convert entire field to bytes */ new_st = convert_to_bytes(st_arg2); sttype_test_set2_args(st_node, st_arg1, new_st); } } else if (type2 == STTYPE_STRING) { DebugLog((" 5 check_relation_LHS_RANGE(type2 = STTYPE_STRING)\n")); s = (char*)stnode_data(st_arg2); if (strcmp(relation_string, "matches") == 0) { /* Convert to a FT_PCRE */ fvalue = dfilter_fvalue_from_string(dfw, FT_PCRE, s); } else { fvalue = dfilter_fvalue_from_string(dfw, FT_BYTES, s); } if (!fvalue) { DebugLog((" 5 check_relation_LHS_RANGE(type2 = STTYPE_STRING): Could not convert from string!\n")); THROW(TypeError); } new_st = stnode_new(STTYPE_FVALUE, fvalue); sttype_test_set2_args(st_node, st_arg1, new_st); stnode_free(st_arg2); } else if (type2 == STTYPE_UNPARSED) { DebugLog((" 5 check_relation_LHS_RANGE(type2 = STTYPE_UNPARSED)\n")); s = (char*)stnode_data(st_arg2); len_range = drange_get_total_length(sttype_range_drange(st_arg1)); if (strcmp(relation_string, "matches") == 0) { /* Convert to a FT_PCRE */ fvalue = dfilter_fvalue_from_unparsed(dfw, FT_PCRE, s, FALSE); } /* The RHS should be FT_BYTES. However, there is a special case where * the range slice on the LHS is one byte long. In that case, it is natural * for the user to specify a normal hex integer on the RHS, with the "0x" * notation, as in "slice[0] == 0x10". We can't allow this for any * slices that are longer than one byte, because then we'd have to know * which endianness the byte string should be in. */ else if (len_range == 1 && strlen(s) == 4 && strncmp(s, "0x", 2) == 0) { /* Even if the RHS string starts with "0x", it still could fail to * be an integer. Try converting it here. */ fvalue = dfilter_fvalue_from_unparsed(dfw, FT_UINT8, s, allow_partial_value); if (fvalue) { FVALUE_FREE(fvalue); /* The value doees indeed fit into 8 bits. Create a BYTE_STRING * from it. Since we know that the last 2 characters are a valid * hex string, just use those directly. */ fvalue = dfilter_fvalue_from_unparsed(dfw, FT_BYTES, s+2, allow_partial_value); } } else { fvalue = dfilter_fvalue_from_unparsed(dfw, FT_BYTES, s, allow_partial_value); } if (!fvalue) { DebugLog((" 5 check_relation_LHS_RANGE(type2 = STTYPE_UNPARSED): Could not convert from string!\n")); THROW(TypeError); } new_st = stnode_new(STTYPE_FVALUE, fvalue); sttype_test_set2_args(st_node, st_arg1, new_st); stnode_free(st_arg2); } else if (type2 == STTYPE_RANGE) { DebugLog((" 5 check_relation_LHS_RANGE(type2 = STTYPE_RANGE)\n")); check_drange_sanity(dfw, st_arg2); } else if (type2 == STTYPE_FUNCTION) { df_func_def_t *funcdef = sttype_function_funcdef(st_arg2); ftype2 = funcdef->retval_ftype; if (!is_bytes_type(ftype2)) { if (!ftype_can_slice(ftype2)) { dfilter_fail(dfw, "Return value of function \"%s\" is a %s and cannot be converted into a sequence of bytes.", funcdef->name, ftype_pretty_name(ftype2)); THROW(TypeError); } /* Convert function result to bytes */ new_st = convert_to_bytes(st_arg2); sttype_test_set2_args(st_node, st_arg1, new_st); } check_function(dfw, st_arg2); } else if (type2 == STTYPE_SET) { dfilter_fail(dfw, "Only a field may be tested for membership in a set."); THROW(TypeError); } else { g_assert_not_reached(); } }