[vlc-commits] httpd: simplify httpd_ReasonFromCode

Rafaël Carré git at videolan.org
Sun Feb 16 12:02:53 CET 2014


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Sun Feb 16 11:36:33 2014 +0100| [5e0e8697de0815674f8312a02f8c89f1c7de4777] | committer: Rafaël Carré

httpd: simplify httpd_ReasonFromCode

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5e0e8697de0815674f8312a02f8c89f1c7de4777
---

 src/network/httpd.c |  144 +++++++++++++++++++++++++--------------------------
 1 file changed, 72 insertions(+), 72 deletions(-)

diff --git a/src/network/httpd.c b/src/network/httpd.c
index a9a76a3..10912d5 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -177,89 +177,89 @@ struct httpd_client_t
 /*****************************************************************************
  * Various functions
  *****************************************************************************/
-typedef struct
-{
-    unsigned   i_code;
-    const char psz_reason[36];
-} http_status_info;
-
-static const http_status_info http_reason[] =
-{
-  /*{ 100, "Continue" },
-    { 101, "Switching Protocols" },*/
-    { 200, "OK" },
-  /*{ 201, "Created" },
-    { 202, "Accepted" },
-    { 203, "Non-authoritative information" },
-    { 204, "No content" },
-    { 205, "Reset content" },
-    { 206, "Partial content" },
-    { 250, "Low on storage space" },
-    { 300, "Multiple choices" },*/
-    { 301, "Moved permanently" },
-  /*{ 302, "Moved temporarily" },
-    { 303, "See other" },
-    { 304, "Not modified" },
-    { 305, "Use proxy" },
-    { 307, "Temporary redirect" },
-    { 400, "Bad request" },*/
-    { 401, "Unauthorized" },
-  /*{ 402, "Payment Required" },*/
-    { 403, "Forbidden" },
-    { 404, "Not found" },
-    { 405, "Method not allowed" },
-  /*{ 406, "Not acceptable" },
-    { 407, "Proxy authentication required" },
-    { 408, "Request time-out" },
-    { 409, "Conflict" },
-    { 410, "Gone" },
-    { 411, "Length required" },
-    { 412, "Precondition failed" },
-    { 413, "Request entity too large" },
-    { 414, "Request-URI too large" },
-    { 415, "Unsupported media Type" },
-    { 416, "Requested range not satisfiable" },
-    { 417, "Expectation failed" },
-    { 451, "Parameter not understood" },
-    { 452, "Conference not found" },
-    { 453, "Not enough bandwidth" },*/
-    { 454, "Session not found" },
-    { 455, "Method not valid in this State" },
-    { 456, "Header field not valid for resource" },
-    { 457, "Invalid range" },
-  /*{ 458, "Read-only parameter" },*/
-    { 459, "Aggregate operation not allowed" },
-    { 460, "Non-aggregate operation not allowed" },
-    { 461, "Unsupported transport" },
-  /*{ 462, "Destination unreachable" },*/
-    { 500, "Internal server error" },
-    { 501, "Not implemented" },
-  /*{ 502, "Bad gateway" },*/
-    { 503, "Service unavailable" },
-  /*{ 504, "Gateway time-out" },*/
-    { 505, "Protocol version not supported" },
-    { 551, "Option not supported" },
-    { 999, "" }
-};
-
-static const char psz_fallback_reason[5][16] =
-{ "Continue", "OK", "Found", "Client error", "Server error" };
-
 static const char *httpd_ReasonFromCode( unsigned i_code )
 {
-    const http_status_info *p;
+    typedef struct
+    {
+        unsigned   i_code;
+        const char psz_reason[36];
+    } http_status_info;
+
+    static const http_status_info http_reason[] =
+    {
+        /*{ 100, "Continue" },
+          { 101, "Switching Protocols" },*/
+        { 200, "OK" },
+        /*{ 201, "Created" },
+          { 202, "Accepted" },
+          { 203, "Non-authoritative information" },
+          { 204, "No content" },
+          { 205, "Reset content" },
+          { 206, "Partial content" },
+          { 250, "Low on storage space" },
+          { 300, "Multiple choices" },*/
+        { 301, "Moved permanently" },
+        /*{ 302, "Moved temporarily" },
+          { 303, "See other" },
+          { 304, "Not modified" },
+          { 305, "Use proxy" },
+          { 307, "Temporary redirect" },
+          { 400, "Bad request" },*/
+        { 401, "Unauthorized" },
+        /*{ 402, "Payment Required" },*/
+        { 403, "Forbidden" },
+        { 404, "Not found" },
+        { 405, "Method not allowed" },
+        /*{ 406, "Not acceptable" },
+          { 407, "Proxy authentication required" },
+          { 408, "Request time-out" },
+          { 409, "Conflict" },
+          { 410, "Gone" },
+          { 411, "Length required" },
+          { 412, "Precondition failed" },
+          { 413, "Request entity too large" },
+          { 414, "Request-URI too large" },
+          { 415, "Unsupported media Type" },
+          { 416, "Requested range not satisfiable" },
+          { 417, "Expectation failed" },
+          { 451, "Parameter not understood" },
+          { 452, "Conference not found" },
+          { 453, "Not enough bandwidth" },*/
+        { 454, "Session not found" },
+        { 455, "Method not valid in this State" },
+        { 456, "Header field not valid for resource" },
+        { 457, "Invalid range" },
+        /*{ 458, "Read-only parameter" },*/
+        { 459, "Aggregate operation not allowed" },
+        { 460, "Non-aggregate operation not allowed" },
+        { 461, "Unsupported transport" },
+        /*{ 462, "Destination unreachable" },*/
+        { 500, "Internal server error" },
+        { 501, "Not implemented" },
+        /*{ 502, "Bad gateway" },*/
+        { 503, "Service unavailable" },
+        /*{ 504, "Gateway time-out" },*/
+        { 505, "Protocol version not supported" },
+        { 551, "Option not supported" },
+        { 999, "" }
+    };
+
+    static const char psz_fallback_reason[5][16] = {
+        "Continue", "OK", "Found", "Client error", "Server error"
+    };
 
     assert( ( i_code >= 100 ) && ( i_code <= 599 ) );
 
-    for (p = http_reason; i_code > p->i_code; p++);
+    const http_status_info *p = http_reason;
+    while (i_code < p->i_code)
+        p++;
 
-    if( p->i_code == i_code )
+    if (p->i_code == i_code)
         return p->psz_reason;
 
     return psz_fallback_reason[(i_code / 100) - 1];
 }
 
-
 static size_t httpd_HtmlError (char **body, int code, const char *url)
 {
     const char *errname = httpd_ReasonFromCode (code);



More information about the vlc-commits mailing list