예제 #1
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   USmtpClient smtp;
   UString tmp(argv[1], strlen(argv[1]));

   if (smtp._connectServer(tmp))
      {
      UString rcpt(argv[2], strlen(argv[2]));
#  ifdef USE_LIBSSL
      bool secure = (argc == 4);
#  else
      bool secure = false;
#  endif

      smtp.setSenderAddress(U_STRING_FROM_CONSTANT("< *****@*****.** >"));
      smtp.setRecipientAddress(rcpt);

      cout << (smtp.sendMessage(secure) ? "mail     send"
                                        : "mail NOT send") << '\n';

   // exit(0);
      }
}
예제 #2
0
int U_EXPORT main(int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UCDB y(false);
   UFileConfig fcg;
   off_t sz = 30000L;
   UString cfg(argv[1], strlen(argv[1])), dbname(argv[2]);

   if (fcg.open(cfg) == false) U_ERROR("file configurazione  <%s> not valid...", fcg.getPath().data());

   URDBServer s(&fcg, false);

   if (y.UFile::creat(dbname))
      {
      y.UFile::ftruncate(sz);
      y.UFile::memmap(PROT_READ | PROT_WRITE);

      cin >> y; // do ftruncate() and munmap()...

      y.UFile::close();
      y.UFile::reset();

      if (s.open(dbname)) s.go();
      }
예제 #3
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   ULDAP ldap;

   if (ldap.init(argv[1]) &&
       ldap.set_protocol() &&
       ldap.bind(argv[2],argv[3]))
      {
      int i, n = ldap.search(argv[4], LDAP_SCOPE_ONELEVEL, (char**)attr_name);

      if (n > 0)
         {
         ULDAPEntry entry(NUM_ATTR, attr_name, n);

         ldap.get(entry);

         for (i = 0; i < n; ++i)
            {
            cout << "dn:   " << entry[i]            << "\n"
                 << "cn:   " << entry.getCStr(0, i) << "\n"
                 << "mail: " << entry.getCStr(1, i) << "\n\n";
            }
         }
      }
}
예제 #4
0
int
U_EXPORT main (int argc, char* argv[], char* env[])
{
   U_ULIB_INIT(argv);

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

   u_init_ulib_hostname();
   u_init_ulib_username();

   ULog y(U_STRING_FROM_CONSTANT("$PWD/test_log.log"), 1024, "tmp");

   y.setPrefix(U_CONSTANT_TO_PARAM(U_SERVER_LOG_PREFIX));

   uint32_t i, n = (argc > 1 ? u_atoi(argv[1]) : 10);

   for (i = 0; i < n; ++i)
      {
      y.log(U_CONSTANT_TO_PARAM("message %6d - %H %U %w"), i+1);

      y.msync();
      }

   cout << "ok" << '\n';
}
예제 #5
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UUnixSocket x;

   if (x.connectServer(UString(argv[1]), 0))
      {
      const char* str = "Hello";
      int size        = strlen(str);

      for (int i = 0; i < 2; ++i)
         {
         if (x.send(str, size) == size)
            {
            cout << str << '\n';

            char buffer[1024];

            if (x.recv(buffer, size) == size)
               {
               cout.write(buffer, size);

               cout << '\n';
               }
            }
         }
      }
}
예제 #6
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UTimeDate data1(31,12,99), data2("31/12/99");

   U_ASSERT( UTimeDate("14/09/1752").getJulian() == 2361222 )
   U_ASSERT( UTimeDate("31/12/1900").getJulian() == 2415385 )
   U_ASSERT( UTimeDate("01/01/1970").getJulian() == 2440588 )

   U_ASSERT( data1 == data2 )
   U_ASSERT( data1.getDayOfWeek() == 5 )           // Venerdi
   U_ASSERT( data2.getDayOfYear() == 365 )

   U_ASSERT( UTimeDate("1/3/00").getDayOfWeek() == 3 ) // Mercoledi
   U_ASSERT( UTimeDate(31,12,00).getDayOfYear() == 366 )

   UTimeDate data3(60,2000);
   UTimeDate data4("29/02/00");

   U_ASSERT( data3 == data4 )
   U_ASSERT( data3.getDayOfYear() == 60 )

   UTimeDate data5(60,1901);
   UTimeDate data6("1/3/1901");

   U_ASSERT( data5 == data6 )

   U_ASSERT( UTimeDate(17, 5, 2002).isValid() == true )  // TRUE   May 17th 2002 is valid
   U_ASSERT( UTimeDate(30, 2, 2002).isValid() == false ) // FALSE  Feb 30th does not exist
   U_ASSERT( UTimeDate(29, 2, 2004).isValid() == true )  // TRUE   2004 is a leap year

   UTimeDate data7(29, 2, 2004);

   UString x = data7.strftime("%Y-%m-%d");

   U_ASSERT( x == U_STRING_FROM_CONSTANT("2004-02-29") )

   U_ASSERT( UTimeDate("14/09/1752").getJulian() == 2361222 )

   cout << "Date: " << data6.strftime("%d/%m/%y") << '\n';

   while (cin >> data6) cout << data6 << '\n';

   U_ASSERT( UTimeDate::getSecondFromTime("19030314104248Z", true, "%4u%2u%2u%2u%2u%2uZ") < u_now->tv_sec )
}
예제 #7
0
int U_EXPORT main(int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UString filename;

   while (cin >> filename)
      {
      UString dati = UFile::contentOf(filename);

      check(dati);
      }
}
예제 #8
0
파일: test_crl.cpp 프로젝트: psfu/ULib
int U_EXPORT main(int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UString filename_crl, filename_ca;

   while (cin >> filename_crl &&
          cin >> filename_ca)
      {
      UString dati_crl = UFile::contentOf(filename_crl),
              dati_ca  = UFile::contentOf(filename_ca);

      check(dati_crl, dati_ca);
      }
}
예제 #9
0
파일: test_rdb.cpp 프로젝트: fast01/ULib
int
U_EXPORT main(int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UCDB y(false);
   off_t sz = 30000L;
   UString name(argv[1]);

   if (y.UFile::creat(name))
      {
      y.UFile::ftruncate(sz);
      y.UFile::memmap(PROT_READ | PROT_WRITE);

      cin >> y; // do ftruncate() and munmap()...

      y.UFile::close();
      }
예제 #10
0
파일: test_twilio.cpp 프로젝트: psfu/ULib
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)
}
예제 #11
0
int U_EXPORT main(int argc, char* argv[])
{
    U_ULIB_INIT(argv);

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

    UString x, url(argv[1], strlen(argv[1]));

    UHttpClient<USSLSocket> http(0);
    http.setRequestPasswordAuthentication(U_STRING_FROM_CONSTANT("Aladdin"),
                                          U_STRING_FROM_CONSTANT("open sesame"));

    if (http.connectServer(url) &&
            http.sendRequest(x))
    {
        UString content = http.getContent();

        cout.write(content.data(), content.size());
    }
}
예제 #12
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   U_ASSERT_EQUALS( UServices::dosMatchWithOR(U_CONSTANT_TO_PARAM("www.sito1.com"), U_CONSTANT_TO_PARAM("SSI|benchmark|www.sito1.com|www.sito2.com"), FNM_INVERT), false)

   UString buffer(2000);

   u_base64_max_columns = 72;

   UBase64::encode(U_CONSTANT_TO_PARAM(TESTOA), buffer);

   U_INTERNAL_DUMP("buffer = %#.*S", U_STRING_TO_TRACE(buffer))

   U_ASSERT( buffer == U_STRING_FROM_CONSTANT(TESTOB) )

   UBase64::decode( U_CONSTANT_TO_PARAM(TESTOB), buffer);

   U_ASSERT( buffer == U_STRING_FROM_CONSTANT(TESTOA) )

   UString cmd, result1, result2;
   int fd_stderr = U_SYSCALL(open, "%S,%d", "err/services.err", O_WRONLY);

   cmd = U_STRING_FROM_CONSTANT("ls test_services.cpp");
   result1 = UCommand::outputCommand(cmd);

// U_ASSERT( result1 == U_STRING_FROM_CONSTANT("test_services.cpp\n") )

   buffer = UServices::getUUID();
   U_INTERNAL_DUMP("buffer = %#.*S", U_STRING_TO_TRACE(buffer))

   cmd = U_STRING_FROM_CONSTANT("cat test_services.cpp");
   result2 = UCommand::outputCommand(cmd, 0, -1, fd_stderr);

   U_ASSERT( result2.empty() == false )

   cout.write(result2.data(), result2.size());
}
예제 #13
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UString value, path, domain, port, not_found;

   HttpCookie c1(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM("Name=value")),
              c2(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_2)),
              c5(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_5));

   U_ASSERT( c5.find(U_STRING_FROM_CONSTANT("otptoken"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("pluto") )

   U_ASSERT( c1.count(U_STRING_FROM_CONSTANT("Name"))    == 1 )
   U_ASSERT( c2.count(U_STRING_FROM_CONSTANT("$Domain")) == 2 )

   U_ASSERT( c1.find(U_STRING_FROM_CONSTANT("Name"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("value") )
   U_ASSERT( path    == not_found )
   U_ASSERT( domain  == not_found )
   U_ASSERT( port    == not_found )

   U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("NameB"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("ValueB") )
   U_ASSERT( domain  == U_STRING_FROM_CONSTANT("domain1") )
   U_ASSERT( port    == not_found )

#ifdef SERGIO
   U_ASSERT( path    == U_STRING_FROM_CONSTANT("/") )
#else
   U_ASSERT( path    == U_STRING_FROM_CONSTANT("\"/\"") )
#endif

   U_ASSERT( c2.del(U_STRING_FROM_CONSTANT("NameB")) == true )

   value = path = domain = port = not_found;

   U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("Name"), value, path, domain, port)  == false )
   U_ASSERT( value   == not_found )
   U_ASSERT( path    == not_found )
   U_ASSERT( domain  == not_found )
   U_ASSERT( port    == not_found )

   U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("NameC"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("ValueC") )
   U_ASSERT( path    == U_STRING_FROM_CONSTANT("domain1") )

#ifdef SERGIO
   U_ASSERT( port    == U_STRING_FROM_CONSTANT("123") )
   U_ASSERT( domain  == U_STRING_FROM_CONSTANT("/") )
#else
   U_ASSERT( port    == U_STRING_FROM_CONSTANT("\"123\"") )
   U_ASSERT( domain  == U_STRING_FROM_CONSTANT("\"/\"") )
#endif

   HttpSetCookie s1(U_CONSTANT_TO_PARAM("Set-Cookie"),  U_CONSTANT_TO_PARAM(SETCOOKIE_1)),
                 s2(U_CONSTANT_TO_PARAM("Set-Cookie2"), U_CONSTANT_TO_PARAM(SETCOOKIE_2));

   U_ASSERT( s1.count(U_STRING_FROM_CONSTANT("Domain"))  == 2 )
   U_ASSERT( s2.count(U_STRING_FROM_CONSTANT("Port"))    == 1 )

   HttpCookie c3(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_AUTH) );

   U_ASSERT( c3.count(U_STRING_FROM_CONSTANT("AUTHTOKEN")) == 1 )

   value = path = domain = port = not_found;

   U_ASSERT( c3.find(U_STRING_FROM_CONSTANT("AUTHTOKEN"), value, path, domain, port)  == true )

   U_ASSERT( path    == not_found )
   U_ASSERT( domain  == not_found )
   U_ASSERT( port    == not_found )

   value.erase(value.size()-1, 1);
   value.erase(0, 1);

#ifdef U_PROXY_UNIT
   DES3engine eng("pippo");
   OtpAuthToken a(&eng, value);
#else
   u_des3_key("pippo");
   OtpAuthToken a(0, value);
#endif

   U_ASSERT( a.tid     == U_STRING_FROM_CONSTANT("Current_Server_ID") )
   U_ASSERT( a.uid     == U_STRING_FROM_CONSTANT("User_ID") )
   U_ASSERT( a.sid     == U_STRING_FROM_CONSTANT("Session_ID") )
   U_ASSERT( a.ts      == U_STRING_FROM_CONSTANT("20031125131800") )
   U_ASSERT( a.cf      == U_STRING_FROM_CONSTANT("codicefiscale1") )
   U_ASSERT( a.migrate == true )

   HttpHeader h;
   HttpField* f = new HttpField(U_STRING_FROM_CONSTANT("Content-Type"), U_STRING_FROM_CONSTANT(" application/x-www-form-urlencoded"));
   HttpBaAuthorization* ba = new HttpBaAuthorization(U_CONSTANT_TO_PARAM("Authorization"),
                                                     U_CONSTANT_TO_PARAM(" Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="));
   HttpBaAuthorization* ba1 = new HttpBaAuthorization(U_CONSTANT_TO_PARAM("Authorization"),
                                                      U_CONSTANT_TO_PARAM(" Basic dXRlbnRlMTpzaWQx"));

   h.add(ba);
   h.add(f);
   h.add(ba1);

   HttpOtpPostLogin p(U_CONSTANT_TO_PARAM(POST_BODY), U_STRING_FROM_CONSTANT("user"),
                                                    U_STRING_FROM_CONSTANT("pin"),
                                                    U_STRING_FROM_CONSTANT("token"),
                                                    U_STRING_FROM_CONSTANT("password"),
                                                    U_STRING_FROM_CONSTANT("cf"), h);

   U_ASSERT( p.user  == U_STRING_FROM_CONSTANT("stefano casazza") )
   U_ASSERT( p.pin   == U_STRING_FROM_CONSTANT("12345") )
   U_ASSERT( p.token == U_STRING_FROM_CONSTANT("autorizzativo") )

   HttpField* p1 = h.del(U_STRING_FROM_CONSTANT("Content-Type"));

   U_ASSERT( p1 !=  0 )
   U_ASSERT( p1 == f )

   HttpBaAuthorization* p2 = (HttpBaAuthorization*) h.find(U_STRING_FROM_CONSTANT("Authorization"));

   U_ASSERT( p2 !=  0 )
   U_ASSERT( p2 == ba )

   U_ASSERT( p2->user   == U_STRING_FROM_CONSTANT("Aladdin") )
   U_ASSERT( p2->passwd == U_STRING_FROM_CONSTANT("open sesame") )

   HttpBaAuthorization* p3 = (HttpBaAuthorization*) h.find(U_STRING_FROM_CONSTANT("Authorization"), 1);

   U_ASSERT( p3 !=  0 )
   U_ASSERT( p3 == ba1 )

   U_ASSERT( p3->user   == U_STRING_FROM_CONSTANT("utente1") )
   U_ASSERT( p3->passwd == U_STRING_FROM_CONSTANT("sid1") )

   h.clear();

   UString result;

   a.stringify(result);

// TID=trustACCESS1;UID=utente1;SID=;TS=20031201174127;CF=codicefiscale1
#  define COOKIE_AUTH_1 \
"U2FsdGVkX1/QsrBvmsVHx0rrX78ldh6IJu1+4GhKoJ9O5ETSbfSiDip1gszkZX7w5ah6vkYfRWI8271LcNKhUsZVehRoscudLO8uotQgeiiF1B46ITphGw=="

// TID=trustACCESS1;UID=utente1;SID=sid;TS=20031201174127;CF=codicefiscale1;HP1=Profile_Header1;HPn=Profile_Headern;MIGRATE
#  define COOKIE_AUTH_2 \
"U2FsdGVkX1+tUkpPi14NVlKhm5KUFbSH0JFvi23+8B75MnKgtyD/sc0hc0ESmSahiYozVbS6a3OoZfWDHX3G3zuUwCP7n1+3jXK0wu6niifYUW+cKBk1WUdpJZd0xjJernDsWtPfq9j30uatAhHULG57vdrKlbtxM/EIaiaUow1AeLuDiZDcTRonghpI/aaz"

#ifdef U_PROXY_UNIT
   DES3engine eng1("password");
   OtpAuthToken c(&eng1, U_STRING_FROM_CONSTANT(COOKIE_AUTH_2));
   DES3engine eng2("password");
   OtpAuthToken b(&eng2, U_STRING_FROM_CONSTANT(COOKIE_AUTH_1));
#else
   u_des3_key("password");
   OtpAuthToken c(0, U_STRING_FROM_CONSTANT(COOKIE_AUTH_2));
   u_des3_reset();
   OtpAuthToken b(0, U_STRING_FROM_CONSTANT(COOKIE_AUTH_1));
#endif

   U_ASSERT( b.is_valid() == false )
   U_ASSERT( c.is_valid() == true )

   U_ASSERT( c.tid     == U_STRING_FROM_CONSTANT("trustACCESS1") )
   U_ASSERT( c.uid     == U_STRING_FROM_CONSTANT("utente1") )
   U_ASSERT( c.sid     == U_STRING_FROM_CONSTANT("sid") )
   U_ASSERT( c.ts      == U_STRING_FROM_CONSTANT("20031201174127") )
   U_ASSERT( c.cf      == U_STRING_FROM_CONSTANT("codicefiscale1") )
   U_ASSERT( c.migrate == true )

   value = not_found;

   U_ASSERT( c.find(U_STRING_FROM_CONSTANT("HP1"), value)  == true )
   U_ASSERT( value == U_STRING_FROM_CONSTANT("Profile_Header1") )

   U_ASSERT( c.del(U_STRING_FROM_CONSTANT("HP1"))  == true )

   value = not_found;

   U_ASSERT( c.find(U_STRING_FROM_CONSTANT("HPn"), value)  == true )
   U_ASSERT( value == U_STRING_FROM_CONSTANT("Profile_Headern") )

   HttpCookie c4(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_PROBLEM) );

   U_ASSERT( c4.count(U_STRING_FROM_CONSTANT("otptoken")) == 1 )

   value = path = domain = port = not_found;

   U_ASSERT( c4.find(U_STRING_FROM_CONSTANT("otptoken"), value, path, domain, port) == true )

   value.erase(value.size()-1, 1);
   value.erase(0, 1);

#ifdef U_PROXY_UNIT
   DES3engine eng3("password");
   OtpAuthToken d(&eng3, value);
#else
   u_des3_reset();
   OtpAuthToken d(0, value);
#endif

   U_ASSERT( d.is_valid() == false )

   result.erase(result.size()-1, 1);
   result.erase(0, 1);

   cout.write(result.data(), result.size());
}
예제 #14
0
파일: test_timeval.cpp 프로젝트: psfu/ULib
int U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UTimeVal x;

   x.set(0L);
   U_ASSERT(x.isZero());

   UTimeVal a(1L);
   UTimeVal y(a);

   a.add(8L, 1999999L);
   a.sub(8L, 1999999L);

   U_ASSERT(y == a);
   U_ASSERT(y == UTimeVal(1L));
   U_ASSERT(y <= UTimeVal(1L));
   U_ASSERT(y >= UTimeVal(1L));
   U_ASSERT(y >  UTimeVal(0L, 999999));
   U_ASSERT(y <  UTimeVal(1L, 2L));

   y = a;
   U_ASSERT(y == a);

   UTimeVal tv1;
   UTimeVal tv2(2);
   UTimeVal tv3(100);
   UTimeVal tv4(1, 100000);
   UTimeVal tv5(2);
   UTimeVal tv6(1, -100000);

   tv1.set(0L);

   U_ASSERT(tv1 == x);
   U_ASSERT(tv2 < tv3);
   U_ASSERT(tv2 <= tv2);
   U_ASSERT(tv2 >= tv4);
   U_ASSERT(tv5 >= tv6);
   U_ASSERT(tv5 != tv4);
   U_ASSERT(tv2 != tv4);
   U_ASSERT(tv1 != tv2);
   U_ASSERT(tv6 != tv1);

   U_gettimeofday

   U_ASSERT(y < *u_now);

   set_alarm();

   y.nanosleep();

   y += *u_now;

   U_ASSERT(y > *u_now);

   /*
   long start = (u_now->tv_sec - (u_now->tv_sec % U_ONE_HOUR_IN_SECOND));

   for (uint32_t i = 0; i <= U_ONE_DAY_IN_SECOND; ++i) check_time(start+i);
   */
}
예제 #15
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UTimeDate data1(31,12,99), data2("31/12/99");

   U_ASSERT( UTimeDate("14/09/1752").getJulian() == 2361222 )
   U_ASSERT( UTimeDate("31/12/1900").getJulian() == 2415385 )
   U_ASSERT( UTimeDate("01/01/1970").getJulian() == 2440588 )

   U_ASSERT( data1 == data2 )
   U_ASSERT( data1.getDayOfWeek() == 5 ) // Venerdi
   U_ASSERT( data2.getDayOfYear() == 365 )

   U_ASSERT( UTimeDate("1/3/00").getDayOfWeek() == 3 ) // Mercoledi
   U_ASSERT( UTimeDate(31,12,0).getDayOfYear() == 366 )

   UTimeDate data3(60,2000);
   UTimeDate data4("29/02/00");

   U_ASSERT( data3 == data4 )
   U_ASSERT( data3.getDayOfYear() == 60 )

   UTimeDate data5(60,1901);
   UTimeDate data6("1/3/1901");

   U_ASSERT( data5 == data6 )

   U_ASSERT( UTimeDate(17, 5, 2002).isValid() == true )  // TRUE   May 17th 2002 is valid
   U_ASSERT( UTimeDate(30, 2, 2002).isValid() == false ) // FALSE  Feb 30th does not exist
   U_ASSERT( UTimeDate(29, 2, 2004).isValid() == true )  // TRUE   2004 is a leap year

   UTimeDate data7(29, 2, 2004);

   UString x = data7.strftime("%Y-%m-%d");

   U_ASSERT( x == U_STRING_FROM_CONSTANT("2004-02-29") )

   U_ASSERT( UTimeDate("14/09/1752").getJulian() == 2361222 )

   cout << "Date: " << data6.strftime("%d/%m/%y") << '\n';

   while (cin >> data6) cout << data6 << '\n';

   U_ASSERT( UTimeDate::getSecondFromTime("19030314104248Z", true, "%4u%2u%2u%2u%2u%2uZ") < u_now->tv_sec )

   /*
   typedef struct static_date {
      struct timeval _timeval;      // => u_now
      char lock1[1];
      char date1[17+1];             // 18/06/12 18:45:56
      char lock2[1];
      char date2[26+1];             // 04/Jun/2012:18:18:37 +0200
      char lock3[1];
      char date3[6+29+2+12+2+19+1]; // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\nConnection: close\r\n
   } static_date;
   */

   ULog::static_date log_data;

   (void) u_strftime2(log_data.date1, 17,               "%d/%m/%y %T",    u_now->tv_sec + u_now_adjust);
   (void) u_strftime2(log_data.date2, 26,               "%d/%b/%Y:%T %z", u_now->tv_sec + u_now_adjust);
   (void) u_strftime2(log_data.date3, 6+29+2+12+2+17+2, "Date: %a, %d %b %Y %T GMT\r\nServer: ULib\r\nConnection: close\r\n", u_now->tv_sec);

   U_INTERNAL_DUMP("date1 = %.17S date2 = %.26S date3+6 = %.29S", log_data.date1, log_data.date2, log_data.date3+6)

   /*
   for (int i = 0; i < 360; ++i)
      {
      u_now->tv_sec++;

      UTimeDate::updateTime(log_data.date1   + 12);
      UTimeDate::updateTime(log_data.date2   + 15);
      UTimeDate::updateTime(log_data.date3+6 + 20);

      cout.write(log_data.date1, 17);
      cout.write(" - ", 3);
      cout.write(log_data.date2, 26);
      cout.write(" - ", 3);
      cout.write(log_data.date3+6, 29);
      cout.put('\n');
      }
   */
}
예제 #16
0
파일: test_http.cpp 프로젝트: fast01/ULib
int U_EXPORT main(int argc, char* argv[])
{
   U_ULIB_INIT(argv);

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

   UString x, url(argv[1], strlen(argv[1]));

   UHttpClient<UTCPSocket> http(0);

#ifndef JOHN
   http.setRequestPasswordAuthentication(U_STRING_FROM_CONSTANT("Aladdin"),
                                         U_STRING_FROM_CONSTANT("open sesame"));

   if (http.connectServer(url) &&
       http.sendRequest())
      {
      UString content = http.getContent();

      cout.write(content.data(), content.size());
      }
#else
   (void) http.setHostPort(url.getHost(), url.getPort());

#  define AB_REQUEST(ver) "GET /usp/benchmarking.usp?name=stefano HTTP/1."#ver"\r\n" \
                          "Host: stefano\r\n" \
                          "User-Agent: ApacheBench/2.3\r\n" \
                          "Accept: */*\r\n" \
                          "\r\n"

/*
#  define HTTP_VER 1
*/
#  define HTTP_VER 0
   x = U_STRING_FROM_CONSTANT(AB_REQUEST(HTTP_VER));

#  if HTTP_VER == 1
   if (http.connect())
      {
      for (uint32_t i = 0 ; i < 100000 && http.sendRequest(x); ++i)
         {
         }
      }
#  else
   for (uint32_t i = 0 ; i < 100000; ++i)
      {
      if (http.connect())
         {
         if (http.sendRequest(x))
            {
            http.close();

            continue;
            }
         }

      break;
      }
#  endif
#endif
}