]> arthur.barton.de Git - netdata.git/blobdiff - src/web_client.c
Merge remote-tracking branch 'fredericopissarra/changes' into registry
[netdata.git] / src / web_client.c
index 6e2e639c145c6478e6aa6f8c7e53c4d88ba60f64..f1e368ff6923337ef38f1ccb806b9645f0db7847 100644 (file)
@@ -73,8 +73,8 @@ struct web_client *web_client_create(int listener)
 
                if(getnameinfo(sadr, addrlen, w->client_ip, NI_MAXHOST, w->client_port, NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
                        error("Cannot getnameinfo() on received client connection.");
-                       strncpy(w->client_ip,   "UNKNOWN", NI_MAXHOST);
-                       strncpy(w->client_port, "UNKNOWN", NI_MAXSERV);
+                       strncpyz(w->client_ip,   "UNKNOWN", NI_MAXHOST);
+                       strncpyz(w->client_port, "UNKNOWN", NI_MAXSERV);
                }
                w->client_ip[NI_MAXHOST]   = '\0';
                w->client_port[NI_MAXSERV] = '\0';
@@ -327,7 +327,7 @@ int mysendfile(struct web_client *w, char *filename)
 
        // access the file
        char webfilename[FILENAME_MAX + 1];
-       snprintf(webfilename, FILENAME_MAX, "%s/%s", web_dir, filename);
+       snprintfz(webfilename, FILENAME_MAX, "%s/%s", web_dir, filename);
 
        // check if the file exists
        struct stat stat;
@@ -352,7 +352,7 @@ int mysendfile(struct web_client *w, char *filename)
        }
 
        if((stat.st_mode & S_IFMT) == S_IFDIR) {
-               snprintf(webfilename, FILENAME_MAX+1, "%s/index.html", filename);
+               snprintfz(webfilename, FILENAME_MAX, "%s/index.html", filename);
                return mysendfile(w, webfilename);
        }
 
@@ -1332,6 +1332,7 @@ void web_client_process(struct web_client *w) {
 
                debug(D_WEB_CLIENT_ACCESS, "%llu: Cannot understand '%s'.", w->id, w->response.data->buffer);
 
+<<<<<<< HEAD
                code = 500;
                buffer_flush(w->response.data);
                buffer_strcat(w->response.data, "I don't understand you...\r\n");
@@ -1342,6 +1343,10 @@ void web_client_process(struct web_client *w) {
                global_statistics_lock();
                global_statistics.web_requests++;
                global_statistics_unlock();
+=======
+               if(w->mode == WEB_CLIENT_MODE_OPTIONS) {
+                       strncpyz(w->last_url, url, URL_MAX);
+>>>>>>> fredericopissarra/changes
 
                // copy the URL - we are going to overwrite parts of it
                // FIXME -- we should avoid it
@@ -1360,8 +1365,14 @@ void web_client_process(struct web_client *w) {
                                web_client_enable_deflate(w);
 #endif
 
+<<<<<<< HEAD
                        char *url = w->decoded_url;
                        char *tok = mystrsep(&url, "/?");
+=======
+                       strncpyz(w->last_url, url, URL_MAX);
+
+                       tok = mystrsep(&url, "/?");
+>>>>>>> fredericopissarra/changes
                        if(tok && *tok) {
                                debug(D_WEB_CLIENT, "%llu: Processing command '%s'.", w->id, tok);
 
@@ -1469,7 +1480,7 @@ void web_client_process(struct web_client *w) {
                                                else {
                                                        code = 200;
                                                        debug_flags |= D_RRD_STATS;
-                                                       st->debug = st->debug?0:1;
+                                                       st->debug = !st->debug;
                                                        buffer_sprintf(w->response.data, "Chart %s has now debug %s.\r\n", tok, st->debug?"enabled":"disabled");
                                                        debug(D_WEB_CLIENT_ACCESS, "%llu: debug for %s is %s.", w->id, tok, st->debug?"enabled":"disabled");
                                                }
@@ -1495,8 +1506,7 @@ void web_client_process(struct web_client *w) {
                                else {
                                        char filename[FILENAME_MAX+1];
                                        url = filename;
-                                       strncpy(filename, w->last_url, FILENAME_MAX);
-                                       filename[FILENAME_MAX] = '\0';
+                                       strncpyz(filename, w->last_url, FILENAME_MAX);
                                        tok = mystrsep(&url, "?");
                                        buffer_flush(w->response.data);
                                        code = mysendfile(w, (tok && *tok)?tok:"/");
@@ -1505,8 +1515,7 @@ void web_client_process(struct web_client *w) {
                        else {
                                char filename[FILENAME_MAX+1];
                                url = filename;
-                               strncpy(filename, w->last_url, FILENAME_MAX);
-                               filename[FILENAME_MAX] = '\0';
+                               strncpyz(filename, w->last_url, FILENAME_MAX);
                                tok = mystrsep(&url, "?");
                                buffer_flush(w->response.data);
                                code = mysendfile(w, (tok && *tok)?tok:"/");