瀏覽代碼

Merge branch 'master' of ssh://github.com/valenok/mongoose

Sergey Lyubka 12 年之前
父節點
當前提交
a730afc44d
共有 2 個文件被更改,包括 13 次插入5 次删除
  1. 1 1
      UserManual.md
  2. 12 4
      mongoose.c

+ 1 - 1
UserManual.md

@@ -103,7 +103,7 @@ will fail.
 Path to an executable to use as CGI interpreter for __all__ CGI scripts
 regardless script extension. If this option is not set (which is a default),
 Mongoose looks at first line of a CGI script,
-[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix)), for an interpreter.
+[shebang line](http://en.wikipedia.org/wiki/Shebang_(Unix\)), for an interpreter.
 
 For example, if both PHP and perl CGIs are used, then
 `#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be first lines of the

+ 12 - 4
mongoose.c

@@ -2415,14 +2415,21 @@ static int parse_auth_header(struct mg_connection *conn, char *buf,
 static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p) {
   char *eof;
   size_t len;
+  char *memend;
 
   if (filep->membuf != NULL && *p != NULL) {
-    eof = (char *) memchr(*p, '\n', &filep->membuf[filep->size] - *p);
-    len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p);
+    memend = (char *) &filep->membuf[filep->size];
+    eof = (char *) memchr(*p, '\n', memend - *p); // Search for \n from p till the end of stream
+    if (eof != NULL) {
+      eof += 1; // Include \n
+    } else {
+      eof = memend; // Copy remaining data
+    }
+    len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p);  
     memcpy(buf, *p, len);
     buf[len] = '\0';
-    *p = eof;
-    return eof;
+    *p += len;
+    return len ? eof : NULL;
   } else if (filep->fp != NULL) {
     return fgets(buf, size, filep->fp);
   } else {
@@ -3272,6 +3279,7 @@ static void prepare_cgi_environment(struct mg_connection *conn,
   addenv(blk, "SERVER_NAME=%s", conn->ctx->config[AUTHENTICATION_DOMAIN]);
   addenv(blk, "SERVER_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]);
   addenv(blk, "DOCUMENT_ROOT=%s", conn->ctx->config[DOCUMENT_ROOT]);
+  addenv(blk, "SERVER_SOFTWARE=%s/%s", "Mongoose", mg_version());
 
   // Prepare the environment block
   addenv(blk, "%s", "GATEWAY_INTERFACE=CGI/1.1");