diff --git a/examples/embedded_cpp/embedded_cpp.cpp b/examples/embedded_cpp/embedded_cpp.cpp index 30f7d91a..6bf6ee49 100644 --- a/examples/embedded_cpp/embedded_cpp.cpp +++ b/examples/embedded_cpp/embedded_cpp.cpp @@ -25,18 +25,24 @@ class ExampleHandler : public CivetHandler bool handleGet(CivetServer *server, struct mg_connection *conn) { - mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: " + "text/html\r\nConnection: close\r\n\r\n"); mg_printf(conn, "\r\n"); mg_printf(conn, "

This is an example text from a C++ handler

\r\n"); - mg_printf(conn, "

To see a page from the A handler click here

\r\n"); - mg_printf(conn, "

To see a page from the A handler with a parameter " - "click here

\r\n"); - mg_printf(conn, "

To see a page from the A/B handler click here

\r\n"); - mg_printf(conn, "

To see a page from the *.foo handler click here

\r\n"); + mg_printf(conn, + "

To see a page from the A handler click here

\r\n"); + mg_printf(conn, + "

To see a page from the A handler with a parameter " + "click here

\r\n"); + mg_printf(conn, + "

To see a page from the A/B handler click here

\r\n"); + mg_printf(conn, + "

To see a page from the *.foo handler click here

\r\n"); mg_printf(conn, "

To exit click here

\r\n", EXIT_URI); @@ -51,7 +57,9 @@ class ExitHandler : public CivetHandler bool handleGet(CivetServer *server, struct mg_connection *conn) { - mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\n"); + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: " + "text/plain\r\nConnection: close\r\n\r\n"); mg_printf(conn, "Bye!\n"); exitNow = true; return true; @@ -67,7 +75,9 @@ class AHandler : public CivetHandler struct mg_connection *conn) { std::string s = ""; - mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: " + "text/html\r\nConnection: close\r\n\r\n"); mg_printf(conn, ""); mg_printf(conn, "

This is the A handler for \"%s\" !

", method); if (CivetServer::getParam(conn, "param", s)) { @@ -98,7 +108,9 @@ class ABHandler : public CivetHandler bool handleGet(CivetServer *server, struct mg_connection *conn) { - mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: " + "text/html\r\nConnection: close\r\n\r\n"); mg_printf(conn, ""); mg_printf(conn, "

This is the AB handler!!!

"); mg_printf(conn, "\n"); @@ -115,7 +127,9 @@ class FooHandler : public CivetHandler /* Handler may access the request info using mg_get_request_info */ const struct mg_request_info *req_info = mg_get_request_info(conn); - mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: " + "text/html\r\nConnection: close\r\n\r\n"); mg_printf(conn, "\n"); mg_printf(conn, "

This is the Foo GET handler!!!

\n"); @@ -123,7 +137,7 @@ class FooHandler : public CivetHandler "

The request was:

%s %s HTTP/%s

\n", req_info->request_method, req_info->uri, - req_info->http_version); + req_info->http_version); mg_printf(conn, "\n"); return true; @@ -133,12 +147,14 @@ class FooHandler : public CivetHandler { /* Handler may access the request info using mg_get_request_info */ const struct mg_request_info *req_info = mg_get_request_info(conn); - size_t rlen, wlen; - size_t nlen = 0; - size_t tlen = (size_t)req_info->content_length; - char buf[1024]; + long long rlen, wlen; + long long nlen = 0; + long long tlen = req_info->content_length; + char buf[1024]; - mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: " + "text/html\r\nConnection: close\r\n\r\n"); mg_printf(conn, "\n"); mg_printf(conn, "

This is the Foo POST handler!!!

\n"); @@ -147,20 +163,26 @@ class FooHandler : public CivetHandler req_info->request_method, req_info->uri, req_info->http_version); - mg_printf(conn, "

Content Length: %li

\n", (long)tlen); - mg_printf(conn, "
\n");
+		mg_printf(conn, "

Content Length: %li

\n", (long)tlen); + mg_printf(conn, "
\n");
 
-        while (nlen < tlen) {
-            rlen = tlen - nlen;
-            if (rlen>sizeof(buf)) {rlen=sizeof(buf);}           
-            rlen = mg_read(conn, buf, rlen);
-            if (rlen<=0) break;
-            wlen = mg_write(conn, buf, rlen);
-            if (rlen!=rlen) break;
-            nlen += wlen;
-        }
+		while (nlen < tlen) {
+			rlen = tlen - nlen;
+			if (rlen > sizeof(buf)) {
+				rlen = sizeof(buf);
+			}
+			rlen = mg_read(conn, buf, rlen);
+			if (rlen <= 0) {
+				break;
+			}
+			wlen = mg_write(conn, buf, rlen);
+			if (rlen != rlen) {
+				break;
+			}
+			nlen += wlen;
+		}
 
-        mg_printf(conn, "\n
\n"); + mg_printf(conn, "\n
\n"); mg_printf(conn, "\n"); return true; @@ -170,12 +192,14 @@ class FooHandler : public CivetHandler { /* Handler may access the request info using mg_get_request_info */ const struct mg_request_info *req_info = mg_get_request_info(conn); - size_t rlen, wlen; - size_t nlen = 0; - size_t tlen = (size_t)req_info->content_length; - char buf[1024]; + long long rlen, wlen; + long long nlen = 0; + long long tlen = (size_t)req_info->content_length; + char buf[1024]; - mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n"); + mg_printf(conn, + "HTTP/1.1 200 OK\r\nContent-Type: " + "text/html\r\nConnection: close\r\n\r\n"); mg_printf(conn, "\n"); mg_printf(conn, "

This is the Foo PUT handler!!!

\n"); @@ -184,20 +208,26 @@ class FooHandler : public CivetHandler req_info->request_method, req_info->uri, req_info->http_version); - mg_printf(conn, "

Content Length: %li

\n", (long)tlen); - mg_printf(conn, "
\n");
+		mg_printf(conn, "

Content Length: %li

\n", (long)tlen); + mg_printf(conn, "
\n");
 
-        while (nlen < tlen) {
-            rlen = tlen - nlen;
-            if (rlen>sizeof(buf)) {rlen=sizeof(buf);}           
-            rlen = mg_read(conn, buf, rlen);
-            if (rlen<=0) break;
-            wlen = mg_write(conn, buf, rlen);
-            if (rlen!=rlen) break;
-            nlen += wlen;
-        }
+		while (nlen < tlen) {
+			rlen = tlen - nlen;
+			if (rlen > sizeof(buf)) {
+				rlen = sizeof(buf);
+			}
+			rlen = mg_read(conn, buf, rlen);
+			if (rlen <= 0) {
+				break;
+			}
+			wlen = mg_write(conn, buf, rlen);
+			if (rlen != rlen) {
+				break;
+			}
+			nlen += wlen;
+		}
 
-        mg_printf(conn, "\n
\n"); + mg_printf(conn, "\n
\n"); mg_printf(conn, "\n"); return true;