gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22121 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r22121 - in gnunet/src: include util
Date: Tue, 19 Jun 2012 23:44:38 +0200

Author: grothoff
Date: 2012-06-19 23:44:38 +0200 (Tue, 19 Jun 2012)
New Revision: 22121

Modified:
   gnunet/src/include/gnunet_strings_lib.h
   gnunet/src/util/strings.c
Log:
adding API for parsing absolute time

Modified: gnunet/src/include/gnunet_strings_lib.h
===================================================================
--- gnunet/src/include/gnunet_strings_lib.h     2012-06-19 21:14:47 UTC (rev 
22120)
+++ gnunet/src/include/gnunet_strings_lib.h     2012-06-19 21:44:38 UTC (rev 
22121)
@@ -76,6 +76,19 @@
 
 
 /**
+ * Convert a given fancy human-readable time to our internal
+ * representation.
+ *
+ * @param fancy_time human readable string (i.e. %Y-%m-%d %H:%M:%S)
+ * @param atime set to the absolute time
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
+                                       struct GNUNET_TIME_Absolute *atime);
+
+
+/**
  * Convert a given filesize into a fancy human-readable format.
  *
  * @param size number of bytes

Modified: gnunet/src/util/strings.c
===================================================================
--- gnunet/src/util/strings.c   2012-06-19 21:14:47 UTC (rev 22120)
+++ gnunet/src/util/strings.c   2012-06-19 21:44:38 UTC (rev 22121)
@@ -308,7 +308,39 @@
   return ret;
 }
 
+
 /**
+ * Convert a given fancy human-readable time to our internal
+ * representation.
+ *
+ * @param fancy_time human readable string (i.e. %Y-%m-%d %H:%M:%S)
+ * @param atime set to the absolute time
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time,
+                                       struct GNUNET_TIME_Absolute *atime)
+{
+  struct tm tv;
+  time_t t;
+
+  if ( (NULL == strptime (fancy_time, "%c", &tv)) &&
+       (NULL == strptime (fancy_time, "%Ec", &tv)) &&
+       (NULL == strptime (fancy_time, "%Y-%m-%d %H:%M:%S", &tv)) &&
+       (NULL == strptime (fancy_time, "%Y-%m-%d %H:%M", &tv)) &&
+       (NULL == strptime (fancy_time, "%x", &tv)) &&
+       (NULL == strptime (fancy_time, "%Ex", &tv)) &&
+       (NULL == strptime (fancy_time, "%Y-%m-%d", &tv)) &&
+       (NULL == strptime (fancy_time, "%Y-%m", &tv)) &&
+       (NULL == strptime (fancy_time, "%Y", &tv)) )
+    return GNUNET_SYSERR;
+  t = mktime (&tv);
+  atime->abs_value = (uint64_t) ((uint64_t) t * 1000LL);
+  return GNUNET_OK;
+}
+
+
+/**
  * Convert the len characters long character sequence
  * given in input that is in the given input charset
  * to a string in given output charset.
@@ -389,10 +421,11 @@
   return GNUNET_STRINGS_conv (input, len, charset, "UTF-8");
 }
 
+
 /**
  * Convert the len bytes-long UTF-8 string
  * given in input to the given charset.
-
+ *
  * @return the converted string (0-terminated),
  *  if conversion fails, a copy of the orignal
  *  string is returned.
@@ -403,6 +436,7 @@
   return GNUNET_STRINGS_conv (input, len, "UTF-8", charset);
 }
 
+
 /**
  * Convert the utf-8 input string to lowercase
  * Output needs to be allocated appropriately
@@ -423,6 +457,7 @@
   free(tmp_in);
 }
 
+
 /**
  * Convert the utf-8 input string to uppercase
  * Output needs to be allocated appropriately
@@ -455,7 +490,6 @@
 GNUNET_STRINGS_filename_expand (const char *fil)
 {
   char *buffer;
-
 #ifndef MINGW
   size_t len;
   size_t n;
@@ -982,7 +1016,6 @@
 }
 
 
-
 /**
  * Tries to convert 'zt_addr' string to an IPv6 address.
  * The string is expected to have the format "[ABCD::01]:80".
@@ -1114,6 +1147,7 @@
   return GNUNET_STRINGS_to_address_ipv4 (addr, addrlen, (struct sockaddr_in *) 
r_buf);
 }
 
+
 /**
  * Makes a copy of argv that consists of a single memory chunk that can be
  * freed with a single call to GNUNET_free ();
@@ -1139,6 +1173,7 @@
   return (char *const *) new_argv;
 }
 
+
 /**
  * Returns utf-8 encoded arguments.
  * Does nothing (returns a copy of argc and argv) on any platform




reply via email to

[Prev in Thread] Current Thread [Next in Thread]