Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
USSIPlugIn::USSIPlugIn()
{
   U_TRACE_REGISTER_OBJECT(0, USSIPlugIn, "")

   U_NEW(UString, errmsg,  UString);
   U_NEW(UString, timefmt, UString);
   U_NEW(UString, docname, UString);

   UString::str_allocate(STR_ALLOCATE_SSI);
}
Exemplo n.º 3
0
int UProxyPlugIn::handlerConfig(UFileConfig& cfg)
{
   U_TRACE(0, "UProxyPlugIn::handlerConfig(%p)", &cfg)

   vservice   = U_NEW(UVector<UModProxyService*>);
   vmsg_error = U_NEW(UVector<UString>);

   UModProxyService::loadConfig(cfg, *vservice, vmsg_error);

   U_RETURN(U_PLUGIN_HANDLER_GO_ON);
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
UHttpClient_Base::UHttpClient_Base(UFileConfig* _cfg) : UClient_Base(_cfg)
{
   U_TRACE_REGISTER_OBJECT(0, UHttpClient_Base, "%p", _cfg)

   method_num       = 0;
   bFollowRedirects = true;
   bproxy           = false;

   u_init_http_method_list();

   U_NEW(UMimeHeader,  requestHeader, UMimeHeader);
   U_NEW(UMimeHeader, responseHeader, UMimeHeader);
}
Exemplo n.º 6
0
static void usp_init_fortunes()
{
    U_TRACE(5, "::usp_init_fortunes()")

    psql_fortune  = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("fortune")));
    pstmt_fortune = U_NEW(UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune")));

    if (pstmt_fortune == 0) U_ERROR("usp_init_fortunes(): we cound't connect to db, exiting...");

    pfortune  = U_NEW(Fortune);
    pvfortune = U_NEW(UVector<Fortune*>);
    pmessage  = U_NEW(U_STRING_FROM_CONSTANT("Additional fortune added at request time."));

    pstmt_fortune->into(*pfortune);
}
Exemplo n.º 7
0
URDBServer::URDBServer(UFileConfig* cfg, bool ignore_case) : UServer<UTCPSocket>(cfg)
{
   U_TRACE_REGISTER_OBJECT(0, URDBServer, "%p,%b", cfg, ignore_case)

   rdb = U_NEW(URDB(ignore_case));

   URPC::allocate();
}
Exemplo n.º 8
0
 static void usp_init_queries()
 {
    U_TRACE(5, "::usp_init_queries()")
 
    psql_queries  = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));
    pstmt_queries = U_NEW(UOrmStatement(*psql_queries, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
 
    if (pstmt_queries == 0) U_ERROR("usp_init_queries(): we cound't connect to db, exiting...");
 
    pworld_queries  = U_NEW(World);
    pvworld_queries = U_NEW(UVector<World*>(500));
 
    pstmt_queries->use( pworld_queries->id);
    pstmt_queries->into(pworld_queries->randomNumber);
 
 #ifndef AS_cpoll_cppsp_DO
    pvalue = U_NEW(UValue(ARRAY_VALUE));
 #endif
 }
Exemplo n.º 9
0
UThread::UThread(bool suspendEnable, bool joinEnable)
{
   U_TRACE_REGISTER_OBJECT(0, UThread, "%b,%b", suspendEnable, joinEnable)

   priv  = U_NEW(UThreadImpl(suspendEnable, joinEnable));
   next  = first;
   first = this;

   U_INTERNAL_DUMP("first = %p next = %p", first, next)
}
Exemplo n.º 10
0
UMimeEntity::UMimeEntity(const UString& _data) : data(_data)
{
   U_TRACE_REGISTER_OBJECT(0, UMimeEntity, "%.*S", U_STRING_TO_TRACE(_data))

   header       = U_NEW(UMimeHeader);
   startHeader  = 0;
   parse_result = false;

   if (parse()) decodeBody();
}
Exemplo n.º 11
0
UMimeEntity::UMimeEntity(const char* ptr, uint32_t len) : data(ptr, len)
{
   U_TRACE_REGISTER_OBJECT(0, UMimeEntity, "%.*S,%u", len, ptr, len)

   header       = U_NEW(UMimeHeader);
   startHeader  = 0;
   parse_result = false;

   if (parse(ptr, len)) decodeBody();
}
Exemplo n.º 12
0
void ULock::init(sem_t* ptr)
{
   U_TRACE(0, "ULock::init(%p)", ptr)

   U_CHECK_MEMORY

   sem = U_NEW(USemaphore);

   sem->init(ptr);
}
Exemplo n.º 13
0
UStringRep* UObjectIO::create()
{
   U_TRACE(0, "UObjectIO::create()")

   UObjectIO::output();

   UStringRep* rep = U_NEW(UStringRep(buffer_output, buffer_output_len));

   U_INTERNAL_PRINT("rep = %.*S", U_STRING_TO_TRACE(*rep))

   U_RETURN_POINTER(rep, UStringRep);
}
Exemplo n.º 14
0
UPing::UPing(int _timeoutMS, bool bSocketIsIPv6) : USocket(bSocketIsIPv6)
{
   U_TRACE_REGISTER_OBJECT(0, UPing, "%d,%b", _timeoutMS, bSocketIsIPv6)

   timeoutMS = _timeoutMS;

   if (proc     == 0) proc = U_NEW(UProcess);
   if (addrmask == 0)
      {
      bmmap    = true;
      addrmask = (fd_set*) UFile::mmap(sizeof(fd_set) + sizeof(uint32_t));
      }
}
Exemplo n.º 15
0
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);
}
Exemplo n.º 16
0
UEventTime::UEventTime(long sec, long usec) : UTimeVal(sec, usec)
{
   U_TRACE_REGISTER_OBJECT(0, UEventTime, "%ld,%ld", sec, usec)

   reset();

#ifdef USE_LIBEVENT
   if (u_ev_base == 0) u_ev_base = (struct event_base*) U_SYSCALL_NO_PARAM(event_init);

   U_INTERNAL_ASSERT_POINTER(u_ev_base)

   pevent = U_NEW(UTimerEv<UEventTime>(*this));

   (void) UDispatcher::add(*pevent, *(UTimeVal*)this);
#endif
}
Exemplo n.º 17
0
UEventTime::UEventTime(long sec, long micro_sec) : UTimeVal(sec, micro_sec)
{
   U_TRACE_REGISTER_OBJECT(0, UEventTime, "%ld,%ld", sec, micro_sec)

   setTolerance();

   xtime.tv_sec =
   xtime.tv_usec = 0L;

#ifdef USE_LIBEVENT
   if (u_ev_base == 0) u_ev_base = (struct event_base*) U_SYSCALL_NO_PARAM(event_base_new);

   U_INTERNAL_ASSERT_POINTER(u_ev_base)

   U_NEW(UTimerEv<UEventTime>, pevent, UTimerEv<UEventTime>(*this));

   (void) UDispatcher::add(*pevent, *(UTimeVal*)this);
#endif
}
Exemplo n.º 18
0
UPing::UPing(int _timeoutMS, bool bSocketIsIPv6) : USocket(bSocketIsIPv6)
{
   U_TRACE_REGISTER_OBJECT(0, UPing, "%d,%b", _timeoutMS, bSocketIsIPv6)

   rep       = 0;
   timeoutMS = _timeoutMS;

   (void) memset(&req, 0, sizeof(reqhdr));
#ifdef HAVE_NETPACKET_PACKET_H
   (void) memset(&arp, 0, sizeof(arpmsg));
#endif

   if (proc     == 0) proc = U_NEW(UProcess);
   if (addrmask == 0)
      {
      map_size = sizeof(fd_set) + sizeof(uint32_t);
      addrmask = (fd_set*) UFile::mmap(&map_size);
      }
}
Exemplo n.º 19
0
bool UTranformXPointer::setExpr(const char* expr, int nodeSetType, xmlNodePtr node)
{
   U_TRACE(0, "UTranformXPointer::setExpr(%S,%d,%p)", expr, nodeSetType, node)

   UBaseTransform::hereNode = node;

   UXPathData* data;

   U_NEW(UXPathData, data, UXPathData(UXPathData::XPOINTER, nodeSetType, expr));

   if (data->registerNamespaces(node))
      {
      dataList.push(data);

      U_RETURN(true);
      }

   U_DELETE(data)

   U_RETURN(false);
}
Exemplo n.º 20
0
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);
      }
}
Exemplo n.º 21
0
UProxyPlugIn::UProxyPlugIn()
{
   U_TRACE_REGISTER_OBJECT_WITHOUT_CHECK_MEMORY(0, UProxyPlugIn, "")

   client_http = U_NEW(UHttpClient<UTCPSocket>((UFileConfig*)0));
}
Exemplo n.º 22
0
void USOAPParser::startElement(const XML_Char* name, const XML_Char** attrs)
{
   U_TRACE(0, "USOAPParser::startElement(%S,%p)", name, attrs)

   U_DUMP_ATTRS(attrs)

   UXMLAttribute* attribute;
   UString str((void*)name), namespaceName, accessorName, value;

   UXMLElement::splitNamespaceAndName(str, namespaceName, accessorName);

   if (flag_state == 0)
      {
      U_INTERNAL_ASSERT(u_rmatch(U_STRING_TO_PARAM(str), U_CONSTANT_TO_PARAM(":Envelope")))

      flag_state = 1;
      }

   U_DUMP("flag_state = %d ptree = %p ptree->parent() = %p ptree->numChild() = %u ptree->depth() = %u",
           flag_state, ptree, ptree->parent(), ptree->numChild(), ptree->depth())

   current = U_NEW(UXMLElement(str, accessorName, namespaceName));
   ptree   = ptree->push(current);

   if (flag_state <= 2)
      {
      if (flag_state == 1 &&
          u_rmatch(U_STRING_TO_PARAM(str), U_CONSTANT_TO_PARAM(":Header")))
         {
         header     = ptree;
         flag_state = 2;
         }
      else if (u_rmatch(U_STRING_TO_PARAM(str), U_CONSTANT_TO_PARAM(":Body")))
         {
         body       = ptree;
         flag_state = 3;
         }
      }

   U_INTERNAL_DUMP("flag_state = %d", flag_state)

   while (*attrs)
      {
        str.replace(*attrs++);
      value.replace(*attrs++);

      UXMLElement::splitNamespaceAndName(str, namespaceName, accessorName);

      attribute = U_NEW(UXMLAttribute(str, accessorName, namespaceName, value));

      current->addAttribute(attribute);

      // check if anybody has mustUnderstand set to true

      if (flag_state == 2 &&
          accessorName.equal(U_CONSTANT_TO_PARAM("mustUnderstand")))
         {
         envelope.mustUnderstand = value.equal(U_CONSTANT_TO_PARAM("true"));

         U_INTERNAL_DUMP("envelope.mustUnderstand = %b", envelope.mustUnderstand)
         }

      // set the name of namespace qualified element information (gSOAP)

      if (flag_state == 1                                   &&
          namespaceName.equal(U_CONSTANT_TO_PARAM("xmlns")) &&
           accessorName == *UString::str_ns)
         {
         envelope.nsName = value;

         U_INTERNAL_DUMP("envelope.nsName = %V", envelope.nsName.rep)
         }
Exemplo n.º 23
0
            UHTTP::mime_index = U_html;

            u_http_info.endHeader = 0;
        }

        (void) UClientImage_Base::wbuffer->append(
            U_CONSTANT_TO_PARAM("<!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>")
        );

        Fortune* elem;
        unsigned char encoded[1024];

        pstmt_fortune->execute();

        pvfortune->push_back(U_NEW(Fortune(0, *pmessage)));
        do {
            pvfortune->push_back(U_NEW(Fortune(*pfortune)));
        }
        while (pstmt_fortune->nextRow());

        pvfortune->sort(Fortune::cmp_obj);

        for (uint32_t i = 0, n = pvfortune->size(); i < n; ++i)
        {
            elem = (*pvfortune)[i];

            (void) u_xml_encode((const unsigned char*)U_STRING_TO_PARAM(elem->message), encoded);

            USP_PRINTF_ADD(
                "<tr>"
Exemplo n.º 24
0
#else
   (void) U_SYSCALL(dlclose, "%p", handle);
#endif

   err    = 0;
   addr   = 0;
   handle = 0;
}

void UDynamic::setPluginDirectory(const UString& dir)
{
   U_TRACE(0, "UDynamic::setPluginDirectory(%V)", dir.rep)

   U_INTERNAL_ASSERT(dir.isNullTerminated())

   if (plugin_dir == 0) plugin_dir = U_NEW(UString(dir));
   else
      {
      U_INTERNAL_DUMP("plugin_dir = %V", plugin_dir->rep)

      if (*plugin_dir != dir) *plugin_dir = dir;
      }
}

void UDynamic::clear()
{
   U_TRACE(0, "UDynamic::clear()")

   if (plugin_dir)
      {
      delete plugin_dir;
Exemplo n.º 25
0
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
}
Exemplo n.º 26
0
ULog::ULog(const UString& path, uint32_t _size, const char* dir_log_gz) : UFile(path, 0)
{
   U_TRACE_REGISTER_OBJECT(0, ULog, "%V,%u,%S", path.rep, _size, dir_log_gz)

   lock         = 0;
   ptr_log_data = 0;
   log_file_sz  =
   log_gzip_sz  = 0;

   U_Log_start_stop_msg(this) = false;

#ifdef USE_LIBZ
     buf_path_compress = 0;
   index_path_compress = 0;
#endif

   if (UFile::getPath().equal(U_CONSTANT_TO_PARAM("syslog")))
      {
      U_Log_syslog(this) = true;

#  ifndef _MSWINDOWS_
      openlog(u_progname, LOG_PID, LOG_LOCAL0);
#  endif

      return;
      }

   if (UFile::creat(O_RDWR | O_APPEND, 0664) == false)
      {
#  ifndef U_COVERITY_FALSE_POSITIVE
      U_ERROR("cannot creat log file %.*S", U_FILE_TO_TRACE(*this));
#  endif

      return;
      }

   /**
    * typedef struct log_data {
    *  uint32_t file_ptr;
    *  uint32_t file_page;
    *  uint32_t gzip_len;
    *  sem_t lock_shared;
    *  char spinlock_shared[1];
    *  // --------------> maybe unnamed array of char for gzip compression...
    * } log_data;
    */

   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);

      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));

         if (ptr)
            {
            ptr_log_data->file_ptr = ptr - UFile::map;

            // NB: we can be an other process that manage this file (apache like log)...

            u_put_unalignedp64(ptr,    U_MULTICHAR_CONSTANT64('\n','\n','\n','\n','\n','\n','\n','\n'));
            u_put_unalignedp64(ptr+8,  U_MULTICHAR_CONSTANT64('\n','\n','\n','\n','\n','\n','\n','\n'));
            u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64('\n','\n','\n','\n','\n','\n','\n','\n'));

            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_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)
      {
#  ifndef U_COVERITY_FALSE_POSITIVE // Uninitialized pointer read (UNINIT)
      (void) UFile::setPathFromFile(*this, ptr, suffix, len_suffix);
#  endif

      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();

      (void) memcpy(ptr, dir_log_gz, len);

       ptr  += len;
      *ptr++ = '/';

      buf_path_compress->size_adjust(len + 1 + sz + len_suffix);

      (void) memcpy(ptr, name.data(), sz);
                    ptr            += sz;
      (void) memcpy(ptr, suffix, len_suffix);

      index_path_compress = buf_path_compress->distance(ptr) + 1;
      }
#endif
}
Exemplo n.º 27
0
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);
}