/* Adds all locales from the program's external libraries. */ static sdef(int, onLibrary, struct dl_phdr_info *info, __unused size_t size, void *data) { DynInstName(self) $this = (DynInstName(self)) (self *) data; RdString path = String_FromNul((char *) info->dlpi_name); path.len != 0 || ret(0); RdString ext = Path_getFileExtension(path); RdString fileName = Path_getFileName(path); Logger_Debug(&this->logger, $("Found external library %."), fileName); if (!String_Equals(ext, $("dll"))) { Logger_Debug(&this->logger, $("Incompatible library extension.")); return 0; } String realPath; if (Path_isLink(path)) { realPath = Path_followLink(path); } else { realPath = String_Clone(path); } RdString folderPath = Path_getFolderPath(realPath.rd); RdString context = String_Slice(fileName, 0, -4); String lngpath = String_Format($("%Locale/"), folderPath); if (!Path_exists(lngpath.rd)) { Logger_Debug(&this->logger, $("External library % has no locales."), context); String_Destroy(&lngpath); } else { if (Locale_hasContext(Locale_GetInstance(), context)) { Logger_Error(&this->logger, $( "The locale context % was already registered. Possibly " "the program maintains a local copy of its external locales."), context); } else { Logger_Debug(&this->logger, $("Adding locale directory % (for external library %)."), lngpath.rd, context); Locale_addContext(Locale_GetInstance(), context, lngpath); } } String_Destroy(&realPath); return 0; }
static def(void, ParseSubscriptions, YAML_Node *node) { for (size_t i = 0; i < node->len; i++) { YAML_Node *child = node->buf[i]; ProviderFacadeInstance provider = ProviderFacade_Null(); if (child->type == YAML_NodeType_Item) { Logger_Debug(this->logger, $("Adding provider '%' (%)..."), YAML_Item(child)->value, YAML_Item(child)->key); provider = call(NewProvider, YAML_Item(child)->key); if (!ProviderFacade_IsNull(provider)) { ProviderFacade_SetName(provider, YAML_Item(child)->value); } } else if (child->type == YAML_NodeType_Section) { Logger_Debug(this->logger, $("Adding provider '%'..."), YAML_Section(child)->name); provider = call(NewProvider, YAML_Section(child)->name); } if (!ProviderFacade_IsNull(provider) && child->len > 0) { for (size_t j = 0; j < child->buf[0]->len; j++) { YAML_Node *_child = child->buf[0]->buf[j]; if (_child->type == YAML_NodeType_Item) { String key = YAML_Item(_child)->key; String value = YAML_Item(_child)->value; if (String_Equals(key, $("limit"))) { ProviderFacade_SetLimit(provider, Int32_Parse(value)); } else { bool handled = ProviderFacade_SetOption( provider, key, value); if (!handled) { ProviderFacade_AddSource(provider, YAML_Item(_child)->value); } } } } } } }
def(void, Get, String prefix, ListingItem *item, String url) { this->location.len = 0; HTTP_Client client; URL_Parts parts = URL_Parse(url); HTTP_Client_Init(&client, parts.host); HTTP_Client_Events events; events.onVersion = (HTTP_OnVersion) EmptyCallback(); events.onHeader = (HTTP_OnHeader) Callback(this, ref(OnHeader)); HTTP_Client_SetEvents(&client, events); HTTP_Client_Request(&client, HTTP_Client_CreateRequest( parts.host, parts.path)); Logger_Debug(this->logger, $("URL: %"), url); URL_Parts_Destroy(&parts); HTTP_Client_FetchResponse(&client); size_t cnt = 0; bool error = false; if (this->location.len > 0) { if (cnt > 3) { Logger_Error(this->logger, $("Redirection loop.")); goto out; } cnt++; Logger_Debug(this->logger, $("Redirecting...")); call(Get, prefix, item, this->location); goto out; } String full = call(BuildPath, prefix, item, scall(GetMediaExtension, parts.path)); Logger_Debug(this->logger, $("Destination: %"), full); File file; File_Open(&file, full, FileStatus_Create | FileStatus_Truncate | FileStatus_WriteOnly); String_Destroy(&full); BufferedStream output; BufferedStream_Init(&output, File_AsStream(&file)); BufferedStream_SetOutputBuffer(&output, 128 * 1024); u64 got = 0; s64 total = HTTP_Client_GetLength(&client); size_t prevPercent = 100; String buf = String_New(HTTP_Client_ReadChunkSize); Terminal_ProgressBar pbar; Terminal_ProgressBar_Init(&pbar, &term); while (HTTP_Client_Read(&client, &buf)) { got += buf.len; try { BufferedStream_Write(&output, buf.buf, buf.len); } clean catch(File, WritingFailed) { error = true; excBreak; } finally { } tryEnd; size_t percent = (size_t) ((float) got / (float) total * 100); if (prevPercent != percent) { float gotmb = (float) got / 1024 / 1024; float totalmb = (float) total / 1024 / 1024; String strGot = Float_ToString(gotmb, 0.01, '.'); String strTotal = Float_ToString(totalmb, 0.01, '.'); String msg = String_Format($("Received % MiB of % MiB"), strGot, strTotal); String_Destroy(&strTotal); String_Destroy(&strGot); Terminal_ProgressBar_Render(&pbar, percent, msg); String_Destroy(&msg); } prevPercent = percent; } Terminal_ProgressBar_Clear(&pbar); String_Destroy(&buf); if (error) { /* Don't flush when closing the file. */ BufferedStream_Reset(&output); } BufferedStream_Close(&output); BufferedStream_Destroy(&output); out: HTTP_Client_Destroy(&client); if (error) { throw(DownloadFailed); } }
void func() { logger_c_t logger = GetLoggerInstance("dblog"); Logger_Debug(logger,"one dblog.ip=%s port=%u","127.0.0.1",3306); }