gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r37888 - libmicrohttpd/src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r37888 - libmicrohttpd/src/microhttpd
Date: Mon, 5 Sep 2016 14:43:45 +0200

Author: grothoff
Date: 2016-09-05 14:43:45 +0200 (Mon, 05 Sep 2016)
New Revision: 37888

Modified:
   libmicrohttpd/src/microhttpd/connection.c
   libmicrohttpd/src/microhttpd/internal.h
Log:
-working on gettext-ing, improving log messages and indentation

Modified: libmicrohttpd/src/microhttpd/connection.c
===================================================================
--- libmicrohttpd/src/microhttpd/connection.c   2016-09-05 12:15:43 UTC (rev 
37887)
+++ libmicrohttpd/src/microhttpd/connection.c   2016-09-05 12:43:45 UTC (rev 
37888)
@@ -403,12 +403,14 @@
 int
 MHD_set_connection_value (struct MHD_Connection *connection,
                           enum MHD_ValueKind kind,
-                          const char *key, const char *value)
+                          const char *key,
+                          const char *value)
 {
   struct MHD_HTTP_Header *pos;
 
   pos = MHD_pool_allocate (connection->pool,
-                           sizeof (struct MHD_HTTP_Header), MHD_YES);
+                           sizeof (struct MHD_HTTP_Header),
+                           MHD_YES);
   if (NULL == pos)
     return MHD_NO;
   pos->header = (char *) key;
@@ -454,7 +456,8 @@
        ( (key == pos->header) ||
          ( (NULL != pos->header) &&
            (NULL != key) &&
-        (MHD_str_equal_caseless_(key, pos->header)))))
+        (MHD_str_equal_caseless_(key,
+                                 pos->header)))))
       return pos->value;
   return NULL;
 }
@@ -479,7 +482,8 @@
           (NULL != (expect = MHD_lookup_connection_value (connection,
                                                           MHD_HEADER_KIND,
                                                           
MHD_HTTP_HEADER_EXPECT))) &&
-          (MHD_str_equal_caseless_(expect, "100-continue")) &&
+          (MHD_str_equal_caseless_(expect,
+                                    "100-continue")) &&
           (connection->continue_message_write_offset <
            strlen (HTTP_100_CONTINUE)) );
 }
@@ -500,7 +504,8 @@
 
   daemon = connection->daemon;
   if (0 == (connection->daemon->options & MHD_USE_EPOLL_TURBO))
-    shutdown (connection->socket_fd, SHUT_WR);
+    shutdown (connection->socket_fd,
+              SHUT_WR);
   connection->state = MHD_CONNECTION_CLOSED;
   connection->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP;
   if ( (NULL != daemon->notify_completed) &&
@@ -516,11 +521,13 @@
      to resume accepting connections */
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
        (MHD_INVALID_PIPE_ != daemon->wpipe[1]) &&
-       (1 != MHD_pipe_write_ (daemon->wpipe[1], "c", 1)) )
+       (1 != MHD_pipe_write_ (daemon->wpipe[1],
+                              "c",
+                              1)) )
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
-                "failed to signal end of connection via pipe");
+                _("Failed to signal end of connection via pipe"));
 #endif
     }
 }
@@ -539,7 +546,8 @@
 {
 #ifdef HAVE_MESSAGES
   if (NULL != emsg)
-    MHD_DLOG (connection->daemon, emsg);
+    MHD_DLOG (connection->daemon,
+              emsg);
 #endif
   MHD_connection_close_ (connection,
                          MHD_REQUEST_TERMINATED_WITH_ERROR);
@@ -548,7 +556,7 @@
 
 /**
  * Macro to only include error message in call to
- * "connection_close_error" if we have HAVE_MESSAGES.
+ * #connection_close_error() if we have HAVE_MESSAGES.
  */
 #ifdef HAVE_MESSAGES
 #define CONNECTION_CLOSE_ERROR(c, emsg) connection_close_error (c, emsg)
@@ -598,9 +606,9 @@
   ret = response->crc (response->crc_cls,
                        connection->response_write_position,
                        response->data,
-                       (size_t)MHD_MIN ((uint64_t)response->data_buffer_size,
-                                response->total_size -
-                                connection->response_write_position));
+                       (size_t) MHD_MIN ((uint64_t)response->data_buffer_size,
+                                         response->total_size -
+                                         connection->response_write_position));
   if ( (((ssize_t) MHD_CONTENT_READER_END_OF_STREAM) == ret) ||
        (((ssize_t) MHD_CONTENT_READER_END_WITH_ERROR) == ret) )
     {
@@ -612,7 +620,7 @@
                                MHD_REQUEST_TERMINATED_COMPLETED_OK);
       else
        CONNECTION_CLOSE_ERROR (connection,
-                               "Closing connection (stream error)\n");
+                               _("Closing connection (application reported 
error generating data)\n"));
       return MHD_NO;
     }
   response->data_start = connection->response_write_position;
@@ -649,7 +657,8 @@
   response = connection->response;
   if (0 == connection->write_buffer_size)
     {
-      size = MHD_MIN(connection->daemon->pool_size, 2 * (0xFFFFFF + 
sizeof(cbuf) + 2));
+      size = MHD_MIN (connection->daemon->pool_size,
+                      2 * (0xFFFFFF + sizeof(cbuf) + 2));
       do
         {
           size /= 2;
@@ -657,10 +666,12 @@
             {
               /* not enough memory */
               CONNECTION_CLOSE_ERROR (connection,
-                                     "Closing connection (out of memory)\n");
+                                     _("Closing connection (out of 
memory)\n"));
               return MHD_NO;
             }
-          buf = MHD_pool_allocate (connection->pool, size, MHD_NO);
+          buf = MHD_pool_allocate (connection->pool,
+                                   size,
+                                   MHD_NO);
         }
       while (NULL == buf);
       connection->write_buffer_size = size;
@@ -676,13 +687,15 @@
     {
       /* difference between response_write_position and data_start is less
          than data_size which is size_t type, no need to check for overflow */
-      const size_t data_write_offset = 
(size_t)(connection->response_write_position - response->data_start);
+      const size_t data_write_offset
+        = (size_t)(connection->response_write_position - response->data_start);
       /* buffer already ready, use what is there for the chunk */
       ret = response->data_size - data_write_offset;
       if ( ((size_t) ret) > connection->write_buffer_size - sizeof (cbuf) - 2 )
        ret = connection->write_buffer_size - sizeof (cbuf) - 2;
       memcpy (&connection->write_buffer[sizeof (cbuf)],
-              &response->data[data_write_offset], ret);
+              &response->data[data_write_offset],
+              ret);
     }
   else
     {
@@ -697,7 +710,7 @@
       /* error, close socket! */
       response->total_size = connection->response_write_position;
       CONNECTION_CLOSE_ERROR (connection,
-                             "Closing connection (error generating 
response)\n");
+                             _("Closing connection (application error 
generating response)\n"));
       return MHD_NO;
     }
   if ( (((ssize_t) MHD_CONTENT_READER_END_OF_STREAM) == ret) ||
@@ -704,7 +717,8 @@
        (0 == response->total_size) )
     {
       /* end of message, signal other side! */
-      strcpy (connection->write_buffer, "0\r\n");
+      strcpy (connection->write_buffer,
+              "0\r\n");
       connection->write_buffer_append_offset = 3;
       connection->write_buffer_send_offset = 0;
       response->total_size = connection->response_write_position;
@@ -718,12 +732,17 @@
   if (ret > 0xFFFFFF)
     ret = 0xFFFFFF;
   cblen = MHD_snprintf_(cbuf,
-           sizeof (cbuf),
-           "%X\r\n", (unsigned int) ret);
+                        sizeof (cbuf),
+                        "%X\r\n",
+                        (unsigned int) ret);
   EXTRA_CHECK(cblen > 0);
   EXTRA_CHECK(cblen < sizeof(cbuf));
-  memcpy (&connection->write_buffer[sizeof (cbuf) - cblen], cbuf, cblen);
-  memcpy (&connection->write_buffer[sizeof (cbuf) + ret], "\r\n", 2);
+  memcpy (&connection->write_buffer[sizeof (cbuf) - cblen],
+          cbuf,
+          cblen);
+  memcpy (&connection->write_buffer[sizeof (cbuf) + ret],
+          "\r\n",
+          2);
   connection->response_write_position += ret;
   connection->write_buffer_send_offset = sizeof (cbuf) - cblen;
   connection->write_buffer_append_offset = sizeof (cbuf) + ret + 2;
@@ -765,8 +784,10 @@
   {
     if (NULL == end)
       return MHD_YES;
-    if ( (MHD_str_equal_caseless_ (end, "close")) ||
-         ( (MHD_str_equal_caseless_ (end, "upgrade")) &&
+    if ( (MHD_str_equal_caseless_ (end,
+                                   "close")) ||
+         ( (MHD_str_equal_caseless_ (end,
+                                     "upgrade")) &&
            (NULL == connection->response->upgrade_handler) ) )
       return MHD_NO;
    return MHD_YES;
@@ -776,7 +797,8 @@
   {
     if (NULL == end)
       return MHD_NO;
-    if (MHD_str_equal_caseless_(end, "Keep-Alive"))
+    if (MHD_str_equal_caseless_(end,
+                                "Keep-Alive"))
       return MHD_YES;
     return MHD_NO;
   }
@@ -793,12 +815,13 @@
 static void
 get_date_string (char *date)
 {
-  static const char *const days[] =
-    { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
-  static const char *const mons[] =
-    { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
-    "Nov", "Dec"
+  static const char *const days[] = {
+    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
   };
+  static const char *const mons[] = {
+    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+  };
   struct tm now;
   time_t t;
 #if !defined(HAVE_C11_GMTIME_S) && !defined(HAVE_W32_GMTIME_S) && 
!defined(HAVE_GMTIME_R)
@@ -808,13 +831,16 @@
   date[0] = 0;
   time (&t);
 #if defined(HAVE_C11_GMTIME_S)
-  if (NULL == gmtime_s (&t, &now))
+  if (NULL == gmtime_s (&t,
+                        &now))
     return;
 #elif defined(HAVE_W32_GMTIME_S)
-  if (0 != gmtime_s (&now, &t))
+  if (0 != gmtime_s (&now,
+                     &t))
     return;
 #elif defined(HAVE_GMTIME_R)
-  if (NULL == gmtime_r(&t, &now))
+  if (NULL == gmtime_r(&t,
+                       &now))
     return;
 #else
   pNow = gmtime(&t);
@@ -835,12 +861,11 @@
 
 
 /**
- * Try growing the read buffer.  We initially claim half the
- * available buffer space for the read buffer (the other half
- * being left for management data structures; the write
- * buffer can in the end take virtually everything as the
- * read buffer can be reduced to the minimum necessary at that
- * point.
+ * Try growing the read buffer.  We initially claim half the available
+ * buffer space for the read buffer (the other half being left for
+ * management data structures; the write buffer can in the end take
+ * virtually everything as the read buffer can be reduced to the
+ * minimum necessary at that point.
  *
  * @param connection the connection
  * @return #MHD_YES on success, #MHD_NO on failure
@@ -904,7 +929,9 @@
   EXTRA_CHECK (NULL != connection->version);
   if (0 == connection->version[0])
     {
-      data = MHD_pool_allocate (connection->pool, 0, MHD_YES);
+      data = MHD_pool_allocate (connection->pool,
+                                0,
+                                MHD_YES);
       connection->write_buffer = data;
       connection->write_buffer_append_offset = 0;
       connection->write_buffer_send_offset = 0;
@@ -958,16 +985,19 @@
                                                     
MHD_HTTP_HEADER_CONNECTION);
       response_has_keepalive = response_has_close;
       if ( (NULL != response_has_close) &&
-           (!MHD_str_equal_caseless_ (response_has_close, "close")) )
+           (! MHD_str_equal_caseless_ (response_has_close,
+                                       "close")) )
         response_has_close = NULL;
       if ( (NULL != response_has_keepalive) &&
-           (!MHD_str_equal_caseless_ (response_has_keepalive, "Keep-Alive")) )
+           (! MHD_str_equal_caseless_ (response_has_keepalive,
+                                       "Keep-Alive")) )
         response_has_keepalive = NULL;
       client_requested_close = MHD_lookup_connection_value (connection,
                                                             MHD_HEADER_KIND,
                                                             
MHD_HTTP_HEADER_CONNECTION);
       if ( (NULL != client_requested_close) &&
-           (!MHD_str_equal_caseless_ (client_requested_close, "close")) )
+           (! MHD_str_equal_caseless_ (client_requested_close,
+                                       "close")) )
         client_requested_close = NULL;
 
       /* now analyze chunked encoding situation */
@@ -993,7 +1023,8 @@
                   must_add_chunked_encoding = MHD_YES;
                   connection->have_chunked_upload = MHD_YES;
                 }
-              else if (MHD_str_equal_caseless_(have_encoding, "identity"))
+              else if (MHD_str_equal_caseless_ (have_encoding,
+                                                "identity"))
                 {
                   /* application forced identity encoding, can't do 'chunked' 
*/
                   must_add_close = MHD_YES;
@@ -1091,7 +1122,9 @@
                                 MHD_HTTP_HEADER_CONNECTION) ) ) ) )
       size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, 
linefeeds */
   /* produce data */
-  data = MHD_pool_allocate (connection->pool, size + 1, MHD_NO);
+  data = MHD_pool_allocate (connection->pool,
+                            size + 1,
+                            MHD_NO);
   if (NULL == data)
     {
 #ifdef HAVE_MESSAGES
@@ -1102,7 +1135,9 @@
     }
   if (MHD_CONNECTION_FOOTERS_RECEIVED == connection->state)
     {
-      memcpy (data, code, off);
+      memcpy (data,
+              code,
+              off);
     }
   if (must_add_close)
     {
@@ -1141,7 +1176,7 @@
          (! ( (pos->value == response_has_keepalive) &&
               (MHD_YES == must_add_close) &&
               (MHD_str_equal_caseless_(pos->header,
-                                MHD_HTTP_HEADER_CONNECTION) ) ) ) )
+                                       MHD_HTTP_HEADER_CONNECTION) ) ) ) )
       off += sprintf (&data[off],
                      "%s: %s\r\n",
                      pos->header,
@@ -1148,14 +1183,20 @@
                      pos->value);
   if (MHD_CONNECTION_FOOTERS_RECEIVED == connection->state)
     {
-      strcpy (&data[off], date);
+      strcpy (&data[off],
+              date);
       off += strlen (date);
     }
-  memcpy (&data[off], "\r\n", 2);
+  memcpy (&data[off],
+          "\r\n",
+          2);
   off += 2;
 
   if (off != size)
-    mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL);
+    mhd_panic (mhd_panic_cls,
+               __FILE__,
+               __LINE__,
+               NULL);
   connection->write_buffer = data;
   connection->write_buffer_append_offset = size;
   connection->write_buffer_send_offset = 0;
@@ -1190,14 +1231,17 @@
   connection->read_closed = MHD_YES;
 #ifdef HAVE_MESSAGES
   MHD_DLOG (connection->daemon,
-            "Error %u (`%s') processing request, closing connection.\n",
-            status_code, message);
+            _("Error processing request (HTTP response code is %u (`%s')). 
Closing connection.\n"),
+            status_code,
+            message);
 #endif
   EXTRA_CHECK (NULL == connection->response);
   response = MHD_create_response_from_buffer (strlen (message),
                                              (void *) message,
                                              MHD_RESPMEM_PERSISTENT);
-  MHD_queue_response (connection, status_code, response);
+  MHD_queue_response (connection,
+                      status_code,
+                      response);
   EXTRA_CHECK (NULL != connection->response);
   MHD_destroy_response (response);
   if (MHD_NO == build_header_response (connection))
@@ -1204,7 +1248,7 @@
     {
       /* oops - close! */
       CONNECTION_CLOSE_ERROR (connection,
-                             "Closing connection (failed to create response 
header)\n");
+                             _("Closing connection (failed to create response 
header)\n"));
     }
   else
     {
@@ -1228,7 +1272,7 @@
     {
 #if DEBUG_STATES
       MHD_DLOG (connection->daemon,
-                "%s: state: %s\n",
+                _("In function %s handling connection at state: %s\n"),
                 __FUNCTION__,
                 MHD_state_to_string (connection->state));
 #endif
@@ -1359,17 +1403,17 @@
 
 
 /**
- * Parse a single line of the HTTP header.  Advance
- * read_buffer (!) appropriately.  If the current line does not
- * fit, consider growing the buffer.  If the line is
- * far too long, close the connection.  If no line is
- * found (incomplete, buffer too small, line too long),
+ * Parse a single line of the HTTP header.  Advance read_buffer (!)
+ * appropriately.  If the current line does not fit, consider growing
+ * the buffer.  If the line is far too long, close the connection.  If
+ * no line is found (incomplete, buffer too small, line too long),
  * return NULL.  Otherwise return a pointer to the line.
  *
  * @param connection connection we're processing
  * @param[out] line_len pointer to variable that receive
- *                      length of line or NULL
- * @return NULL if no full line is available
+ *             length of line or NULL
+ * @return NULL if no full line is available; note that the returned
+ *         string will not be 0-termianted
  */
 static char *
 get_next_header_line (struct MHD_Connection *connection,
@@ -1382,8 +1426,9 @@
     return NULL;
   pos = 0;
   rbuf = connection->read_buffer;
-  while ((pos < connection->read_buffer_offset - 1) &&
-         ('\r' != rbuf[pos]) && ('\n' != rbuf[pos]))
+  while ( (pos < connection->read_buffer_offset - 1) &&
+          ('\r' != rbuf[pos]) &&
+          ('\n' != rbuf[pos]) )
     pos++;
   if ( (pos == connection->read_buffer_offset - 1) &&
        ('\n' != rbuf[pos]) )
@@ -1407,7 +1452,8 @@
   if (line_len)
     *line_len = pos;
   /* found, check if we have proper LFCR */
-  if (('\r' == rbuf[pos]) && ('\n' == rbuf[pos + 1]))
+  if ( ('\r' == rbuf[pos]) &&
+       ('\n' == rbuf[pos + 1]) )
     rbuf[pos++] = '\0';         /* skip both r and n */
   rbuf[pos++] = '\0';
   connection->read_buffer += pos;
@@ -1442,7 +1488,7 @@
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (connection->daemon,
-                "Not enough memory to allocate header record!\n");
+                _("Not enough memory in pool to allocate header record!\n"));
 #endif
       transmit_error_response (connection,
                               MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
@@ -1477,18 +1523,23 @@
                                     MHD_HTTP_HEADER_COOKIE);
   if (NULL == hdr)
     return MHD_YES;
-  cpy = MHD_pool_allocate (connection->pool, strlen (hdr) + 1, MHD_YES);
+  cpy = MHD_pool_allocate (connection->pool,
+                           strlen (hdr) + 1,
+                           MHD_YES);
   if (NULL == cpy)
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (connection->daemon,
-                "Not enough memory to parse cookies!\n");
+                _("Not enough memory in pool to parse cookies!\n"));
 #endif
-      transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
+      transmit_error_response (connection,
+                               MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
                                REQUEST_TOO_BIG);
       return MHD_NO;
     }
-  memcpy (cpy, hdr, strlen (hdr) + 1);
+  memcpy (cpy,
+          hdr,
+          strlen (hdr) + 1);
   pos = cpy;
   while (NULL != pos)
     {
@@ -1496,12 +1547,15 @@
         pos++;                  /* skip spaces */
 
       sce = pos;
-      while (((*sce) != '\0') &&
-             ((*sce) != ',') && ((*sce) != ';') && ((*sce) != '='))
+      while ( ((*sce) != '\0') &&
+              ((*sce) != ',') &&
+              ((*sce) != ';') &&
+              ((*sce) != '=') )
         sce++;
       /* remove tailing whitespace (if any) from key */
       ekill = sce - 1;
-      while ((*ekill == ' ') && (ekill >= pos))
+      while ( (*ekill == ' ') &&
+              (ekill >= pos) )
         *(ekill--) = '\0';
       old = *sce;
       *sce = '\0';
@@ -1509,7 +1563,10 @@
         {
           /* value part omitted, use empty string... */
           if (MHD_NO ==
-              connection_add_header (connection, pos, "", MHD_COOKIE_KIND))
+              connection_add_header (connection,
+                                     pos,
+                                     "",
+                                     MHD_COOKIE_KIND))
             return MHD_NO;
           if (old == '\0')
             break;
@@ -1558,8 +1615,8 @@
  * Parse the first line of the HTTP HEADER.
  *
  * @param connection the connection (updated)
- * @param line the first line
- * @param line_len length of the first line
+ * @param line the first line, not 0-terminated
+ * @param line_len length of the first @a line
  * @return #MHD_YES if the line is ok, #MHD_NO if it is malformed
  */
 static int
@@ -1574,7 +1631,9 @@
   char *args;
   unsigned int unused_num_headers;
 
-  if (NULL == (uri = memchr (line, ' ', line_len)))
+  if (NULL == (uri = memchr (line,
+                             ' ',
+                             line_len)))
     return MHD_NO;              /* serious error */
   uri[0] = '\0';
   connection->method = line;
@@ -1597,21 +1656,27 @@
       /* Search from back to accept misformed URI with space */
       http_version = line + line_len - 1;
       /* Skip any trailing spaces */
-      while (' ' == http_version[0] && http_version > uri)
+      while ( (' ' == http_version[0]) &&
+              (http_version > uri) )
         http_version--;
       /* Find first space in reverse direction */
-      while (' ' != http_version[0] && http_version > uri)
+      while ( (' ' != http_version[0]) &&
+              (http_version > uri) )
         http_version--;
       if (http_version > uri)
         {
           http_version[0] = '\0';
           connection->version = http_version + 1;
-          args = memchr(uri, '?', http_version - uri);
+          args = memchr (uri,
+                         '?',
+                         http_version - uri);
         }
       else
         {
           connection->version = "";
-          args = memchr(uri, '?', line_len - (uri - line));
+          args = memchr (uri,
+                         '?',
+                         line_len - (uri - line));
         }
     }
   if (NULL != daemon->uri_log_callback)
@@ -1619,7 +1684,7 @@
       connection->client_context
         = daemon->uri_log_callback (daemon->uri_log_callback_cls,
                                    curi,
-                                    connection);
+                                    connection);
       connection->client_aware = MHD_YES;
     }
   if (NULL != args)
@@ -1664,12 +1729,13 @@
                                            connection->url,
                                           connection->method,
                                           connection->version,
-                                          NULL, &processed,
+                                          NULL,
+                                           &processed,
                                           &connection->client_context))
     {
       /* serious internal error, close connection */
       CONNECTION_CLOSE_ERROR (connection,
-                             "Internal application error, closing 
connection.\n");
+                             _("Application reported internal error, closing 
connection.\n"));
       return;
     }
 }
@@ -1711,15 +1777,17 @@
             {
               /* skip new line at the *end* of a chunk */
               i = 0;
-              if ((buffer_head[i] == '\r') || (buffer_head[i] == '\n'))
+              if ( ('\r' == buffer_head[i]) ||
+                   ('\n' == buffer_head[i]) )
                 i++;            /* skip 1st part of line feed */
-              if ((buffer_head[i] == '\r') || (buffer_head[i] == '\n'))
+              if ( ('\r' == buffer_head[i]) ||
+                   ('\n' == buffer_head[i]) )
                 i++;            /* skip 2nd part of line feed */
-              if (i == 0)
+              if (0 == i)
                 {
                   /* malformed encoding */
                   CONNECTION_CLOSE_ERROR (connection,
-                                         "Received malformed HTTP request (bad 
chunked encoding), closing connection.\n");
+                                         _("Received malformed HTTP request 
(bad chunked encoding). Closing connection.\n"));
                   return;
                 }
               available -= i;
@@ -1733,9 +1801,8 @@
               /* we are in the middle of a chunk, give
                  as much as possible to the client (without
                  crossing chunk boundaries) */
-              processed =
-                connection->current_chunk_size -
-                connection->current_chunk_offset;
+              processed
+                = connection->current_chunk_size - 
connection->current_chunk_offset;
               if (processed > available)
                 processed = available;
               if (available > processed)
@@ -1747,7 +1814,8 @@
               i = 0;
               while (i < available)
                 {
-                  if ((buffer_head[i] == '\r') || (buffer_head[i] == '\n'))
+                  if ( ('\r' == buffer_head[i]) ||
+                       ('\n' == buffer_head[i]) )
                     break;
                   i++;
                   if (i >= 6)
@@ -1757,13 +1825,16 @@
                  is the unavailable character, we
                  will need to wait until we have it
                  before going further */
-              if ((i + 1 >= available) &&
-                  !((i == 1) && (available == 2) && (buffer_head[0] == '0')))
+              if ( (i + 1 >= available) &&
+                   ! ( (1 == i) &&
+                       (2 == available) &&
+                       ('0' == buffer_head[0]) ) )
                 break;          /* need more data... */
               malformed = (i >= 6);
-              if (!malformed)
+              if (! malformed)
                 {
-                  size_t num_dig = MHD_strx_to_sizet_n_ (buffer_head, i,
+                  size_t num_dig = MHD_strx_to_sizet_n_ (buffer_head,
+                                                         i,
                                                          
&connection->current_chunk_size);
                   malformed = (i != num_dig);
                 }
@@ -1771,12 +1842,13 @@
                 {
                   /* malformed encoding */
                   CONNECTION_CLOSE_ERROR (connection,
-                                         "Received malformed HTTP request (bad 
chunked encoding), closing connection.\n");
+                                         _("Received malformed HTTP request 
(bad chunked encoding). Closing connection.\n"));
                   return;
                 }
               i++;
-              if ((i < available) &&
-                  ((buffer_head[i] == '\r') || (buffer_head[i] == '\n')))
+              if ( (i < available) &&
+                   ( ('\r' == buffer_head[i]) ||
+                     ('\n' == buffer_head[i]) ) )
                 i++;            /* skip 2nd part of line feed */
 
               buffer_head += i;
@@ -1825,13 +1897,15 @@
         {
           /* serious internal error, close connection */
          CONNECTION_CLOSE_ERROR (connection,
-                                 "Internal application error, closing 
connection.\n");
+                                  _("Application reported internal error, 
closing connection.\n"));
           return;
         }
       if (processed > used)
-        mhd_panic (mhd_panic_cls, __FILE__, __LINE__
+        mhd_panic (mhd_panic_cls,
+                   __FILE__,
+                   __LINE__
 #ifdef HAVE_MESSAGES
-                  , "API violation"
+                  , _("libmicrohttpd API violation")
 #else
                   , NULL
 #endif
@@ -1847,21 +1921,23 @@
                 (0 != (connection->daemon->options & 
MHD_USE_SELECT_INTERNALLY)) ) &&
               (MHD_NO == connection->suspended) )
            MHD_DLOG (connection->daemon,
-                     "WARNING: incomplete POST processing and connection not 
suspended will result in hung connection.\n");
+                     _("WARNING: incomplete POST processing and connection not 
suspended will result in hung connection.\n"));
 #endif
        }
       used -= processed;
-      if (connection->have_chunked_upload == MHD_YES)
+      if (MHD_YES == connection->have_chunked_upload)
         connection->current_chunk_offset += used;
       /* dh left "processed" bytes in buffer for next time... */
       buffer_head += used;
       available -= used;
-      if (connection->remaining_upload_size != MHD_SIZE_UNKNOWN)
+      if (MHD_SIZE_UNKNOWN != connection->remaining_upload_size)
         connection->remaining_upload_size -= used;
     }
   while (MHD_YES == instant_retry);
   if (available > 0)
-    memmove (connection->read_buffer, buffer_head, available);
+    memmove (connection->read_buffer,
+             buffer_head,
+             available);
   connection->read_buffer_offset = available;
 }
 
@@ -1890,14 +1966,17 @@
   if (bytes_read < 0)
     {
       const int err = MHD_socket_get_error_ ();
-      if (MHD_SCKT_ERR_IS_EINTR_ (err) || MHD_SCKT_ERR_IS_EAGAIN_ (err))
+      if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
+          MHD_SCKT_ERR_IS_EAGAIN_ (err))
          return MHD_NO;
       if (MHD_SCKT_ERR_IS_REMOTE_DISCNN_ (err))
         {
-           CONNECTION_CLOSE_ERROR (connection, NULL);
+           CONNECTION_CLOSE_ERROR (connection,
+                                   NULL);
           return MHD_NO;
        }
-      CONNECTION_CLOSE_ERROR (connection, NULL);
+      CONNECTION_CLOSE_ERROR (connection,
+                              NULL);
       return MHD_YES;
     }
   if (0 == bytes_read)
@@ -1937,14 +2016,16 @@
   if (ret < 0)
     {
       const int err = MHD_socket_get_error_ ();
-      if (MHD_SCKT_ERR_IS_EINTR_ (err) || MHD_SCKT_ERR_IS_EAGAIN_ (err))
+      if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
+          MHD_SCKT_ERR_IS_EAGAIN_ (err))
         return MHD_NO;
-      CONNECTION_CLOSE_ERROR (connection, NULL);
+      CONNECTION_CLOSE_ERROR (connection,
+                              NULL);
       return MHD_YES;
     }
 #if DEBUG_SEND_DATA
   fprintf (stderr,
-           "Sent response: `%.*s'\n",
+           _("Sent response: `%.*s'\n"),
            ret,
            &connection->write_buffer[connection->write_buffer_send_offset]);
 #endif
@@ -1976,7 +2057,8 @@
   connection->state = next_state;
   MHD_pool_reallocate (connection->pool,
                       connection->write_buffer,
-                       connection->write_buffer_size, 0);
+                       connection->write_buffer_size,
+                       0);
   connection->write_buffer = NULL;
   connection->write_buffer_size = 0;
   return MHD_YES;
@@ -1993,7 +2075,8 @@
  * @return #MHD_YES on success, #MHD_NO on error (malformed @a line)
  */
 static int
-process_header_line (struct MHD_Connection *connection, char *line)
+process_header_line (struct MHD_Connection *connection,
+                     char *line)
 {
   char *colon;
 
@@ -2003,13 +2086,15 @@
     {
       /* error in header line, die hard */
       CONNECTION_CLOSE_ERROR (connection,
-                             "Received malformed line (no colon), closing 
connection.\n");
+                             _("Received malformed line (no colon). Closing 
connection.\n"));
       return MHD_NO;
     }
   /* zero-terminate header */
   colon[0] = '\0';
   colon++;                      /* advance to value */
-  while ((colon[0] != '\0') && ((colon[0] == ' ') || (colon[0] == '\t')))
+  while ( ('\0' != colon[0]) &&
+          ( (' ' == colon[0]) ||
+            ('\t' == colon[0]) ) )
     colon++;
   /* we do the actual adding of the connection
      header at the beginning of the while
@@ -2034,7 +2119,8 @@
  */
 static int
 process_broken_line (struct MHD_Connection *connection,
-                     char *line, enum MHD_ValueKind kind)
+                     char *line,
+                     enum MHD_ValueKind kind)
 {
   char *last;
   char *tmp;
@@ -2042,7 +2128,8 @@
   size_t tmp_len;
 
   last = connection->last;
-  if ((line[0] == ' ') || (line[0] == '\t'))
+  if ( (' ' == line[0]) ||
+       ('\t' == line[0]) )
     {
       /* value was continued on the next line, see
          http://www.jmarshall.com/easy/http/ */
@@ -2049,7 +2136,8 @@
       last_len = strlen (last);
       /* skip whitespace at start of 2nd line */
       tmp = line;
-      while ((tmp[0] == ' ') || (tmp[0] == '\t'))
+      while ( (' ' == tmp[0]) ||
+              ('\t' == tmp[0]) )
         tmp++;
       tmp_len = strlen (tmp);
       /* FIXME: we might be able to do this better (faster!), as most
@@ -2076,13 +2164,15 @@
       connection->last = last;
       return MHD_YES;           /* possibly more than 2 lines... */
     }
-  EXTRA_CHECK ((NULL != last) && (NULL != connection->colon));
+  EXTRA_CHECK ( (NULL != last) &&
+                (NULL != connection->colon) );
   if ((MHD_NO == connection_add_header (connection,
                                         last,
                                        connection->colon,
                                        kind)))
     {
-      transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
+      transmit_error_response (connection,
+                               MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
                                REQUEST_TOO_BIG);
       return MHD_NO;
     }
@@ -2089,10 +2179,12 @@
   /* we still have the current line to deal with... */
   if (0 != line[0])
     {
-      if (MHD_NO == process_header_line (connection, line))
+      if (MHD_NO == process_header_line (connection,
+                                         line))
         {
           transmit_error_response (connection,
-                                   MHD_HTTP_BAD_REQUEST, REQUEST_MALFORMED);
+                                   MHD_HTTP_BAD_REQUEST,
+                                   REQUEST_MALFORMED);
           return MHD_NO;
         }
     }
@@ -2118,7 +2210,8 @@
   parse_cookie_header (connection);
   if ( (0 != (MHD_USE_PEDANTIC_CHECKS & connection->daemon->options)) &&
        (NULL != connection->version) &&
-       (MHD_str_equal_caseless_(MHD_HTTP_VERSION_1_1, connection->version)) &&
+       (MHD_str_equal_caseless_(MHD_HTTP_VERSION_1_1,
+                                connection->version)) &&
        (NULL ==
         MHD_lookup_connection_value (connection,
                                      MHD_HEADER_KIND,
@@ -2129,8 +2222,7 @@
       connection->read_closed = MHD_YES;
 #ifdef HAVE_MESSAGES
       MHD_DLOG (connection->daemon,
-                "Received `%s' request without `%s' header.\n",
-                MHD_HTTP_VERSION_1_1, MHD_HTTP_HEADER_HOST);
+                _("Received HTTP 1.1 request without `Host' header.\n"));
 #endif
       EXTRA_CHECK (NULL == connection->response);
       response =
@@ -2137,7 +2229,9 @@
         MHD_create_response_from_buffer (strlen (REQUEST_LACKS_HOST),
                                         REQUEST_LACKS_HOST,
                                         MHD_RESPMEM_PERSISTENT);
-      MHD_queue_response (connection, MHD_HTTP_BAD_REQUEST, response);
+      MHD_queue_response (connection,
+                          MHD_HTTP_BAD_REQUEST,
+                          response);
       MHD_destroy_response (response);
       return;
     }
@@ -2149,7 +2243,8 @@
   if (NULL != enc)
     {
       connection->remaining_upload_size = MHD_SIZE_UNKNOWN;
-      if (MHD_str_equal_caseless_(enc, "chunked"))
+      if (MHD_str_equal_caseless_(enc,
+                                  "chunked"))
         connection->have_chunked_upload = MHD_YES;
     }
   else
@@ -2161,16 +2256,16 @@
         {
           end = clen + MHD_str_to_uint64_ (clen,
                                            &connection->remaining_upload_size);
-          if ( (clen == end) || ('\0' != *end) )
+          if ( (clen == end) ||
+               ('\0' != *end) )
             {
               connection->remaining_upload_size = 0;
 #ifdef HAVE_MESSAGES
               MHD_DLOG (connection->daemon,
-                        "Failed to parse `%s' header `%s', closing 
connection.\n",
-                        MHD_HTTP_HEADER_CONTENT_LENGTH,
-                        clen);
+                        "Failed to parse `Content-Length' header. Closing 
connection.\n");
 #endif
-             CONNECTION_CLOSE_ERROR (connection, NULL);
+             CONNECTION_CLOSE_ERROR (connection,
+                                      NULL);
               return;
             }
         }
@@ -2231,7 +2326,8 @@
   while (1)
     {
 #if DEBUG_STATES
-      MHD_DLOG (connection->daemon, "%s: state: %s\n",
+      MHD_DLOG (connection->daemon,
+                _("In function %s handling connection at state: %s\n"),
                 __FUNCTION__,
                 MHD_state_to_string (connection->state));
 #endif
@@ -2291,7 +2387,8 @@
   while (1)
     {
 #if DEBUG_STATES
-      MHD_DLOG (connection->daemon, "%s: state: %s\n",
+      MHD_DLOG (connection->daemon,
+                _("In function %s handling connection at state: %s\n"),
                 __FUNCTION__,
                 MHD_state_to_string (connection->state));
 #endif
@@ -2314,19 +2411,22 @@
           if (ret < 0)
             {
               const int err = MHD_socket_get_error_ ();
-              if (MHD_SCKT_ERR_IS_EINTR_ (err) || MHD_SCKT_ERR_IS_EAGAIN_ 
(err))
+
+              if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
+                  MHD_SCKT_ERR_IS_EAGAIN_ (err))
                 break;
 #ifdef HAVE_MESSAGES
               MHD_DLOG (connection->daemon,
-                        "Failed to send data: %s\n",
+                        _("Failed to send data: %s\n"),
                         MHD_socket_strerr_ (err));
 #endif
-             CONNECTION_CLOSE_ERROR (connection, NULL);
+             CONNECTION_CLOSE_ERROR (connection,
+                                      NULL);
               return MHD_YES;
             }
 #if DEBUG_SEND_DATA
           fprintf (stderr,
-                   "Sent 100 continue response: `%.*s'\n",
+                   _("Sent 100 continue response: `%.*s'\n"),
                    (int) ret,
                    
&HTTP_100_CONTINUE[connection->continue_message_write_offset]);
 #endif
@@ -2340,7 +2440,7 @@
           break;
         case MHD_CONNECTION_HEADERS_SENDING:
           do_write (connection);
-         if (connection->state != MHD_CONNECTION_HEADERS_SENDING)
+         if (MHD_CONNECTION_HEADERS_SENDING != connection->state)
             break;
           check_write_done (connection,
                             MHD_CONNECTION_HEADERS_SENT);
@@ -2355,6 +2455,7 @@
           {
             int err;
             uint64_t data_write_offset;
+
             if (NULL != response->crc)
               (void) MHD_mutex_lock_ (&response->mutex);
             if (MHD_YES != try_ready_normal_body (connection))
@@ -2366,7 +2467,7 @@
             data_write_offset = connection->response_write_position
                                 - response->data_start;
             if (data_write_offset > (uint64_t)SIZE_MAX)
-              MHD_PANIC("Data offset exceeds limit");
+              MHD_PANIC (_("Data offset exceeds limit"));
             ret = connection->send_cls (connection,
                                         &response->data
                                         [(size_t)data_write_offset],
@@ -2376,7 +2477,7 @@
 #if DEBUG_SEND_DATA
             if (ret > 0)
               fprintf (stderr,
-                       "Sent %d-byte DATA response: `%.*s'\n",
+                       _("Sent %d-byte DATA response: `%.*s'\n"),
                        (int) ret,
                        (int) ret,
                        &response->data[connection->response_write_position -
@@ -2391,10 +2492,11 @@
                   return MHD_YES;
 #ifdef HAVE_MESSAGES
                 MHD_DLOG (connection->daemon,
-                          "Failed to send data: %s\n",
+                          _("Failed to send data: %s\n"),
                           MHD_socket_strerr_ (err));
 #endif
-                CONNECTION_CLOSE_ERROR (connection, NULL);
+                CONNECTION_CLOSE_ERROR (connection,
+                                        NULL);
                 return MHD_YES;
               }
             connection->response_write_position += ret;
@@ -2422,9 +2524,10 @@
           break;
         case MHD_CONNECTION_FOOTERS_SENDING:
           do_write (connection);
-         if (connection->state != MHD_CONNECTION_FOOTERS_SENDING)
+         if (MHD_CONNECTION_FOOTERS_SENDING != connection->state)
            break;
-          check_write_done (connection, MHD_CONNECTION_FOOTERS_SENT);
+          check_write_done (connection,
+                            MHD_CONNECTION_FOOTERS_SENT);
           break;
         case MHD_CONNECTION_FOOTERS_SENT:
           EXTRA_CHECK (0);
@@ -2440,7 +2543,7 @@
         default:
           EXTRA_CHECK (0);
          CONNECTION_CLOSE_ERROR (connection,
-                                  "Internal error\n");
+                                  _("Internal error\n"));
           return MHD_YES;
         }
       break;
@@ -2467,8 +2570,8 @@
     }
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     {
-      if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
-        MHD_PANIC ("Failed to acquire cleanup mutex\n");
+      if (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex))
+        MHD_PANIC (_("Failed to acquire cleanup mutex\n"));
     }
   else
     {
@@ -2496,8 +2599,8 @@
   connection->resuming = MHD_NO;
   connection->in_idle = MHD_NO;
   if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-       (!MHD_mutex_unlock_(&daemon->cleanup_connection_mutex)) )
-    MHD_PANIC ("Failed to release cleanup mutex\n");
+       (! MHD_mutex_unlock_(&daemon->cleanup_connection_mutex)) )
+    MHD_PANIC (_("Failed to release cleanup mutex\n"));
 }
 
 
@@ -2524,7 +2627,7 @@
     {
 #if DEBUG_STATES
       MHD_DLOG (daemon,
-                "%s: state: %s\n",
+                _("In function %s handling connection at state: %s\n"),
                 __FUNCTION__,
                 MHD_state_to_string (connection->state));
 #endif
@@ -2531,10 +2634,12 @@
       switch (connection->state)
         {
         case MHD_CONNECTION_INIT:
-          line = get_next_header_line (connection, &line_len);
+          line = get_next_header_line (connection,
+                                       &line_len);
           /* Check for empty string, as we might want
              to tolerate 'spurious' empty lines; also
-             NULL means we didn't get a full line yet. */
+             NULL means we didn't get a full line yet;
+             line is not 0-terminated here. */
           if ( (NULL == line) ||
                (0 == line[0]) )
             {
@@ -2587,7 +2692,8 @@
           connection->state = MHD_CONNECTION_HEADER_PART_RECEIVED;
           continue;
         case MHD_CONNECTION_HEADER_PART_RECEIVED:
-          line = get_next_header_line (connection, NULL);
+          line = get_next_header_line (connection,
+                                       NULL);
           if (NULL == line)
             {
               if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED)
@@ -2601,7 +2707,9 @@
               break;
             }
           if (MHD_NO ==
-              process_broken_line (connection, line, MHD_HEADER_KIND))
+              process_broken_line (connection,
+                                   line,
+                                   MHD_HEADER_KIND))
             continue;
           if (0 == line[0])
             {
@@ -2667,10 +2775,10 @@
               if (MHD_CONNECTION_CLOSED == connection->state)
                 continue;
             }
-          if ((0 == connection->remaining_upload_size) ||
-              ((connection->remaining_upload_size == MHD_SIZE_UNKNOWN) &&
-               (0 == connection->read_buffer_offset) &&
-               (MHD_YES == connection->read_closed)))
+          if ( (0 == connection->remaining_upload_size) ||
+               ( (MHD_SIZE_UNKNOWN == connection->remaining_upload_size) &&
+                 (0 == connection->read_buffer_offset) &&
+                 (MHD_YES == connection->read_closed) ) )
             {
               if ((MHD_YES == connection->have_chunked_upload) &&
                   (MHD_NO == connection->read_closed))
@@ -2704,7 +2812,8 @@
                 break;
               continue;
             }
-          if (MHD_NO == process_header_line (connection, line))
+          if (MHD_NO == process_header_line (connection,
+                                             line))
             {
               transmit_error_response (connection,
                                        MHD_HTTP_BAD_REQUEST,
@@ -2714,7 +2823,8 @@
           connection->state = MHD_CONNECTION_FOOTER_PART_RECEIVED;
           continue;
         case MHD_CONNECTION_FOOTER_PART_RECEIVED:
-          line = get_next_header_line (connection, NULL);
+          line = get_next_header_line (connection,
+                                       NULL);
           if (NULL == line)
             {
               if (connection->state != MHD_CONNECTION_FOOTER_PART_RECEIVED)
@@ -2750,7 +2860,7 @@
             {
               /* oops - close! */
              CONNECTION_CLOSE_ERROR (connection,
-                                     "Closing connection (failed to create 
response header)\n");
+                                     _("Closing connection (failed to create 
response header)\n"));
               continue;
             }
           connection->state = MHD_CONNECTION_HEADERS_SENDING;
@@ -2852,7 +2962,7 @@
             {
               /* oops - close! */
              CONNECTION_CLOSE_ERROR (connection,
-                                     "Closing connection (failed to create 
response header)\n");
+                                     _("Closing connection (failed to create 
response header)\n"));
               continue;
             }
           if ( (MHD_NO == connection->have_chunked_upload) ||
@@ -2874,7 +2984,9 @@
           end =
             MHD_get_response_header (connection->response,
                                     MHD_HTTP_HEADER_CONNECTION);
-          client_close = ((NULL != end) && (MHD_str_equal_caseless_(end, 
"close")));
+          client_close = ( (NULL != end) &&
+                           (MHD_str_equal_caseless_(end,
+                                                    "close")));
           MHD_destroy_response (connection->response);
           connection->response = NULL;
           if ( (NULL != daemon->notify_completed) &&
@@ -2893,7 +3005,8 @@
           if ( (MHD_YES == connection->read_closed) ||
                (client_close) ||
                ( (NULL != end) &&
-                (MHD_str_equal_caseless_ (end, "close")) ) )
+                (MHD_str_equal_caseless_ (end,
+                                           "close")) ) )
             {
               connection->read_closed = MHD_YES;
               connection->read_buffer_offset = 0;
@@ -3051,7 +3164,7 @@
 #ifdef HAVE_MESSAGES
          if (0 != (daemon->options & MHD_USE_DEBUG))
            MHD_DLOG (daemon,
-                     "Call to epoll_ctl failed: %s\n",
+                     _("Call to epoll_ctl failed: %s\n"),
                      MHD_socket_last_strerr_ ());
 #endif
          connection->state = MHD_CONNECTION_CLOSED;
@@ -3162,7 +3275,8 @@
                           connection);
         }
       va_start (ap, option);
-      connection->connection_timeout = va_arg (ap, unsigned int);
+      connection->connection_timeout = va_arg (ap,
+                                               unsigned int);
       va_end (ap);
       if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
           (MHD_YES != connection->suspended) )

Modified: libmicrohttpd/src/microhttpd/internal.h
===================================================================
--- libmicrohttpd/src/microhttpd/internal.h     2016-09-05 12:15:43 UTC (rev 
37887)
+++ libmicrohttpd/src/microhttpd/internal.h     2016-09-05 12:43:45 UTC (rev 
37888)
@@ -226,8 +226,7 @@
   struct MHD_HTTP_Header *next;
 
   /**
-   * The name of the header (key), without
-   * the colon.
+   * The name of the header (key), without the colon.
    */
   char *header;
 
@@ -237,8 +236,8 @@
   char *value;
 
   /**
-   * Type of the header (where in the HTTP
-   * protocol is this header from).
+   * Type of the header (where in the HTTP protocol is this header
+   * from).
    */
   enum MHD_ValueKind kind;
 




reply via email to

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