static void usp_init() { U_TRACE(5, "::usp_init()") U_INTERNAL_ASSERT_EQUALS(ir,0) U_INTERNAL_ASSERT_EQUALS(query,0) U_INTERNAL_ASSERT_EQUALS(crono,0) U_INTERNAL_ASSERT_EQUALS(footer,0) ir = U_NEW(IR); query = U_NEW(Query); crono = U_NEW(UCrono); footer = U_NEW(UString(200U)); UString cfg_index; if ((ir->loadFileConfig(cfg_index) && ir->openCDB(false)) == false) { U_ERROR("usp_init() of servlet 'ir_web' failed..."); } footer->snprintf("ver. %s, with %u documents and %u words.", ULIB_VERSION, cdb_names->size(), cdb_words->size()); UHTTP::data_session = U_NEW(IRDataSession); }
void URPCObject::loadGenericMethod(UFileConfig* file_method) { U_TRACE(0, "URPCObject::loadGenericMethod(%p)", file_method) U_INTERNAL_ASSERT_EQUALS(dispatcher, 0) U_INTERNAL_ASSERT_EQUALS(URPCMethod::encoder, 0) dispatcher = U_NEW(URPCObject); URPCMethod::encoder = U_NEW(URPCEncoder); if (file_method) readGenericMethod(*file_method); }
bool UMagic::init(int flags) { U_TRACE(1, "UMagic::init(%d)", flags) U_INTERNAL_ASSERT_EQUALS(magic, U_NULLPTR) magic = (magic_t) U_SYSCALL(magic_open, "%d", flags); bool ok = (magic && U_SYSCALL(magic_load, "%p,%S", magic, U_NULLPTR) != -1); U_DUMP("ok = %b status = %.*S", ok, 512, getError()) U_RETURN(ok); }
void UDirWalk::setSuffixFileType(const char* format, ...) { U_TRACE(0, "UDirWalk::setSuffixFileType(%S)", format) U_INTERNAL_ASSERT_EQUALS(suffix_file_type, 0) suffix_file_type = U_NEW(UString(100U)); va_list argp; va_start(argp, format); suffix_file_type->vsnprintf(format, argp); va_end(argp); }
ULDAPEntry::ULDAPEntry(int num_names, const char** names, int num_entry) { U_TRACE_REGISTER_OBJECT(0, ULDAPEntry, "%d,%p,%d", num_names, names, num_entry) U_INTERNAL_ASSERT_EQUALS(names[num_names], 0) U_DUMP_ATTRS(names) n_attr = num_names; n_entry = num_entry; attr_name = names; dn = (char**) UMemoryPool::_malloc(num_entry, sizeof(char*), true); attr_val = (UString**) UMemoryPool::_malloc(num_entry * num_names, sizeof(UString*), true); }
bool UDynamic::load(const char* pathname) { U_TRACE(0, "UDynamic::load(%S)", pathname) U_CHECK_MEMORY U_INTERNAL_ASSERT_EQUALS(handle, 0) #ifdef _MSWINDOWS_ handle = ::LoadLibrary(pathname); #else /** * -------------------------------------------------------------------- * Perform lazy binding * -------------------------------------------------------------------- * Only resolve symbols as the code that references them is executed. * If the symbol is never referenced, then it is never resolved. * Lazy binding is only performed for function references; references * to variables are always immediately bound when the library is loaded * -------------------------------------------------------------------- */ handle = U_SYSCALL(dlopen, "%S,%d", pathname, RTLD_LAZY); // RTLD_NOW #endif if (handle == 0) { # if defined(_MSWINDOWS_) err = "load failed"; # else err = ::dlerror(); # endif U_WARNING("UDynamic::load(%S) failed: %.*S", pathname, 256, err); U_RETURN(false); } #ifndef _MSWINDOWS_ (void) ::dlerror(); /* Clear any existing error */ #endif U_RETURN(true); }
UPosting::UPosting(uint32_t dimension, bool parsing, bool index) { U_TRACE_REGISTER_OBJECT(5, UPosting, "%u,%b,%b", dimension, parsing, index) U_INTERNAL_ASSERT_EQUALS(word,0) U_INTERNAL_ASSERT_EQUALS(posting,0) U_INTERNAL_ASSERT_EQUALS(filename,0) U_INTERNAL_ASSERT_EQUALS(str_cur_doc_id,0) word = U_NEW(UString); posting = U_NEW(UString); filename = U_NEW(UString); str_cur_doc_id = U_NEW(UString(sizeof(cur_doc_id))); approximate_num_words = 2000 + (dimension * 8); if (index) { U_INTERNAL_ASSERT_EQUALS(tbl_name, 0) U_INTERNAL_ASSERT_EQUALS(tbl_words, 0) dimension += dimension / 4; tbl_name = U_NEW(UHashMap<UString>(U_GET_NEXT_PRIME_NUMBER(dimension))); tbl_words = U_NEW(UHashMap<UString>(U_GET_NEXT_PRIME_NUMBER(approximate_num_words), ignore_case)); } if (parsing) { U_INTERNAL_ASSERT_EQUALS(file,0) U_INTERNAL_ASSERT_EQUALS(content,0) file = U_NEW(UFile); content = U_NEW(UString); } }
void UThread::close() { U_TRACE_NO_PARAM(0, "UThread::close()") #ifdef _MSWINDOWS_ DWORD _tid = tid; #else pthread_t _tid = tid; #endif tid = 0; U_INTERNAL_DUMP("tid = %p first = %p next = %p", _tid, first, next) U_INTERNAL_ASSERT_POINTER(first) UThread* obj; UThread** ptr = &first; while ((obj = *ptr)) { U_INTERNAL_ASSERT_POINTER(obj) # ifdef _MSWINDOWS_ if (tid == obj->tid) # else if (pthread_equal(tid, obj->tid)) # endif { U_INTERNAL_ASSERT_EQUALS(this, obj) U_INTERNAL_ASSERT_EQUALS(next, obj->next) *ptr = next; next = 0; break; } ptr = &(*ptr)->next; } if (_tid) { # ifdef _MSWINDOWS_ // wait for real w32 thread to cleanup switch (cancel) { case cancelImmediate: TerminateThread((HANDLE)_tid, 0); break; default: SetEvent(cancellation); } (void) WaitForSingleObject((HANDLE)_tid, INFINITE); (void) U_SYSCALL(CloseHandle, "%p", cancellation); (void) U_SYSCALL(CloseHandle, "%p", (HANDLE)_tid); _endthreadex(0); # else # ifdef HAVE_PTHREAD_CANCEL (void) U_SYSCALL(pthread_cancel, "%p", _tid); # endif if (detachstate == PTHREAD_CREATE_JOINABLE) (void) U_SYSCALL(pthread_join, "%p,%p", _tid, 0); # ifdef HAVE_PTHREAD_YIELD else { (void) U_SYSCALL_NO_PARAM(pthread_yield); } # endif # endif } }
int URDBClientImage::handlerRead() { U_TRACE(0, "URDBClientImage::handlerRead()") u_clientimage_flag.u = 0; if (UClientImage_Base::genericRead() == false) { if (U_ClientImage_state == U_PLUGIN_HANDLER_AGAIN) U_RETURN(U_NOTIFIER_OK); // NOT BLOCKING... U_INTERNAL_ASSERT_EQUALS(U_ClientImage_state, U_PLUGIN_HANDLER_ERROR) U_RETURN(U_NOTIFIER_DELETE); } #ifdef U_LOG_ENABLE if (UClientImage_Base::logbuf) { *UClientImage_Base::request = *UClientImage_Base::rbuffer; UClientImage_Base::logRequest(); } #endif // check for RPC request URPC::resetInfo(); if (URPC::readRequest(UClientImage_Base::socket) == false) U_RETURN(U_NOTIFIER_DELETE); UClientImage_Base::wbuffer->setBuffer(U_CAPACITY); // Process the RPC message int result; const char* res = STR_200; const char* ptr = UClientImage_Base::rbuffer->data(); enum { RPC_METHOD_FIND = U_MULTICHAR_CONSTANT32('F','I','N','D'), RPC_METHOD_STORE = U_MULTICHAR_CONSTANT32('S','T','R','0'), RPC_METHOD_REPLACE = U_MULTICHAR_CONSTANT32('S','T','R','1'), RPC_METHOD_REMOVE = U_MULTICHAR_CONSTANT32('R','E','M','V'), RPC_METHOD_SUBSTITUTE0 = U_MULTICHAR_CONSTANT32('S','U','B','0'), RPC_METHOD_SUBSTITUTE1 = U_MULTICHAR_CONSTANT32('S','U','B','1'), RPC_METHOD_PRINT0 = U_MULTICHAR_CONSTANT32('P','R','T','0'), RPC_METHOD_PRINT1 = U_MULTICHAR_CONSTANT32('P','R','T','1'), RPC_METHOD_REORGANIZE = U_MULTICHAR_CONSTANT32('R','O','R','G'), RPC_METHOD_BEGIN_TRANSACTION = U_MULTICHAR_CONSTANT32('B','T','R','N'), RPC_METHOD_ABORT_TRANSACTION = U_MULTICHAR_CONSTANT32('A','T','R','N'), RPC_METHOD_COMMIT_TRANSACTION = U_MULTICHAR_CONSTANT32('C','T','R','N') }; switch (*(int32_t*)ptr) { case RPC_METHOD_FIND: { if (rdb->find((*URPC::rpc_info)[0])) { // Build the response: 200 uint32_t size = rdb->data.dsize; (void) UClientImage_Base::wbuffer->reserve(U_TOKEN_LN + size); UStringExt::buildTokenInt(res = STR_200, size, *UClientImage_Base::wbuffer); (void) UClientImage_Base::wbuffer->append((const char*)rdb->data.dptr, size); } else { // Build the response: 400 UStringExt::buildTokenInt(res = STR_400, 0, *UClientImage_Base::wbuffer); } } break; case RPC_METHOD_STORE: case RPC_METHOD_REPLACE: { // ------------------------------------------------------ // Write a key/value pair to a reliable database // ------------------------------------------------------ // RETURN VALUE // ------------------------------------------------------ // 0: Everything was OK // -1: flag was RDB_INSERT and this key already existed // -3: disk full writing to the journal file // ------------------------------------------------------ // #define RDB_INSERT 0 // Insertion of new entries only // #define RDB_REPLACE 1 // Allow replacing existing entries // ------------------------------------------------------ result = rdb->store((*URPC::rpc_info)[0], (*URPC::rpc_info)[1], ptr[3] == '0' ? RDB_INSERT : RDB_REPLACE); switch (result) { case 0: res = STR_200; break; // 0: Everything was OK case -1: res = STR_401; break; // -1: flag was RDB_INSERT and this key already existed case -3: res = STR_500; break; // -3: disk full writing to the journal file } UStringExt::buildTokenInt(res, 0, *UClientImage_Base::wbuffer); } break; case RPC_METHOD_REMOVE: { // --------------------------------------------------------- // Mark a key/value as deleted // --------------------------------------------------------- // RETURN VALUE // --------------------------------------------------------- // 0: Everything was OK // -1: The entry was not in the database // -2: The entry was already marked deleted in the hash-tree // -3: disk full writing to the journal file // --------------------------------------------------------- result = rdb->remove((*URPC::rpc_info)[0]); switch (result) { case 0: res = STR_200; break; // 0: Everything was OK case -1: res = STR_400; break; // -1: The entry was not in the database case -2: res = STR_402; break; // -2: The entry was already marked deleted in the hash-tree case -3: res = STR_500; break; // -3: disk full writing to the journal file } UStringExt::buildTokenInt(res, 0, *UClientImage_Base::wbuffer); } break; case RPC_METHOD_SUBSTITUTE0: case RPC_METHOD_SUBSTITUTE1: { // ---------------------------------------------------------- // Substitute a key/value with a new key/value (remove+store) // ---------------------------------------------------------- // RETURN VALUE // ---------------------------------------------------------- // 0: Everything was OK // -1: The entry was not in the database // -2: The entry was marked deleted in the hash-tree // -3: disk full writing to the journal file // -4: flag was RDB_INSERT and the new key already existed // ---------------------------------------------------------- // #define RDB_INSERT 0 // Insertion of new entries only // #define RDB_REPLACE 1 // Allow replacing existing entries result = rdb->substitute((*URPC::rpc_info)[0], (*URPC::rpc_info)[1], (*URPC::rpc_info)[2], ptr[3] == '0' ? RDB_INSERT : RDB_REPLACE); switch (result) { case 0: res = STR_200; break; // 0: Everything was OK case -1: res = STR_400; break; // -1: The entry was not in the database case -2: res = STR_402; break; // -2: The entry was marked deleted in the hash-tree case -3: res = STR_500; break; // -3: disk full writing to the journal file case -4: res = STR_401; break; // -4: flag was RDB_INSERT and the new key already existed } UStringExt::buildTokenInt(res, 0, *UClientImage_Base::wbuffer); } break; case RPC_METHOD_PRINT0: case RPC_METHOD_PRINT1: { // Build the response: 200 UString tmp = (ptr[3] == '0' ? rdb->print() : rdb->printSorted()); UStringExt::buildTokenInt(res = STR_200, tmp.size(), *UClientImage_Base::wbuffer); UClientImage_Base::wbuffer->append(tmp); } break; case RPC_METHOD_REORGANIZE: { res = (rdb->reorganize() ? STR_200 : STR_500); UStringExt::buildTokenInt(res, 0, *UClientImage_Base::wbuffer); } break; case RPC_METHOD_BEGIN_TRANSACTION: { res = (rdb->beginTransaction() ? STR_200 : STR_500); UStringExt::buildTokenInt(res, 0, *UClientImage_Base::wbuffer); } break; case RPC_METHOD_ABORT_TRANSACTION: { rdb->abortTransaction(); UStringExt::buildTokenInt(res = STR_200, 0, *UClientImage_Base::wbuffer); } break; case RPC_METHOD_COMMIT_TRANSACTION: { rdb->commitTransaction(); UStringExt::buildTokenInt(res = STR_200, 0, *UClientImage_Base::wbuffer); } break; default: { UStringExt::buildTokenInt(res = STR_500, 0, *UClientImage_Base::wbuffer); } break; } U_SRV_LOG_WITH_ADDR("method %.4S return %s for", ptr, res); return UClientImage_Base::handlerResponse(); }
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); }