libsoup r1016 - in branches/libsoup-2.4: . libsoup



Author: danw
Date: Mon Jan  7 01:43:44 2008
New Revision: 1016
URL: http://svn.gnome.org/viewvc/libsoup?rev=1016&view=rev

Log:
	* libsoup/soup-date.c (soup_date_new_from_now): new method to
	generate a date relative to now.
	(soup_date_new, etc): document SoupDate methods

	* libsoup/soup-server.c (got_headers): set Date header, as
	required by RFC 2616


Modified:
   branches/libsoup-2.4/ChangeLog
   branches/libsoup-2.4/libsoup/soup-date.c
   branches/libsoup-2.4/libsoup/soup-date.h
   branches/libsoup-2.4/libsoup/soup-server.c

Modified: branches/libsoup-2.4/ChangeLog
==============================================================================
--- branches/libsoup-2.4/ChangeLog	(original)
+++ branches/libsoup-2.4/ChangeLog	Mon Jan  7 01:43:44 2008
@@ -1,5 +1,14 @@
 2008-01-06  Dan Winship  <danw gnome org>
 
+	* libsoup/soup-date.c (soup_date_new_from_now): new method to
+	generate a date relative to now.
+	(soup_date_new, etc): document SoupDate methods
+
+	* libsoup/soup-server.c (got_headers): set Date header, as
+	required by RFC 2616
+
+2008-01-06  Dan Winship  <danw gnome org>
+
 	* libsoup/soup-server.c (got_headers): if raw_paths isn't set,
 	decode the request's uri->path before doing anything else
 	(soup_server_class_init): add "raw-paths" property, to tell

Modified: branches/libsoup-2.4/libsoup/soup-date.c
==============================================================================
--- branches/libsoup-2.4/libsoup/soup-date.c	(original)
+++ branches/libsoup-2.4/libsoup/soup-date.c	Mon Jan  7 01:43:44 2008
@@ -45,6 +45,19 @@
 	return type;
 }
 
+/**
+ * soup_date_new:
+ * @year: the year (1-9999)
+ * @month: the month (1-12)
+ * @day: the day of the month (1-31, as appropriate for @month)
+ * @hour: the hour (0-23)
+ * @minute: the minute (0-59)
+ * @second: the second (0-59)
+ *
+ * Creates a #SoupDate representing the indicated time, UTC.
+ *
+ * Return value: a new #SoupDate
+ **/
 SoupDate *
 soup_date_new (int year, int month, int day, 
 	       int hour, int minute, int second)
@@ -63,6 +76,22 @@
 	return date;
 }
 
+/**
+ * soup_date_new_from_now:
+ * @offset_seconds: offset from current time
+ *
+ * Creates a #SoupDate representing a time @offset_seconds after the
+ * current time (or before it, if @offset_seconds is negative). If
+ * offset_seconds is 0, returns the current time.
+ *
+ * Return value: a new #SoupDate
+ **/
+SoupDate *
+soup_date_new_from_now (int offset_seconds)
+{
+	return soup_date_new_from_time_t (time (NULL) + offset_seconds);
+}
+
 static gboolean
 parse_iso8601_date (SoupDate *date, const char *date_string)
 {
@@ -282,6 +311,18 @@
 		(((year % 4 == 0) && month == 2) ? 1 : 0);
 }
 
+/**
+ * soup_date_from_now:
+ * @date_string: the date in some plausible format
+ *
+ * Parses @date_string and tries to extract a date from it. This
+ * recognizes all of the "HTTP-date" formats from RFC 2616, all ISO
+ * 8601 formats containing both a time and a date, RFC 2822 dates,
+ * and reasonable approximations thereof. (Eg, it is lenient about
+ * whitespace, leading "0"s, etc.)
+ *
+ * Return value: a new #SoupDate
+ **/
 SoupDate *
 soup_date_new_from_string (const char *date_string)
 {
@@ -320,6 +361,14 @@
 		return date;
 }
 
+/**
+ * soup_date_new_from_time_t:
+ * @when: a #time_t
+ *
+ * Creates a #SoupDate corresponding to @when
+ *
+ * Return value: a new #SoupDate
+ **/
 SoupDate *
 soup_date_new_from_time_t (time_t when)
 {
@@ -352,6 +401,15 @@
 	return days[day % 7];
 }
 
+/**
+ * soup_date_to_string:
+ * @date: a #SoupDate
+ * @format: the format to generate the date in
+ *
+ * Converts @date to a string in the format described by @format.
+ *
+ * Return value: @date as a string
+ **/
 char *
 soup_date_to_string (SoupDate *date, SoupDateFormat format)
 {
@@ -392,6 +450,12 @@
 	}
 }
 
+/**
+ * soup_date_copy:
+ * @date: a #SoupDate
+ *
+ * Copies @date.
+ **/
 SoupDate *
 soup_date_copy (SoupDate *date)
 {
@@ -401,6 +465,12 @@
 	return copy;
 }
 
+/**
+ * soup_date_free:
+ * @date: a #SoupDate
+ *
+ * Frees @date.
+ **/
 void
 soup_date_free (SoupDate *date)
 {

Modified: branches/libsoup-2.4/libsoup/soup-date.h
==============================================================================
--- branches/libsoup-2.4/libsoup/soup-date.h	(original)
+++ branches/libsoup-2.4/libsoup/soup-date.h	Mon Jan  7 01:43:44 2008
@@ -90,6 +90,7 @@
 				     int             second);
 SoupDate *soup_date_new_from_string (const char     *date_string);
 SoupDate *soup_date_new_from_time_t (time_t          when);
+SoupDate *soup_date_new_from_now    (int             offset_seconds);
 
 char     *soup_date_to_string       (SoupDate       *date,
 				     SoupDateFormat  format);

Modified: branches/libsoup-2.4/libsoup/soup-server.c
==============================================================================
--- branches/libsoup-2.4/libsoup/soup-server.c	(original)
+++ branches/libsoup-2.4/libsoup/soup-server.c	Mon Jan  7 01:43:44 2008
@@ -17,6 +17,7 @@
 #include "soup-server.h"
 #include "soup-address.h"
 #include "soup-auth-domain.h"
+#include "soup-date.h"
 #include "soup-form.h"
 #include "soup-headers.h"
 #include "soup-message-private.h"
@@ -577,6 +578,8 @@
 	SoupServer *server = client->server;
 	SoupServerPrivate *priv = SOUP_SERVER_GET_PRIVATE (server);
 	SoupURI *uri;
+	SoupDate *date;
+	char *date_string;
 	SoupAuthDomain *domain;
 	GSList *iter;
 	gboolean rejected = FALSE;
@@ -587,6 +590,19 @@
 		soup_uri_decode (uri->path);
 	}
 
+	/* Add required response headers */
+	date = soup_date_new_from_now (0);
+	date_string = soup_date_to_string (date, SOUP_DATE_HTTP);
+	soup_message_headers_replace (req->response_headers, "Date",
+				      date_string);
+	g_free (date_string);
+	soup_date_free (date);
+	
+	/* Now handle authentication. (We do this here so that if
+	 * the request uses "Expect: 100-continue", we can reject it
+	 * immediately rather than waiting for the request body to
+	 * be sent.
+	 */
 	for (iter = priv->auth_domains; iter; iter = iter->next) {
 		domain = iter->data;
 



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