gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r5710 - libmicrohttpd/src/daemon


From: gnunet
Subject: [GNUnet-SVN] r5710 - libmicrohttpd/src/daemon
Date: Thu, 11 Oct 2007 10:04:19 -0600 (MDT)

Author: grothoff
Date: 2007-10-11 10:04:19 -0600 (Thu, 11 Oct 2007)
New Revision: 5710

Added:
   libmicrohttpd/src/daemon/reason_phrase.c
   libmicrohttpd/src/daemon/reason_phrase.h
Modified:
   libmicrohttpd/src/daemon/Makefile.am
   libmicrohttpd/src/daemon/connection.c
Log:
mantis 1285

Modified: libmicrohttpd/src/daemon/Makefile.am
===================================================================
--- libmicrohttpd/src/daemon/Makefile.am        2007-10-09 03:53:15 UTC (rev 
5709)
+++ libmicrohttpd/src/daemon/Makefile.am        2007-10-11 16:04:19 UTC (rev 
5710)
@@ -15,6 +15,7 @@
   -export-dynamic -version-info 2:0:0 $(retaincommand)
 libmicrohttpd_la_SOURCES = \
   connection.c connection.h \
+  reason_phrase.c reason_phrase.h \
   daemon.c  \
   internal.c internal.h \
   memorypool.c memorypool.h \

Modified: libmicrohttpd/src/daemon/connection.c
===================================================================
--- libmicrohttpd/src/daemon/connection.c       2007-10-09 03:53:15 UTC (rev 
5709)
+++ libmicrohttpd/src/daemon/connection.c       2007-10-11 16:04:19 UTC (rev 
5710)
@@ -30,6 +30,7 @@
 #include "connection.h"
 #include "memorypool.h"
 #include "response.h"
+#include "reason_phrase.h"
 
 /**
  * Message to transmit when http 1.1 request is received
@@ -986,12 +987,14 @@
   size_t size;
   size_t off;
   struct MHD_HTTP_Header *pos;
-  char code[32];
+  char code[128];
   char date[128];
   char *data;
 
   MHD_add_extra_headers (connection);
-  SPRINTF (code, "%s %u\r\n", MHD_HTTP_VERSION_1_1, connection->responseCode);
+  const char* reason_phrase = 
MHD_get_reason_phrase_for(connection->responseCode);
+  _REAL_SNPRINTF (code, 128, "%s %u %s\r\n", MHD_HTTP_VERSION_1_1, 
+                  connection->responseCode, reason_phrase);
   off = strlen (code);
   /* estimate size */
   size = off + 2;               /* extra \r\n at the end */

Added: libmicrohttpd/src/daemon/reason_phrase.c
===================================================================
--- libmicrohttpd/src/daemon/reason_phrase.c                            (rev 0)
+++ libmicrohttpd/src/daemon/reason_phrase.c    2007-10-11 16:04:19 UTC (rev 
5710)
@@ -0,0 +1,108 @@
+/*
+     This file is part of libmicrohttpd
+     (C) 2007 Lymba
+
+
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Lesser General Public
+     License as published by the Free Software Foundation; either
+     version 2.1 of the License, or (at your option) any later version.
+
+     This library is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     Lesser General Public License for more details.
+
+     You should have received a copy of the GNU Lesser General Public
+     License along with this library; if not, write to the Free Software
+     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 
 USA
+
+*/
+
+/**
+ * @file reason_phrase.c
+ * @brief  Tables of the string response phrases
+ * @author Elliot Glaysher
+ * @author Christian Grothoff (minor code clean up)
+ */
+
+#include "reason_phrase.h"
+
+static const char * invalid_hundred[] = { };
+
+static const char * one_hundred[] = {
+  "Continue",
+  "Switching Protocols",
+  "Processing"
+};
+
+static const char* two_hundred[] = {
+  "OK",
+  "Created",
+  "Accepted",
+  "Non-Authoritative Information",
+  "No Content",
+  "Reset Content",
+  "Partial Content"
+};
+
+static const char* three_hundred[] = {
+  "Multiple Choices",
+  "Moved Permanently",
+  "Moved Temporarily",
+  "See Other",
+  "Not Modified",
+  "Use Proxy"
+};
+
+static const char* four_hundred[] = {
+  "Bad Request",
+  "Unauthorized",
+  "Payment Required",
+  "Forbidden",
+  "Not Found",
+  "Method Not Allowed",
+  "Not Acceptable",
+  "Proxy Authentication Required",
+  "Request Time-out",
+  "Conflict",
+  "Gone",
+  "Length Required",
+  "Precondition Failed",
+  "Request Entity Too Large",
+  "Request-URI Too Large",
+  "Unsupported Media Type"
+};
+
+static const char* five_hundred[] = {
+  "Internal Server Error",
+  "Bad Gateway",
+  "Service Unavailable",
+  "Gateway Time-out",
+  "HTTP Version not supported"
+};
+
+
+struct MHD_Reason_Block {
+  unsigned int max;
+  const char ** data;
+};
+
+#define BLOCK(m) { (sizeof(m) / sizeof(char*)), m }
+
+static const struct MHD_Reason_Block reasons[] = {
+  BLOCK(one_hundred),
+  BLOCK(two_hundred),
+  BLOCK(three_hundred),
+  BLOCK(four_hundred),
+  BLOCK(five_hundred),
+};
+
+const char * 
+MHD_get_reason_phrase_for(unsigned int code)
+{
+  if ( (code >= 100 && code < 600) &&
+       (reasons[code / 100].max > code % 100) )
+    return reasons[code / 100].data[code % 100];
+  return "Unknown";
+}


Property changes on: libmicrohttpd/src/daemon/reason_phrase.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: libmicrohttpd/src/daemon/reason_phrase.h
===================================================================
--- libmicrohttpd/src/daemon/reason_phrase.h                            (rev 0)
+++ libmicrohttpd/src/daemon/reason_phrase.h    2007-10-11 16:04:19 UTC (rev 
5710)
@@ -0,0 +1,38 @@
+/*
+     This file is part of libmicrohttpd
+     (C) 2007 Lymba
+
+     This library is free software; you can redistribute it and/or
+     modify it under the terms of the GNU Lesser General Public
+     License as published by the Free Software Foundation; either
+     version 2.1 of the License, or (at your option) any later version.
+
+     This library is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     Lesser General Public License for more details.
+
+     You should have received a copy of the GNU Lesser General Public
+     License along with this library; if not, write to the Free Software
+     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 
 USA
+*/
+
+/**
+ * @file reason_phrase.c
+ * @brief  Tables of the string response phrases
+ * @author Elliot Glaysher
+ */
+
+#ifndef REASON_PHRASE_H
+#define REASON_PHRASE_H
+
+/**
+ * Returns the string reason phrase for a response code.
+ *
+ * If we don't have a string for a status code, we give the first
+ * message in that status code class.
+ */
+const char* 
+MHD_get_reason_phrase_for(unsigned int code);
+
+#endif


Property changes on: libmicrohttpd/src/daemon/reason_phrase.h
___________________________________________________________________
Name: svn:eol-style
   + native





reply via email to

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