]> code.citadel.org Git - citadel.git/blobdiff - webcit/tools.c
* Header file adjustments to make it work on FreeBSD
[citadel.git] / webcit / tools.c
index 149f48d3fe0c4a123b8f9eb7e26ef6760f7bab56..86fd68ec1e351f47eeddf8fc8e98fac886f32478 100644 (file)
@@ -6,16 +6,25 @@
 
 #include <ctype.h>
 #include <stdlib.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdio.h>
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
+#endif
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
+#endif
+#ifdef HAVE_LIMITS_H
 #include <limits.h>
+#endif
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <string.h>
 #include <pwd.h>
 #include <stdarg.h>
 #include <pthread.h>
 #include <signal.h>
-#include <sys/time.h>
 #include "webcit.h"
 #include "webserver.h"
 
+
 typedef unsigned char byte;
 
 #define FALSE 0
 #define TRUE 1
 
-char *ascmonths[] = {
-       "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-       "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-
-char *ascdays[] = {
-       "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-};
-
 static byte dtable[256];       /* base64 encode / decode table */
 
 char *safestrncpy(char *dest, const char *src, size_t n)
@@ -192,103 +192,6 @@ char ch;
 }
 
 
-/*
- * Format a date/time stamp for output 
- */
-void fmt_date(char *buf, time_t thetime, int brief)
-{
-       struct tm tm;
-       struct tm today_tm;
-       time_t today_timet;
-       int hour;
-
-       today_timet = time(NULL);
-       localtime_r(&today_timet, &today_tm);
-
-       localtime_r(&thetime, &tm);
-       hour = tm.tm_hour;
-       if (hour == 0)
-               hour = 12;
-       else if (hour > 12)
-               hour = hour - 12;
-
-       buf[0] = 0;
-
-       if (brief) {
-
-               if ((tm.tm_year == today_tm.tm_year)
-                 &&(tm.tm_mon == today_tm.tm_mon)
-                 &&(tm.tm_mday == today_tm.tm_mday)) {
-                       sprintf(buf, "%2d:%02d%s",
-                               hour, tm.tm_min,
-                               ((tm.tm_hour >= 12) ? "pm" : "am")
-                       );
-               }
-               else {
-                       sprintf(buf, "%s %d %d",
-                               ascmonths[tm.tm_mon],
-                               tm.tm_mday,
-                               tm.tm_year + 1900
-                       );
-               }
-       }
-       else {
-               sprintf(buf, "%s %d %d %2d:%02d%s",
-                       ascmonths[tm.tm_mon],
-                       tm.tm_mday,
-                       tm.tm_year + 1900,
-                       hour, tm.tm_min, ((tm.tm_hour >= 12) ? "pm" : "am")
-               );
-       }
-}
-
-
-
-/*
- * Format TIME ONLY for output 
- */
-void fmt_time(char *buf, time_t thetime)
-{
-       struct tm *tm;
-       int hour;
-
-       buf[0] = 0;
-       tm = localtime(&thetime);
-       hour = tm->tm_hour;
-       if (hour == 0)
-               hour = 12;
-       else if (hour > 12)
-               hour = hour - 12;
-
-       sprintf(buf, "%d:%02d%s",
-               hour, tm->tm_min, ((tm->tm_hour > 12) ? "pm" : "am")
-           );
-}
-
-
-
-
-/*
- * Format a date/time stamp to the format used in HTTP headers
- */
-void httpdate(char *buf, time_t thetime)
-{
-       struct tm *tm;
-
-       buf[0] = 0;
-       tm = localtime(&thetime);
-
-       sprintf(buf, "%s, %02d %s %4d %02d:%02d:%02d",
-               ascdays[tm->tm_wday],
-               tm->tm_mday,
-               ascmonths[tm->tm_mon],
-               tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec);
-}
-
-
-
-
-
 /*
  * Utility function to "readline" from memory
  * (returns new pointer)
@@ -585,7 +488,7 @@ void generate_uuid(char *buf) {
 
        sprintf(buf, "%s-%lx-%x-%x",
                serv_info.serv_nodename,
-               time(NULL),
+               (long)time(NULL),
                getpid(),
                (seq++)
        );