void cPluginManager::FindPlugins(void) { AString PluginsPath = FILE_IO_PREFIX + AString( "Plugins/" ); // First get a clean list of only the currently running plugins, we don't want to mess those up for (PluginMap::iterator itr = m_Plugins.begin(); itr != m_Plugins.end();) { if (itr->second == NULL) { PluginMap::iterator thiz = itr; ++thiz; m_Plugins.erase( itr ); itr = thiz; continue; } ++itr; } AStringVector Files = cFile::GetFolderContents(PluginsPath.c_str()); for (AStringVector::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { if ((*itr == ".") || (*itr == "..") || (!cFile::IsFolder(PluginsPath + *itr))) { // We only want folders, and don't want "." or ".." continue; } // Add plugin name/directory to the list if (m_Plugins.find(*itr) == m_Plugins.end()) { m_Plugins[*itr] = NULL; } } }
AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage) { if (!srcString.IsEmpty()) { const wchar_t * wcs = &srcString[0]; char utf8[4096]; UniChar unipath[4096]; size_t n = wcslen(wcs); for(size_t i = 0 ; i<= n ;i++) { unipath[i] = wcs[i]; } CFStringRef cfpath = CFStringCreateWithCharacters(NULL,unipath,n); CFMutableStringRef cfpath2 = CFStringCreateMutableCopy(NULL,0,cfpath); CFRelease(cfpath); CFStringNormalize(cfpath2,kCFStringNormalizationFormD); CFStringGetCString(cfpath2,(char *)utf8,4096,kCFStringEncodingUTF8); CFRelease(cfpath2); return AString(utf8); } AString resultString; for (int i = 0; i < srcString.Len(); i++) { if (srcString[i] >= 256) resultString += '?'; else resultString += char(srcString[i]); } return resultString; }
AString cWebAdmin::GetDefaultPage(void) { AString Content; Content += "<h4>Server Name:</h4>"; Content += "<p>" + AString( cRoot::Get()->GetServer()->GetServerID() ) + "</p>"; Content += "<h4>Plugins:</h4><ul>"; cPluginManager * PM = cPluginManager::Get(); const cPluginManager::PluginMap & List = PM->GetAllPlugins(); for (cPluginManager::PluginMap::const_iterator itr = List.begin(); itr != List.end(); ++itr) { if (itr->second == NULL) { continue; } AString VersionNum; AppendPrintf(Content, "<li>%s V.%i</li>", itr->second->GetName().c_str(), itr->second->GetVersion()); } Content += "</ul>"; Content += "<h4>Players:</h4><ul>"; cPlayerAccum PlayerAccum; cWorld * World = cRoot::Get()->GetDefaultWorld(); // TODO - Create a list of worlds and players if( World != NULL ) { World->ForEachPlayer(PlayerAccum); Content.append(PlayerAccum.m_Contents); } Content += "</ul><br>"; return Content; }
ADVBConfig::ADVBConfig() : config(AString(DEFAULTCONFDIR).CatPath("dvb"), false), defaults(20, &AString::DeleteString), webresponse(false) { static const struct { const char *name; const char *value; } __defaults[] = { {"prehandle", "2"}, {"posthandle", "3"}, {"pri", "0"}, {"dir", ""}, {"h264crf", "17"}, {"maxvideorate", "2000k"}, {"aacbitrate", "160k"}, {"mp3bitrate", "160k"}, {"copyvideo", "-vcodec copy"}, {"copyaudio", "-acodec copy"}, {"mp3audio", "-acodec mp3 -b:a {conf:mp3bitrate}"}, {"h264preset", "veryfast"}, {"h264bufsize", "3000k"}, {"videodeinterlace", "yadif"}, {"videofilter", "-filter:v {conf:videodeinterlace}"}, {"filters", "{conf:videofilter} {conf:audiofilter}"}, {"encodeflags", "-movflags +faststart"}, {"h264video", "-vcodec libx264 -preset {conf:h264preset} -crf {conf:h264crf} -maxrate {conf:maxvideorate} -bufsize {conf:h264bufsize} {conf:encodeflags} {conf:filters}"}, {"aacaudio", "-acodec libfdk_aac -b:a {conf:aacbitrate}"}, {"encodecopy", "{conf:copyvideo} {conf:mp3audio}"}, {"encodeh264", "{conf:h264video} {conf:aacaudio}"}, {"encodeargs", "{conf:encodeh264}"}, {"encodeaudioonlyargs", "{conf:mp3audio}"}, }; uint_t i; for (i = 0; i < NUMBEROF(__defaults); i++) { defaults.Insert(__defaults[i].name, (uptr_t)new AString(__defaults[i].value)); } CreateDirectory(GetConfigDir()); CreateDirectory(GetDataDir()); CreateDirectory(GetLogDir()); CreateDirectory(GetRecordingsStorageDir()); CreateDirectory(GetRecordingsDir()); CreateDirectory(GetTempDir()); if (CommitScheduling()) { AList users; AString dir; ListUsers(users); const AString *user = AString::Cast(users.First()); while (user) { if (((dir = GetRecordingsDir(*user)).Valid()) && (dir.Pos("{") < 0)) CreateDirectory(dir); if (((dir = GetRecordingsArchiveDir(*user)).Valid()) && (dir.Pos("{") < 0)) CreateDirectory(dir); user = user->Next(); } } }
void ATextServer::__readcallback(ASocketServer *server, int socket, void *context) { ATextHandler *handler = (ATextHandler *)context; if (handler) { static uint8_t buffer[1024]; int n; if ((n = server->ReadSocket(socket, buffer, sizeof(buffer))) > 0) { AString data = AString((const char *)buffer, n).SearchAndReplace("\r", ""); handler->AddData(data); } else { debug("Failed to read data from socket\n"); server->DeleteHandler(socket); return; } handler->SendData(); } else { debug("Received data on an unregistered handler!\n"); server->DeleteHandler(socket); } }
TEST(StringTests, rshort) { LString short_text = "0123456789"_s; EXPECT_EQ(&*short_text.begin(), &*RString(short_text).begin()); EXPECT_EQ(&*short_text.begin(), &*AString(short_text).begin()); RString r = VString<255>(short_text); EXPECT_EQ(r.size(), 10); AString a = VString<255>(short_text); EXPECT_EQ(r, a); AString r2 = r, r3; RString a2 = a, a3; XString r1 = r2; XString a1 = a2; r3 = r1; a3 = a1; EXPECT_EQ(r, r1); EXPECT_EQ(a, a1); EXPECT_EQ(r, r2); EXPECT_EQ(a, a2); EXPECT_EQ(r, r3); EXPECT_EQ(a, a3); EXPECT_EQ(&*r.begin(), &*r1.begin()); EXPECT_NE(&*a.begin(), &*a1.begin()); EXPECT_EQ(&*r.begin(), &*r2.begin()); EXPECT_NE(&*a.begin(), &*a2.begin()); EXPECT_EQ(&*r.begin(), &*r3.begin()); EXPECT_NE(&*a.begin(), &*a3.begin()); }
static int fun_add(dumb_ptr<env_t>, val_t *result, Slice<val_t> args) { if (ARG_TYPE(0) == TYPE::INT && ARG_TYPE(1) == TYPE::INT) { /* Integer addition */ RESULTINT = ARGINT(0) + ARGINT(1); result->ty = TYPE::INT; } else if (ARG_MAY_BE_AREA(0) && ARG_MAY_BE_AREA(1)) { /* Area union */ make_area(&args[0]); make_area(&args[1]); RESULTAREA = area_union(ARGAREA(0), ARGAREA(1)); ARGAREA(0) = nullptr; ARGAREA(1) = nullptr; result->ty = TYPE::AREA; } else { /* Anything else -> string concatenation */ stringify(&args[0], 1); stringify(&args[1], 1); /* Yes, we could speed this up. */ // ugh MString m; m += ARGSTR(0); m += ARGSTR(1); RESULTSTR = dumb_string::copys(AString(m)); result->ty = TYPE::STRING; } return 0; }
void cHTTPFormParser::OnPartData(const char * a_Data, size_t a_Size) { if (m_CurrentPartName.empty()) { // Prologue, epilogue or invalid part return; } if (m_CurrentPartFileName.empty()) { // This is a variable, store it in the map iterator itr = find(m_CurrentPartName); if (itr == end()) { (*this)[m_CurrentPartName] = AString(a_Data, a_Size); } else { itr->second.append(a_Data, a_Size); } } else { // This is a file, pass it on through the callbacks if (!m_FileHasBeenAnnounced) { m_Callbacks.OnFileStart(*this, m_CurrentPartFileName); m_FileHasBeenAnnounced = true; } m_Callbacks.OnFileData(*this, a_Data, a_Size); } }
int main(int argc, char *argv[]) { ASocketServer server; AStdSocket socket(server); if (argc < 2) { fprintf(stderr, "cmdsender " VER_STRING "\n"); fprintf(stderr, "Usage: cmdsender <host> [<port>]\n"); exit(1); } if (socket.open("0.0.0.0", 0, ASocketServer::Type_Datagram)) { uint_t port = 1722; if (argc >= 3) port = (uint_t)AString(argv[2]); if (socket.setdatagramdestination(argv[1], port)) { AString line; while (line.ReadLn(Stdin) >= 0) { if (socket.printf("%s\n", line.str()) <= 0) break; } } socket.close(); } return 0; }
AString _DataProxy::operator[](const std::string& field) const { if (HasField(field)) { return const_access(const_access(data->values, category), field); } else { return AString(""); } }
long _cdecl vdf_fopen(const char* filename, long flags) { IfsBase* res = VdfsBase.OpenFile(filename, flags); if(res) return (int)res; VdfsBase.SetLastError(AString(filename) + " file not found"); return -1; }
bool AMySQLServer::convert(MYSQL_ROW row, int index, int& result) { const char *p = row[index]; result = 0; if (p) result = AString(p).toInt(); return true; }
AString ADVBConfig::GetRelativePath(const AString& filename) const { AString res; if (filename.StartsWith(GetRecordingsDir())) res = AString("/videos").CatPath(filename.Mid(GetRecordingsDir().len())); return res; }
AString cRSAPrivateKey::GetPubKeyDER(void) { class cPubKey { public: cPubKey(rsa_context * a_Rsa) : m_IsValid(false) { pk_init(&m_Key); if (pk_init_ctx(&m_Key, pk_info_from_type(POLARSSL_PK_RSA)) != 0) { ASSERT(!"Cannot init PrivKey context"); return; } if (rsa_copy(pk_rsa(m_Key), a_Rsa) != 0) { ASSERT(!"Cannot copy PrivKey to PK context"); return; } m_IsValid = true; } ~cPubKey() { if (m_IsValid) { pk_free(&m_Key); } } operator pk_context * (void) { return &m_Key; } protected: bool m_IsValid; pk_context m_Key; } PkCtx(&m_Rsa); unsigned char buf[3000]; int res = pk_write_pubkey_der(PkCtx, buf, sizeof(buf)); if (res < 0) { return AString(); } return AString((const char *)(buf + sizeof(buf) - res), (size_t)res); }
bool AMySQLServer::convert(MYSQL_ROW row, int index, u2& result) { const char *p = row[index]; result = 0x0; if (p) result = (u2)AString(row[index]).toU4(); return true; }
bool AMySQLServer::convert(MYSQL_ROW row, int index, AQueryString& result) { const char *p = row[index]; result.clear(); if (p) result.parse(AString(p)); return true; }
AString* StringHashTable::HashString( const AChar* str ){ if(str==NULL) return NULL; AString* p = NULL; m_CS.Enter(); p = Hash(AString(str)); m_CS.Leave(); return p; }
AString cPrefabPiecePool::GetMetadata(const AString & a_ParamName) const { auto itr = m_Metadata.find(a_ParamName); if (itr == m_Metadata.end()) { return AString(); } return itr->second; }
int main(int argc, char **argv) { AString strCommand(argv[1]); try { if (strCommand.equalsNoCase("install")) { if (installService()) std::cout << "Service installed." << std::endl; else std::cout << "Service install failed." << std::endl; } else if (strCommand.equalsNoCase("remove")) { if (removeService()) std::cout << "Service removed." << std::endl; else std::cout << "Service remove failed." << std::endl; } else { // When service dispatch action is requested this main() is called with no parameters // This connects the handler with service connectToServiceDispatch(); } } catch(AException& ex) { AFILE_TRACER_DEBUG_MESSAGE((AString("main: ")+ex.what()).c_str(), NULL); std::cerr << ex.what() << std::endl; } catch(std::exception& ex) { AFILE_TRACER_DEBUG_MESSAGE((AString("main: ")+ex.what()).c_str(), NULL); std::cerr << ex.what() << std::endl; } catch(...) { AFILE_TRACER_DEBUG_MESSAGE("main: Unknown exception", NULL); std::cerr << "Unknown exception" << std::endl; } return 1; }
// static status_t M3UParser::parseByteRange( const AString &line, uint64_t curOffset, uint64_t *length, uint64_t *offset) { ssize_t colonPos = line.find(":"); if (colonPos < 0) { return ERROR_MALFORMED; } ssize_t atPos = line.find("@", colonPos + 1); AString lenStr; if (atPos < 0) { lenStr = AString(line, colonPos + 1, line.size() - colonPos - 1); } else { lenStr = AString(line, colonPos + 1, atPos - colonPos - 1); } lenStr.trim(); const char *s = lenStr.c_str(); char *end; *length = strtoull(s, &end, 10); if (s == end || *end != '\0') { return ERROR_MALFORMED; } if (atPos >= 0) { AString offStr = AString(line, atPos + 1, line.size() - atPos - 1); offStr.trim(); const char *s = offStr.c_str(); *offset = strtoull(s, &end, 10); if (s == end || *end != '\0') { return ERROR_MALFORMED; } } else { *offset = curOffset; } return OK; }
sf::Vector2i make_vector2i(const std::string& str) { sf::Vector2i result; std::vector<int> vec = AString(str).as_int_vector(); if (vec.size() < 2) return sf::Vector2i(0,0); result.x = vec[0]; result.y = vec[1]; return result; }
sf::Vector2f make_vector2f(const std::string& str) { sf::Vector2f result; std::vector<float> vec = AString(str).as_float_vector(); if (vec.size() < 2) return sf::Vector2f(0,0); result.x = vec[0]; result.y = vec[1]; return result; }
sf::Vector2u make_vector2u(const std::string& str) { sf::Vector2u result; std::vector<int> vec = AString(str).as_int_vector(); if (vec.size() < 2) return sf::Vector2u(0,0); result.x = (unsigned int)vec[0]; result.y = (unsigned int)vec[1]; return result; }
int AString::CheckPrefix(const AString &s) { if (Len() < s.len) return 0; AString x = *this; x.str[s.len] = '\0'; x.len = s.len; return AString(x) == s; }
void Faction::SetName(AString* s) { if (s) { AString* newname = s->getlegal(); delete s; if (!newname) return; delete name; *newname += AString(" (") + num + ")"; name = newname; } }
AString BiomeToString(int a_Biome) { for (size_t i = 0; i < ARRAYCOUNT(g_BiomeMap); i++) { if (g_BiomeMap[i].m_Biome == a_Biome) { return g_BiomeMap[i].m_String; } } return AString(); }
/** This is the data of the root certs for Starfield Technologies, the CA that signed sessionserver.mojang.com's cert: Downloaded from http://certs.starfieldtech.com/repository/ */ static const AString StarfieldCACert() { return AString( // G2 cert "-----BEGIN CERTIFICATE-----\n" "MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMx\n" "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT\n" "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVs\n" "ZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAw\n" "MFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6\n" "b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQgVGVj\n" "aG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZp\n" "Y2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n" "ggEBAL3twQP89o/8ArFvW59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMg\n" "nLRJdzIpVv257IzdIvpy3Cdhl+72WoTsbhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1\n" "HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNkN3mSwOxGXn/hbVNMYq/N\n" "Hwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7NfZTD4p7dN\n" "dloedl40wO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j+6XGmBIWtDBFk385N78gDGIc/oav7PKaf\n" "8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN\n" "+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0\n" "X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa\n" "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA\n" "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G\n" "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR\n" "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0\n" "YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD\n" "bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w\n" "DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3\n" "L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D\n" "eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl\n" "xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp\n" "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY\n" "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=\n" "-----END CERTIFICATE-----\n" ); }
std::vector<AString> split(const std::string& str, const char& chr) { std::vector<AString> result; AString current = AString(""); for(unsigned int i = 0; i < str.size(); i++) { char c = str[i]; if (c == chr){ if (current.size() > 0) { result.push_back(current); current = AString(""); } } else current += c; } if (current.size() > 0) { result.push_back(current); current = AString(""); } return result; }
AString cPlayer::GetColor(void) const { if (m_MsgNameColorCode.empty() || (m_MsgNameColorCode == "-")) { // Color has not been assigned, return an empty string: return AString(); } // Return the color, including the delimiter: return cChatColor::Delimiter + m_MsgNameColorCode; }
/*--------------------------------------------------------------------------------*/ bool PostgresDatabase::PostgresQuery::Fetch(AString& results) { bool success = false; if (res && nfields && (row < nrows)) { uint_t i; results.Delete(); for (i = 0; i < nfields; i++) { if (i) results.printf(","); const char *p = PQgetvalue(res, row, i); switch (PQftype(res, i)) { case TIMESTAMPOID: { ADateTime dt; dt.FromTimeStamp(p, true); results += AString((uint64_t)dt); //debug("%s->%llu->%s (%s)\n", p, (uint64)dt, dt.DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), dt.UTCToLocal().DateFormat("%Y-%M-%D %h:%m:%s.%S").str()); break; } case TEXTOID: case CHAROID: case VARCHAROID: results.printf("'%s'", AString(p).Escapify().str()); break; default: results.printf("%s", p); break; } } //debug("Row %u/%u: %s\n", row, nrows, results.str()); row++; success = true; } return success; }