Ejemplo n.º 1
0
bool UDirWalk::setDirectory(const char* dir, const char* _filter, uint32_t _filter_len)
{
   U_TRACE(0, "UDirWalk::setDirectory(%S,%.*S,%u", dir, _filter_len, _filter, _filter_len)

   pthis->pathlen = u__strlen(dir, __PRETTY_FUNCTION__);

   dir = u_getPathRelativ(dir, &(pthis->pathlen));

   U_INTERNAL_ASSERT_MAJOR(pthis->pathlen, 0)

   if (UFile::access(dir) == false)
      {
      pthis->pathlen = 0;

      U_RETURN(false);
      }

   U__MEMCPY(pthis->pathname, dir, pthis->pathlen);

   pthis->pathname[pthis->pathlen] = '\0';

   if (_filter_len)
      {
      filter     = _filter;
      filter_len = _filter_len;

      u_pfn_flags = 0;
      u_pfn_match = u_dosmatch_with_OR;
      }

   U_RETURN(true);
}
Ejemplo n.º 2
0
   void run(int argc, char* argv[], char* env[])
      {
      U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env)

      Action::run(argc, argv, env);

      // read stdin and scanf

      Action::processInputData(5);

      // --------------------------------------------------------------------------------------------------------------
      // configuration parameters
      // --------------------------------------------------------------------------------------------------------------
      // ARCHIVE_TEMPLATE                    printf form to output request of archive
      // ELECTRONIC_ARCHIVATION_SERVICE_URL  url to do request of archive
      // --------------------------------------------------------------------------------------------------------------

      UString arch_tmpl = UFile::contentOf(cfg[U_STRING_FROM_CONSTANT("ARCHIVE_TEMPLATE")]),
              url       =                  cfg[U_STRING_FROM_CONSTANT("ELECTRONIC_ARCHIVATION_SERVICE_URL")];

      UString body(arch_tmpl.size() + request_decoded.size() + (u__strlen(uid, __PRETTY_FUNCTION__) * 3) + 100U);

      body.snprintf(arch_tmpl.data(), uid, uid, uid, U_STRING_TO_TRACE(request_decoded));

      bool ok = Action::sendHttpPostRequest(url, body, "multipart/form-data; boundary=4MYWPDUi9kH5-ipE_f6CiZXFFn4SaQQOj", "OK") && Action::sendEmail();

      Action::writeToSTDOUT(ok, true);
      }
Ejemplo n.º 3
0
   void run(int argc, char* argv[], char* env[])
      {
      U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env)

      Action::run(argc, argv, env);

      // read stdin and scanf

      Action::processInputData(2);

      // --------------------------------------------------------------------------------------------------------------
      // configuration parameters
      // --------------------------------------------------------------------------------------------------------------
      // SUBJECT_TEMPLATE                 scanf form to extract data from mail header Subject:
      // SEARCH_ENGINE_FOLDER_SEARCH_URL  url to do query to search engine
      // --------------------------------------------------------------------------------------------------------------

      UString subj_tmpl = cfg[U_STRING_FROM_CONSTANT("SUBJECT_TEMPLATE")],
              url       = cfg[U_STRING_FROM_CONSTANT("SEARCH_ENGINE_FOLDER_SEARCH_URL")];

      uint32_t subject = U_STRING_FIND(request, 0, "Subject: ");

      if (subject == U_NOT_FOUND) U_ERROR("cannot find mail header subject on input data...");

      // scanf mail header Subject: from request
      // ----------------------------------------------------------------------------------------------------------------------------
      // "Subject: %*[^"]\"%[^"]\",  %*[^"]\"%[^"]\", %*[^"]\"%[^"]\""
      // ----------------------------------------------------------------------------------------------------------------------------
      // Subject: Re: TUnwired processo di registrazione utente residenziale con CPE:
      //              notifica produzione CPE cliente "workflow test", indirizzo installazione "Via Volturno, 12 50100 Firenze (FI)",
      //              UID "37723e2d-d052-4c13-a1e9-134563eb9666"
      // ----------------------------------------------------------------------------------------------------------------------------

      int n = U_SYSCALL(sscanf, "%S,%S,%p,%p,%p,%p", request.c_pointer(subject), subj_tmpl.data(), customer, installation, uid);

      if (n != 3) U_ERROR("scanf error on mail header subject...");

      U_INTERNAL_DUMP("sscanf() customer = %S installation = %S uid = %S", customer, installation, uid)

      // query to Search Engine

      UString body(10U + u__strlen(uid));

      body.snprintf("query=%s", uid);

      bool ok = Action::sendHttpPostRequest(url, body, "application/x-www-form-urlencoded", "1\n");

      Action::writeToSTDOUT(ok, ok);
      }
Ejemplo n.º 4
0
bool UREDISClient_Base::connect(const char* phost, unsigned int _port)
{
   U_TRACE(0, "UREDISClient_Base::connect(%S,%u)", phost, _port)

   UString host;

   if (phost) (void) host.assign(phost);
   else
      {
      const char* env_redis_host = (const char*) U_SYSCALL(getenv, "%S", "REDIS_HOST");

      if (env_redis_host == 0)
         {
         UClient_Base::response.snprintf("connection disabled");

         U_RETURN(false);
         }

      (void) host.assign(env_redis_host, u__strlen(env_redis_host, __PRETTY_FUNCTION__));

      const char* env_redis_port = (const char*) U_SYSCALL(getenv, "%S", "REDIS_PORT");

      if (env_redis_port) _port = atoi(env_redis_port);
      }

   if (UClient_Base::setHostPort(host, _port) &&
       UClient_Base::connect())
      {
      UClient_Base::iovcnt = 4;

      UClient_Base::iov[1].iov_base =
      UClient_Base::iov[4].iov_base = (caddr_t)" ";
      UClient_Base::iov[1].iov_len  =
      UClient_Base::iov[4].iov_len  = 1;

      UClient_Base::iov[3].iov_base =
      UClient_Base::iov[5].iov_base = (caddr_t)U_CRLF;
      UClient_Base::iov[3].iov_len  =
      UClient_Base::iov[5].iov_len  = 2;

      U_DUMP("getRedisVersion() = %V", getRedisVersion().rep)

      U_RETURN(true);
      }

   U_RETURN(false);
}
Ejemplo n.º 5
0
UString UPKCS10::getSubject(X509_REQ* _request)
{
   U_TRACE(1, "UPKCS10::getSubject(%p)", _request)

   U_INTERNAL_ASSERT_POINTER(_request)

   X509_NAME* name = X509_REQ_get_subject_name(_request);
   unsigned len    = U_SYSCALL(i2d_X509_NAME, "%p,%p", name, 0);

   UString subject(len);
   char* ptr = subject.data();

   (void) U_SYSCALL(X509_NAME_oneline, "%p,%p,%d", name, ptr, subject.capacity());

   len = u__strlen(ptr, __PRETTY_FUNCTION__);

   subject.size_adjust(len);

   U_RETURN_STRING(subject);
}
Ejemplo n.º 6
0
         UString name = UStringExt::BIOtoString(bio);

         U_RETURN_STRING(name);
         }

      return UString::getStringNull();
      }

   unsigned len = U_SYSCALL(i2d_X509_NAME, "%p,%p", n, 0);

   UString name(len);
   char* ptr = name.data();

   (void) U_SYSCALL(X509_NAME_oneline, "%p,%p,%d", n, ptr, name.capacity());

   len = u__strlen(ptr, __PRETTY_FUNCTION__);

   name.size_adjust(len);

   U_RETURN_STRING(name);
}

bool UCertificate::isIssued(const UCertificate& ca) const
{
   U_TRACE(1, "UCertificate::isIssued(%p)", &ca)

   U_INTERNAL_ASSERT_POINTER(x509)

   int ok = U_SYSCALL(X509_check_issued, "%p,%p", ca.x509, x509);

   if (ok == X509_V_OK)
Ejemplo n.º 7
0
static int create_central_header(int fd)
{
   zipentry* ze;
   int dir_size;
   int start_offset;
   ub1 header[46];
   ub1 end_header[22];
   int total_in = 0, total_out = 22;

   U_INTERNAL_TRACE("create_central_header(%d)", fd)

   /* magic number */
   header[0] = 'P';
   header[1] = 'K';
   header[2] = 1;
   header[3] = 2;
   /* version made by */
   header[4] = 20;
   header[5] = 0;
   /* version needed to extract */
   header[6] = 10;
   header[7] = 0;
   /* bit flag */
   header[8] = 0;
   header[9] = 0;
   /* compression method */
   header[10] = 0;
   header[11] = 0;
   /* file mod time */
   header[12] = 0;
   header[13] = 0;
   /* file mod date */
   header[14] = 0;
   header[15] = 0;
   /* crc 32 */
   header[16] = 0;
   header[17] = 0;
   header[18] = 0;
   header[19] = 0;
   /* compressed size */
   header[20] = 0;
   header[21] = 0;
   header[22] = 0;
   header[23] = 0;
   /* uncompressed size */
   header[24] = 0;
   header[25] = 0;
   header[26] = 0;
   header[27] = 0;
   /* filename length */
   header[28] = 0;
   header[29] = 0;
   /* extra field length */
   header[30] = 0;
   header[31] = 0;
   /* file comment length */
   header[32] = 0;
   header[33] = 0;
   /* disk number start */
   header[34] = 0;
   header[35] = 0;
   /* internal file attribs */
   header[36] = 0;
   header[37] = 0;
   /* external file attribs */
   header[38] = 0;
   header[39] = 0;
   header[40] = 0;
   header[41] = 0;
   /* relative offset of local header */
   header[42] = 0;
   header[43] = 0;
   header[44] = 0;
   header[45] = 0;

   start_offset = lseek(fd, 0, SEEK_CUR);

   for (ze = ziptail; ze != 0; ze = ze->next_entry)
      {
      total_in  += ze->usize;
      total_out += ze->csize + 76 + u__strlen(ze->filename, __PRETTY_FUNCTION__) * 2;

      if (ze->compressed)
         {
         PACK_UB2(header, CEN_COMP, 8);
         }
      else
         {
         PACK_UB2(header, CEN_COMP, 0);
         }

      PACK_UB2(header, CEN_MODTIME, ze->mod_time);
      PACK_UB2(header, CEN_MODDATE, ze->mod_date);
      PACK_UB4(header, CEN_CRC,     ze->crc);
      PACK_UB4(header, CEN_CSIZE,   ze->csize);
      PACK_UB4(header, CEN_USIZE,   ze->usize);
      PACK_UB2(header, CEN_FNLEN,   u__strlen(ze->filename, __PRETTY_FUNCTION__));
      PACK_UB4(header, CEN_OFFSET,  ze->offset);

      (void) write(fd, header,       46);
      (void) write(fd, ze->filename, u__strlen(ze->filename, __PRETTY_FUNCTION__));
      }

   dir_size = lseek(fd, 0, SEEK_CUR) - start_offset;

   /* signature for ZIP end of central directory record */
   end_header[0] = 0x50;
   end_header[1] = 0x4b;
   end_header[2] = 0x05;
   end_header[3] = 0x06;
   /* number of this disk */
   end_header[4] = 0;
   end_header[5] = 0;
   /* number of disk w/ start of central header */
   end_header[6] = 0;
   end_header[7] = 0;
   /* total number of entries in central dir on this disk*/
   PACK_UB2(end_header, 8, number_of_entries);
   /* total number of entries in central dir*/
   PACK_UB2(end_header, 10, number_of_entries);
   /* size of central dir. */
   PACK_UB4(end_header, 12, dir_size);
   /* offset of start of central dir */
   PACK_UB4(end_header, 16, start_offset);
   /* zipfile comment length */
   end_header[20] = 0;
   end_header[21] = 0;

   (void) write(fd, end_header, 22);

   U_INTERNAL_TRACE("Total:\n------\n(in = %d) (out = %d) (%s %d%%)", total_in, total_out,
                    "deflated", (int)(total_in ? ((1 - (total_out / (float)total_in)) * 100) : 0))

   return 0;
}
Ejemplo n.º 8
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, u__strlen(name, __PRETTY_FUNCTION__)), 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())

   U_NEW(UXMLElement, current, 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);

      U_NEW(UXMLAttribute, attribute, 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)
         }
Ejemplo n.º 9
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
}
Ejemplo n.º 10
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
}