Ejemplo n.º 1
0
HttpBaWwwAuthenticate::HttpBaWwwAuthenticate(const char* name_, unsigned name_len, const char* value_, unsigned value_len)
{
   U_TRACE_REGISTER_OBJECT(5, HttpBaWwwAuthenticate, "%.*S,%u,%.*S,%u", name_len, name_, name_len, value_len, value_, value_len)

   U_INTERNAL_ASSERT(memcmp(name_,  U_CONSTANT_TO_PARAM("WWW-Authenticate")) == 0)
   U_INTERNAL_ASSERT(memcmp(value_, U_CONSTANT_TO_PARAM(" Basic realm")) == 0)

   name.assign(name_, name_len);

   UVector<UString> vec;
   buffer.assign(value_, value_len);

   (void) U_VEC_SPLIT(vec, buffer, "=");

   realm = vec[2];
}
Ejemplo n.º 2
0
UString USOAPParser::processMessage(const UString& msg, URPCObject& object, bool& bContainsFault)
{
   U_TRACE(0, "USOAPParser::processMessage(%V,%p,%p,%b)", msg.rep, &object, &bContainsFault)

   U_INTERNAL_ASSERT(msg)

   UString retval;

   clearData();

   if (U_STRING_FIND(msg, 0, "http://schemas.xmlsoap.org/soap/envelope/") != U_NOT_FOUND)
      {
      zero();

      bContainsFault = true;

      (void) retval.assign(U_CONSTANT_TO_PARAM("<?xml version=\"1.0\" ?>"
                                               "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                                                  "<env:Header>"
                                                   "<env:Upgrade>"
                                                      "<env:SupportedEnvelope qname=\"ns1:Envelope\" xmlns:ns1=\"http://www.w3.org/2003/05/soap-envelope\"/>"
                                                   "</env:Upgrade>"
                                                  "</env:Header>"
                                                  "<env:Body>"
                                                   "<env:Fault>"
                                                      "<faultcode>env:VersionMismatch</faultcode>"
                                                      "<faultstring>Version Mismatch</faultstring>"
                                                   "</env:Fault>"
                                                  "</env:Body>"
                                               "</env:Envelope>"));
      }
   else if (parse(msg))
      {
      U_ASSERT_EQUALS(envelope.methodName.equal(U_CONSTANT_TO_PARAM("Fault")), false)

      retval = object.processMessage(envelope, bContainsFault);
      }
   else
      {
      int line = ::XML_GetCurrentLineNumber(m_parser),
          coln = ::XML_GetCurrentColumnNumber(m_parser);

      object.setFailed();

      URPCMethod::pFault->getFaultReason() = UXMLParser::getErrorMessage();

      U_INTERNAL_DUMP("UXMLParser: %V (%d,%d) ", URPCMethod::pFault->getFaultReason().rep, line, coln)

      URPCMethod::pFault->setDetail("The fault occurred near position (line: %d col: %d) within the message", line, coln);

      bContainsFault = true;
      retval         = URPCMethod::encoder->encodeFault(URPCMethod::pFault);
      }

   U_RETURN_STRING(retval);
}
Ejemplo n.º 3
0
HttpOtpPostLogin::HttpOtpPostLogin(const char* buf, unsigned len, const UString& user_field,
                                   const UString& pin_field, const UString& token_field, const UString& passwd_field,
                                   const UString& cf_field, HttpHeader& header)
{
   U_TRACE(5, "HttpOtpPostLogin::HttpOtpPostLogin(%.*S,%u,%.*S,%.*S,%.*S,%.*S,%p)", len, buf, len,
                     U_STRING_TO_TRACE(user_field), U_STRING_TO_TRACE(pin_field), U_STRING_TO_TRACE(token_field),
                     U_STRING_TO_TRACE(passwd_field), U_STRING_TO_TRACE(cf_field), &header)

   HttpField* f = header.find(U_STRING_FROM_CONSTANT("Content-Type"));

   U_INTERNAL_ASSERT_POINTER(f)

   U_INTERNAL_ASSERT(f->value.find("application/x-www-form-urlencoded") != unsigned(-1))

   buffer.assign(buf, len);

   (void) U_VEC_SPLIT(vec, buffer, "=&"); // "user=stefano+casazza&pin=12345&token=autorizzativo"

   unsigned i = 0;

   while (i < vec.size())
      {
      if (vec[i] == user_field)
         {
         U_STR_RESERVE(user, 64);

         Url::decode(vec[i+1], user);
         }
      else if (vec[i] == pin_field)
         {
         U_STR_RESERVE(pin, 64);

         Url::decode(vec[i+1], pin);
         }
      else if (vec[i] == token_field)
         {
         U_STR_RESERVE(token, 64);

         Url::decode(vec[i+1], token);
         }
      else if (vec[i] == passwd_field)
         {
         U_STR_RESERVE(passwd, 64);

         Url::decode(vec[i+1], passwd);
         }
      else if (vec[i] == cf_field)
         {
         U_STR_RESERVE(cf, 64);

         Url::decode(vec[i+1], cf);
         }

      i += 2;
      }
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
   U_ULIB_INIT(argv);

   U_TRACE(5,"main(%d)",argc)

   UTwilioClient tc(U_STRING_FROM_CONSTANT("SID"), U_STRING_FROM_CONSTANT("TOKEN"));

   bool ok = tc.getCompletedCalls();

   U_INTERNAL_ASSERT(ok)

   ok = tc.makeCall(U_CONSTANT_TO_PARAM("xxx-xxx-xxxx"), U_CONSTANT_TO_PARAM("xxx-xxx-xxxx"), U_CONSTANT_TO_PARAM("http://xxxx"));

   U_INTERNAL_ASSERT(ok)

   ok = tc.sendSMS(U_CONSTANT_TO_PARAM("xxx-xxx-xxxx"), U_CONSTANT_TO_PARAM("xxx-xxx-xxxx"), U_CONSTANT_TO_PARAM("\"Hello, how are you?\""));

   U_INTERNAL_ASSERT(ok)
}
Ejemplo n.º 5
0
HttpLocation::HttpLocation(const char* name_, unsigned name_len, const char* value_, unsigned value_len)
{
   U_TRACE_REGISTER_OBJECT(5, HttpLocation, "%.*S,%u,%.*S,%u", name_len, name_, name_len, value_len, value_, value_len)

   U_INTERNAL_ASSERT(memcmp(name_,  U_CONSTANT_TO_PARAM("Location")) == 0)

   name.assign(name_, name_len);

   trim(value_, value_len);

   url.assign(value_, value_len);

   U_INTERNAL_DUMP("url = %.*S", U_STRING_TO_TRACE(url))
}
Ejemplo n.º 6
0
void UXMLElement::splitNamespaceAndName(const UString& _str, UString& _namespaceName, UString& _accessorName)
{
   U_TRACE(0+256, "UXMLElement::splitNamespaceAndName(%.*S,%p,%p)", U_STRING_TO_TRACE(_str), &_namespaceName, &_accessorName)

   U_INTERNAL_ASSERT(_str)

   uint32_t nColonPos = _str.find(':');

   if (nColonPos != U_NOT_FOUND)
      {
      _namespaceName = _str.substr(0U, nColonPos);
       _accessorName  = _str.substr(nColonPos + 1, _str.length() - nColonPos - 1);
      }
   else
      {
      _namespaceName.clear();
       _accessorName = _str;
      }
}
Ejemplo n.º 7
0
U_NO_EXPORT void UProcess::setStdInOutErr(bool fd_stdin, bool fd_stdout, bool fd_stderr)
{
   U_TRACE(1, "UProcess::setStdInOutErr(%b,%b,%b)", fd_stdin, fd_stdout, fd_stderr)

#ifdef __MINGW32__
   HANDLE hProcess = GetCurrentProcess();
#endif

   // check if we write to STDIN

   if (fd_stdin)
      {
#  ifdef __MINGW32__
      if (hFile[1]) // Created parent-output pipe...
         {
         hChildIn = hFile[0];

         // Duplicating as inheritable child-input pipe
         // -------------------------------------------
         // (void) U_SYSCALL(DuplicateHandle, "%p,%p,%p,%p,%lu,%b,%lu", hProcess, hFile[0], hProcess, &hChildIn, 0, TRUE, DUPLICATE_SAME_ACCESS);
         // (void) U_SYSCALL(    CloseHandle, "%p",                               hFile[0]);
         }
      else
         {
         hChildIn = (HANDLE)_get_osfhandle(filedes[0]);
         }
#  else
      U_INTERNAL_ASSERT_MAJOR(filedes[0],STDERR_FILENO)

      (void) U_SYSCALL(dup2, "%d,%d", filedes[0], STDIN_FILENO);

      U_INTERNAL_ASSERT_EQUALS(::fcntl(STDIN_FILENO,F_GETFD,FD_CLOEXEC), 0)
#  endif
      }

   // check if we read from STDOUT

   if (fd_stdout)
      {
#  ifdef __MINGW32__
      if (hFile[2]) // Created parent-input pipe...
         {
         hChildOut = hFile[3];

         // Duplicating as inheritable child-output pipe
         // -------------------------------------------
         // (void) U_SYSCALL(DuplicateHandle, "%p,%p,%p,%p,%lu,%b,%lu", hProcess, hFile[3], hProcess, &hChildOut, 0, TRUE, DUPLICATE_SAME_ACCESS);
         // (void) U_SYSCALL(    CloseHandle, "%p",                               hFile[3]);
         }
      else
         {
         hChildOut = (HANDLE)_get_osfhandle(filedes[3]);
         }
#  else
      U_INTERNAL_ASSERT_MAJOR(filedes[3],STDOUT_FILENO)

      (void) U_SYSCALL(dup2, "%d,%d", filedes[3], STDOUT_FILENO);

      U_INTERNAL_ASSERT_EQUALS(::fcntl(STDOUT_FILENO,F_GETFD,FD_CLOEXEC), 0)
#  endif
      }

   // check if we read from STDERR

   if (fd_stderr)
      {
#  ifdef __MINGW32__
      if (hFile[4]) // Created parent-input pipe...
         {
         hChildErr = hFile[5];

         // Duplicating as inheritable child-output pipe
         // -------------------------------------------
         // (void) U_SYSCALL(DuplicateHandle, "%p,%p,%p,%p,%lu,%b,%lu", hProcess, hFile[5], hProcess, &hChildErr, 0, TRUE, DUPLICATE_SAME_ACCESS);
         // (void) U_SYSCALL(    CloseHandle, "%p",                               hFile[5]);
         }
      else
         {
         hChildErr = (HANDLE)_get_osfhandle(filedes[5]);
         }
#  else
      U_INTERNAL_ASSERT(filedes[5] >= STDOUT_FILENO)

      (void) U_SYSCALL(dup2, "%d,%d", filedes[5], STDERR_FILENO);

      U_INTERNAL_ASSERT_EQUALS(::fcntl(STDERR_FILENO,F_GETFD,FD_CLOEXEC), 0)
#  endif
      }

#ifdef __MINGW32__
   CloseHandle(hProcess);
#else
   if (fd_stdin)
      {
      U_INTERNAL_DUMP("filedes[0,1] = { %d, %d }", filedes[0], filedes[1])

                                      (void) U_SYSCALL(close, "%d", filedes[0]);
      if (filedes[1] > STDERR_FILENO) (void) U_SYSCALL(close, "%d", filedes[1]);
      }

   if (fd_stdout)
      {
      U_INTERNAL_DUMP("filedes[2,3] = { %d, %d }", filedes[2], filedes[3])

                                       (void) U_SYSCALL(close, "%d", filedes[3]);
      if (filedes[2] > STDERR_FILENO)  (void) U_SYSCALL(close, "%d", filedes[2]);
      }

   if (fd_stderr)
      {
      U_INTERNAL_DUMP("filedes[4,5] = { %d, %d }", filedes[4], filedes[5])

                                       (void) U_SYSCALL(close, "%d", filedes[5]);
      if (filedes[4] > STDERR_FILENO)  (void) U_SYSCALL(close, "%d", filedes[4]);
      }
#endif
}
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), 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)
         }
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
}
Ejemplo n.º 11
0
OtpAuthToken::OtpAuthToken(CryptEngine* eng_, const UString& buf)
{
   U_TRACE_REGISTER_OBJECT(5, OtpAuthToken, "%p,%.*S", eng_,  U_STRING_TO_TRACE(buf))

   eng = eng_;

   U_STR_RESERVE(buffer, 1000);

   long pos;
   unsigned char ptr[1000];

#ifdef U_PROXY_UNIT
   Base64engine eng1;
   pos = eng1.decode((unsigned char*)buf.data(), (long)buf.size(), ptr);
   pos = eng->decrypt(ptr, pos, (unsigned char*)buffer.data());
#else
   pos = u_base64_decode(U_STRING_TO_PARAM(buf), ptr);
#  ifdef USE_LIBSSL
   pos = u_des3_decode(ptr, pos, (unsigned char*)buffer.data());
#  endif
#endif

   U_STR_SIZE_ADJUST_FORCE(buffer, pos);

   migrate   = false;
   valid     = (memcmp(buffer.data(), U_CONSTANT_TO_PARAM("TID=")) == 0);
   timestamp = 0;

   if (valid)
      {
      unsigned n = U_VEC_SPLIT(vec, buffer, "=; \r\n"), i = 10;

      if (n < i)
         {
         valid = false;

         return;
         }

      U_INTERNAL_ASSERT(vec[0] == U_STRING_FROM_CONSTANT("TID"))
      tid = vec[1];
      U_INTERNAL_ASSERT(vec[2] == U_STRING_FROM_CONSTANT("UID"))
      uid = vec[3];
      U_INTERNAL_ASSERT(vec[4] == U_STRING_FROM_CONSTANT("SID"))
      sid = vec[5];
      U_INTERNAL_ASSERT(vec[6] == U_STRING_FROM_CONSTANT("TS"))
      ts = vec[7];
      U_INTERNAL_ASSERT(vec[8] == U_STRING_FROM_CONSTANT("CF"))
      cf = vec[9];

      while (i < n)
         {
         if (vec[i] == U_STRING_FROM_CONSTANT("MIGRATE"))
            {
            migrate = true;

            ++i;
            }
         else
            {
            hp.push_back(vec[i]);

            ++i;

            if (i >= n)
               {
               valid = false;

               return;
               }

            hp.push_back(vec[i]);

            ++i;
            }
         }

#  ifdef U_STD_STRING
      char* _ptr = (char*) ts.c_str();
#  else
      char* _ptr = ts.data();
#  endif

      static struct tm tm;

      (void) strptime(_ptr, "%Y%m%d%H%M%S", &tm);

      timestamp = mktime(&tm);
      }
}
Ejemplo n.º 12
0
HttpCookie::HttpCookie(const char* name_, unsigned name_len, const char* value_, unsigned value_len)
{
   U_TRACE_REGISTER_OBJECT(5, HttpCookie, "%.*S,%u,%.*S,%u", name_len, name_, name_len, value_len, value_, value_len)

   U_INTERNAL_ASSERT(memcmp(name_,  U_CONSTANT_TO_PARAM("Cookie")) == 0)

     name.assign(name_,   name_len);
   buffer.assign(value_, value_len);

#ifdef SERGIO
   // NOTA BENE: La virgola come separatore non viene supportata per consentire l'utilizzo di COOKIE_SPECIAL_VALUE

   UVector<UString> tvec,tvec1;

   (void) cookie_split(tvec, buffer, "=");

   const char* s;
   const char* p;
   const char* pc;
   const char* delim;
   unsigned i, num, size;

   for (i = 0; i < tvec.size(); i++)
      {
      s    = tvec[i].data();

      /* modifica stefano */
      size = tvec[i].size();

      pc = (const char*) memrchr(s, ',', size);
      p  = (const char*) memrchr(s, ';', size);

      if (pc > p)
         {
         p = pc;

         delim = ",";
         }
      else
         {
         delim = ";";
         }

      if (p != NULL)
         {
         /* modifica stefano */

         num = cookie_split(tvec1, tvec[i], delim);

         U_INTERNAL_ASSERT(num > 1)

         vec.push_back(tvec1[0]);
         vec.push_back(tvec1[1]);

         tvec1.clear();
         }
      else
         {
         vec.push_back(tvec[i]);
         }
      }

   tvec.clear();
#else
   (void) U_VEC_SPLIT(vec, buffer, "=;, \r\n");
#endif

#ifdef DEBUG
   for (unsigned i = 0; i < vec.size(); ++i)
      {
      U_DUMP("vec[%d] = %.*S", i, U_STRING_TO_TRACE(vec[i]))
      }
#endif
}