void UNodeSet::destroy(UNodeSet* nset) { U_TRACE(1, "UNodeSet::destroy(%p)", nset) U_INTERNAL_ASSERT_POINTER(nset) UNodeSet* tmp; while ((tmp = nset)) { if ( nset->next && (nset->next != nset)) { nset->next->prev = nset->prev; nset->prev->next = nset->next; nset = nset->next; } else { nset = U_NULLPTR; } if (tmp->nodes) U_SYSCALL_VOID(xmlXPathFreeNodeSet, "%p", tmp->nodes); if (tmp->children) destroy(tmp->children); if (tmp->doc && tmp->destroyDoc) U_SYSCALL_VOID(xmlFreeDoc, "%p", tmp->doc); } }
void UXML2Document::init() { U_TRACE_NO_PARAM(1, "UXML2Document::init()") binit = true; /* * build an XML tree from a file; we need to add default attributes * and resolve all character and entities references: required for c14n! */ xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS; U_SYSCALL_VOID(xmlSubstituteEntitiesDefault, "%d", 1); /* * Do not fetch DTD over network */ // xmlExternalEntityLoader defaultEntityLoader = xmlNoNetExternalEntityLoader; U_SYSCALL_VOID(xmlSetExternalEntityLoader, "%p", xmlNoNetExternalEntityLoader); xmlLoadExtDtdDefaultValue = 0; }
UTranformInputURI::UTranformInputURI(const char* uri) { U_TRACE_CTOR(0, UTranformInputURI, "%S", uri) clbks = U_NULLPTR; clbksCtx = U_NULLPTR; /* * Try to find one of the input accept method accepting that scheme * Go in reverse to give precedence to user defined handlers. * try with an unescaped version of the uri */ char* unescaped = U_SYSCALL(xmlURIUnescapeString, "%S,%d,%S", uri, 0, U_NULLPTR); if (unescaped != U_NULLPTR) { clbks = find(unescaped); if (clbks) clbksCtx = clbks->opencallback(unescaped); U_SYSCALL_VOID(xmlFree, "%p", unescaped); } // If this failed try with a non-escaped uri this may be a strange filename if (clbks == U_NULLPTR) { clbks = find(uri); if (clbks) clbksCtx = clbks->opencallback(uri); } }
UDBI::~UDBI() { U_TRACE_UNREGISTER_OBJECT(0, UDBI) close(); #if LIBDBI_LIB_CURRENT <= 1 U_SYSCALL_VOID_NO_PARAM(dbi_shutdown); #else U_SYSCALL_VOID(dbi_shutdown_r, "%p", pinst); #endif }
static VALUE URUBY_io_new(VALUE _class) { U_TRACE(0, "URUBY_io_new(%llu)", _class) VALUE self = Data_Wrap_Struct(_class, U_NULLPTR, U_NULLPTR, U_NULLPTR); U_INTERNAL_DUMP("self = %llu", self) U_SYSCALL_VOID(rb_obj_call_init, "%llu,%d,%p", self, 0, U_NULLPTR); U_RETURN(self); }
void run(int argc, char* argv[], char* env[]) { U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env) UApplication::run(argc, argv, env); U_SYSCALL_VOID_NO_PARAM(xmlInitParser); // init libxml LIBXML_TEST_VERSION // manage options num_args = (argc - optind); U_INTERNAL_DUMP("optind = %d num_args = %d", optind, num_args) if (UApplication::isOptions()) cfg_str = opt['c']; // manage file configuration if (cfg_str.empty()) cfg_str = U_STRING_FROM_CONSTANT("XAdES.ini"); // ---------------------------------------------------------------------------------------------------------------------------------- // XAdES - configuration parameters // ---------------------------------------------------------------------------------------------------------------------------------- // DigestAlgorithm md2 | md5 | sha | sha1 | sha224 | sha256 | sha384 | sha512 | mdc2 | ripmed160 // // SigningTime this property contains the time at which the signer claims to have performed the signing process (yes/no) // ClaimedRole this property contains claimed or certified roles assumed by the signer in creating the signature // // this property contains the indication of the purported place where the signer claims to have produced the signature // ------------------------------------------------------------------------------------------------------------------- // ProductionPlaceCity // ProductionPlaceStateOrProvince // ProductionPlacePostalCode // ProductionPlaceCountryName // ------------------------------------------------------------------------------------------------------------------- // // DataObjectFormatMimeType this property identifies the format of a signed data object (when electronic signatures // are not exchanged in a restricted context) to enable the presentation to the verifier or // use by the verifier (text, sound or video) in exactly the same way as intended by the signer // // CAStore // ArchiveTimeStamp the time-stamp token within this property covers the archive validation data // // SignatureTimeStamp the time-stamp token within this property covers the digital signature value element // Schema the pathname XML Schema of XAdES // ---------------------------------------------------------------------------------------------------------------------------------- (void) cfg.open(cfg_str); UString x(U_CAPACITY); UServices::readEOF(STDIN_FILENO, x); if (x.empty()) U_ERROR("cannot read data from <stdin>..."); (void) content.reserve(x.size()); if (UBase64::decode(x, content) == false) U_ERROR("decoding data read failed..."); // manage arguments... schema = ( U_SCHEMA == 0 || *U_SCHEMA == '\0' ? cfg[U_STRING_FROM_CONSTANT("XAdES-L.Schema")] : UString(U_SCHEMA)); if (schema.empty()) U_ERROR("error on XAdES schema: empty"); /* UString str_CApath = cfg[U_STRING_FROM_CONSTANT("XAdES-C.CAStore")], digest_algorithm = cfg[U_STRING_FROM_CONSTANT("XAdES-C.DigestAlgorithm")]; if (str_CApath.empty() || UServices::setupOpenSSLStore(0, str_CApath.c_str()) == false) { U_ERROR("error on setting CA Store: %S", str_CApath.data()); } */ UXML2Schema XAdES_schema(UFile::contentOf(schema)); // --------------------------------------------------------------------------------------------------------------- // check for OOffice or MS-Word document... // --------------------------------------------------------------------------------------------------------------- utility.handlerConfig(cfg); if (utility.checkDocument(content, "XAdES", false)) content = utility.getSigned(); // --------------------------------------------------------------------------------------------------------------- UApplication::exit_value = 1; UXML2Document document(content); if (XAdES_schema.validate(document) == false) { UString content1; if (document.getElement(content1, 0, U_CONSTANT_TO_PARAM(U_TAG_SIGNED_INFO)) && content1.empty() == false) { UXML2Document document1(content1); if (XAdES_schema.validate(document1) == false) { U_ERROR("fail to validate data input based on XAdES schema"); } } } UDSIGContext dsigCtx; UString data, signature; const char* digest_algorithm; if (dsigCtx.verify(document, digest_algorithm, data, signature)) { UString element = document.getElementData(128, U_CONSTANT_TO_PARAM(U_TAG_X509_CERTIFICATE)); if (element.empty() == false) { UString certificate(element.size()); if (UBase64::decode(element, certificate)) { alg = u_dgst_get_algoritm(digest_algorithm); if (alg == -1) U_ERROR("I can't find the digest algorithm for: %s", digest_algorithm); X509* x509 = UCertificate::readX509(certificate, "DER"); u_pkey = UCertificate::getSubjectPublicKey(x509); U_SYSCALL_VOID(X509_free, "%p", x509); if (UServices::verifySignature(alg, data, signature, UString::getStringNull(), 0)) { UApplication::exit_value = 0; # ifdef __MINGW32__ (void) setmode(1, O_BINARY); # endif // std::cout.write(U_STRING_TO_PARAM(certificate)); std::cout.write(U_STRING_TO_PARAM(content)); } U_SYSCALL_VOID(EVP_PKEY_free, "%p", u_pkey); u_pkey = 0; } } } utility.clean(); }
bool UGeoIPPlugIn::setCountryCode() { U_TRACE_NO_PARAM(1, "UGeoIPPlugIn::setCountryCode()") gir = 0; region = 0; domain_name = 0; netspeed = country_id = 0; bGEOIP_CITY_EDITION_REV1 = false; country_code = country_name = org = 0; ipnum = U_SYSCALL(_GeoIP_lookupaddress, "%s", UServer_Base::client_address); if (ipnum) { // iterate through different database types for (uint32_t i = 0; i < NUM_DB_TYPES; ++i) { if (gi[i]) { if (GEOIP_DOMAIN_EDITION == i) { domain_name = U_SYSCALL(GeoIP_name_by_ipnum, "%p,%lu", gi[i], ipnum); } else if (GEOIP_COUNTRY_EDITION == i) { country_id = U_SYSCALL(GeoIP_id_by_ipnum, "%p,%lu", gi[i], ipnum); if (country_id >= 0) { country_code = GeoIP_country_code[country_id]; country_name = GeoIP_country_name[country_id]; U_SRV_LOG_WITH_ADDR("%s: IP %.*S is from %s, %s for", GeoIPDBDescription[i], U_CLIENT_ADDRESS_TO_TRACE, country_code, country_name); } } else if (GEOIP_REGION_EDITION_REV0 == i || GEOIP_REGION_EDITION_REV1 == i) { region = (GeoIPRegion*) U_SYSCALL(GeoIP_region_by_ipnum, "%p,%lu", gi[i], ipnum); if (region) { U_SRV_LOG_WITH_ADDR("%s: IP %.*S is from %s, %s for", GeoIPDBDescription[i], U_CLIENT_ADDRESS_TO_TRACE, region->country_code, region->region); U_SYSCALL_VOID(GeoIPRegion_delete, "%p", region); } } else if (GEOIP_CITY_EDITION_REV0 == i || GEOIP_CITY_EDITION_REV1 == i) { gir = (GeoIPRecord*) U_SYSCALL(GeoIP_record_by_ipnum, "%p,%lu", gi[i], ipnum); bGEOIP_CITY_EDITION_REV1 = (GEOIP_CITY_EDITION_REV1 == i); } else if (GEOIP_ORG_EDITION == i || GEOIP_ISP_EDITION == i) { org = U_SYSCALL(GeoIP_org_by_ipnum, "%p,%lu", gi[i], ipnum); } else if (GEOIP_NETSPEED_EDITION == i) { netspeed = U_SYSCALL(GeoIP_id_by_ipnum, "%p,%lu", gi[i], ipnum); /* if (netspeed == GEOIP_UNKNOWN_SPEED) {} else if (netspeed == GEOIP_DIALUP_SPEED) {} else if (netspeed == GEOIP_CABLEDSL_SPEED) {} else if (netspeed == GEOIP_CORPORATE_SPEED) {} */ } } } } if (country_code) U_RETURN(true); U_RETURN(false); }
ULog::ULog(const UString& path, uint32_t _size, const char* dir_log_gz) : UFile(path) { U_TRACE_REGISTER_OBJECT(0, ULog, "%.*S,%u,%S", U_STRING_TO_TRACE(path), _size, dir_log_gz) log_gzip_sz = 0; U_Log_start_stop_msg(this) = false; if (UFile::getPath().equal(U_CONSTANT_TO_PARAM("syslog"))) { lock = 0; ptr_log_data = 0; # ifdef USE_LIBZ buf_path_compress = 0; # endif U_Log_syslog(this) = true; # ifndef __MINGW32__ U_SYSCALL_VOID(openlog, "%S,%d,%d", u_progname, LOG_PID, LOG_LOCAL0); # endif return; } if (UFile::creat(O_RDWR | O_APPEND, 0664) == false) { U_ERROR("cannot creat log file %.*S", U_FILE_TO_TRACE(*this)); return; } ptr_log_data = U_MALLOC_TYPE(log_data); ptr_log_data->file_ptr = 0; if (_size) { uint32_t file_size = UFile::size(); bool bsize = (file_size != _size); U_INTERNAL_DUMP("bsize = %b", bsize) if ((bsize && UFile::ftruncate(_size) == false) || UFile::memmap(PROT_READ | PROT_WRITE) == false) { U_ERROR("cannot init log file %.*S", U_FILE_TO_TRACE(*this)); return; } if (bsize) ptr_log_data->file_ptr = file_size; // append mode else { // NB: we can have a previous crash without resizing the file or we are an other process (apache like log)... char* ptr = (char*) u_find(UFile::map, file_size, U_CONSTANT_TO_PARAM(U_MARK_END)); U_INTERNAL_DUMP("ptr = %p", ptr) if (ptr) { ptr_log_data->file_ptr = ptr - UFile::map; // NB: we can be an other process that manage this file (apache like log)... (void) memcpy(ptr, U_CONSTANT_TO_PARAM(U_MARK_END)); UFile::msync(ptr + U_CONSTANT_SIZE(U_MARK_END), UFile::map, MS_SYNC); } U_INTERNAL_ASSERT_MINOR(ptr_log_data->file_ptr, UFile::st_size) } log_file_sz = UFile::st_size; } U_INTERNAL_DUMP("ptr_log_data->file_ptr = %u UFile::st_size = %u log_gzip_sz = %u", ptr_log_data->file_ptr, UFile::st_size, log_gzip_sz) U_INTERNAL_ASSERT(ptr_log_data->file_ptr <= UFile::st_size) lock = U_NEW(ULock); U_Log_syslog(this) = false; ptr_log_data->gzip_len = 0; ptr_log_data->file_page = ptr_log_data->file_ptr; #ifdef USE_LIBZ char suffix[32]; uint32_t len_suffix = u__snprintf(suffix, sizeof(suffix), ".%4D.gz"); buf_path_compress = U_NEW(UString(MAX_FILENAME_LEN)); char* ptr = buf_path_compress->data(); if (dir_log_gz == 0) { (void) UFile::setPathFromFile(*this, ptr, suffix, len_suffix); buf_path_compress->size_adjust(); index_path_compress = (buf_path_compress->size() - len_suffix + 1); } else { UString name = UFile::getName(); uint32_t len = u__strlen(dir_log_gz, __PRETTY_FUNCTION__), sz = name.size(); U_MEMCPY(ptr, dir_log_gz, len); ptr += len; *ptr++ = '/'; buf_path_compress->size_adjust(len + 1 + sz + len_suffix); U_MEMCPY(ptr, name.data(), sz); ptr += sz; U_MEMCPY(ptr, suffix, len_suffix); index_path_compress = buf_path_compress->distance(ptr) + 1; buf_path_compress->UString::setNullTerminated(); } U_INTERNAL_DUMP("buf_path_compress(%u) = %.*S index_path_compress = %u", buf_path_compress->size(), U_STRING_TO_TRACE(*buf_path_compress), index_path_compress) #endif }
bool ULog::open(uint32_t _size, mode_t mode) { U_TRACE(0, "ULog::open(%u,%d)", _size, mode) // NB: we need to check because all instance try to close the log... (inherits from its parent) u_atexit(&ULog::close); // register function of close at exit()... if (UFile::getPath() == U_STRING_FROM_CONSTANT("syslog")) { prefix = 0; pthis = this; bsyslog = true; # ifndef __MINGW32__ U_SYSCALL_VOID(openlog, "%S,%d,%d", u_progname, LOG_PID, LOG_LOCAL0); # endif U_RETURN(true); } if (UFile::creat(O_CREAT | O_RDWR | O_APPEND, mode)) { uint32_t file_size = 0; if (_size) { file_size = UFile::size(); if (UFile::ftruncate(_size) == false || UFile::memmap(PROT_READ | PROT_WRITE) == false) { goto end; } } pthis = this; ptr_log_data = U_MALLOC_TYPE(log_data); LOG_ptr = LOG_page = (_size ? (UFile::map + file_size) : 0); // append mode... file_limit = (_size ? (UFile::map + UFile::st_size) : 0); U_INTERNAL_ASSERT_EQUALS(lock,0) lock = U_NEW(ULock); U_INTERNAL_ASSERT_POINTER(lock) # ifdef USE_LIBZ backup_log_function = &ULog::backup; dir_log_gz = (const char*) U_SYSCALL(getenv, "%S", "DIR_LOG_GZ"); UInterrupt::setHandlerForSignal(SIGUSR1, (sighandler_t)ULog::handlerSIGUSR1); # endif if (fmt) startup(); U_RETURN(true); } end: U_ERROR("cannot init log file %.*S...", U_FILE_TO_TRACE(*this)); U_RETURN(false); }