RIP BOOL. Convert BOOL -> bool. I found a few interesting
[nivanova/samba-autobuild/.git] / source3 / web / cgi.c
index d1cd38eb512321e2d7a5e1ba6a74b24b7e7e9963..6a8688b637613b58659e513c04605d1f5381bda0 100644 (file)
@@ -4,7 +4,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 
@@ -43,8 +42,8 @@ static char *query_string;
 static const char *baseurl;
 static char *pathinfo;
 static char *C_user;
-static BOOL inetd_server;
-static BOOL got_request;
+static bool inetd_server;
+static bool got_request;
 
 static char *grab_line(FILE *f, int *cl)
 {
@@ -59,7 +58,7 @@ static char *grab_line(FILE *f, int *cl)
                        char *ret2;
                        if (len == 0) len = 1024;
                        else len *= 2;
-                       ret2 = (char *)SMB_REALLOC(ret, len);
+                       ret2 = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR(ret, len);
                        if (!ret2) return ret;
                        ret = ret2;
                }
@@ -80,8 +79,9 @@ static char *grab_line(FILE *f, int *cl)
 
        }
        
-
-       ret[i] = 0;
+       if (ret) {
+               ret[i] = 0;
+       }
        return ret;
 }
 
@@ -223,6 +223,7 @@ void cgi_load_variables(void)
   browser. Also doesn't allow for variables[] containing multiple variables
   with the same name and the same or different values.
   ***************************************************************************/
+
 const char *cgi_variable(const char *name)
 {
        int i;
@@ -233,6 +234,20 @@ const char *cgi_variable(const char *name)
        return NULL;
 }
 
+/***************************************************************************
+ Version of the above that can't return a NULL pointer.
+***************************************************************************/
+
+const char *cgi_variable_nonull(const char *name)
+{
+       const char *var = cgi_variable(name);
+       if (var) {
+               return var;
+       } else {
+               return "";
+       }
+}
+
 /***************************************************************************
 tell a browser about a fatal error in the http processing
   ***************************************************************************/
@@ -313,7 +328,7 @@ static void cgi_web_auth(void)
 /***************************************************************************
 handle a http authentication line
   ***************************************************************************/
-static BOOL cgi_handle_authorization(char *line)
+static bool cgi_handle_authorization(char *line)
 {
        char *p;
        fstring user, user_pass;
@@ -384,7 +399,7 @@ err:
 /***************************************************************************
 is this root?
   ***************************************************************************/
-BOOL am_root(void)
+bool am_root(void)
 {
        if (geteuid() == 0) {
                return( True);
@@ -494,7 +509,7 @@ static void cgi_download(char *file)
  **/
 void cgi_setup(const char *rootdir, int auth_required)
 {
-       BOOL authenticated = False;
+       bool authenticated = False;
        char line[1024];
        char *url=NULL;
        char *p;
@@ -618,7 +633,7 @@ const char *cgi_pathinfo(void)
 /***************************************************************************
 return the hostname of the client
   ***************************************************************************/
-char *cgi_remote_host(void)
+const char *cgi_remote_host(void)
 {
        if (inetd_server) {
                return get_peer_name(1,False);
@@ -629,7 +644,7 @@ char *cgi_remote_host(void)
 /***************************************************************************
 return the hostname of the client
   ***************************************************************************/
-char *cgi_remote_addr(void)
+const char *cgi_remote_addr(void)
 {
        if (inetd_server) {
                return get_peer_addr(1);
@@ -641,7 +656,7 @@ char *cgi_remote_addr(void)
 /***************************************************************************
 return True if the request was a POST
   ***************************************************************************/
-BOOL cgi_waspost(void)
+bool cgi_waspost(void)
 {
        if (inetd_server) {
                return request_post;