aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-07-13 08:33:09 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-07-13 08:33:09 +0300
commit2aabe59373c29410c00ae59cd86cb475c961b56c (patch)
tree43063644a70dee80276cc65b8a0509c154c22473
parentc452c3dc47bacf1cb4dfd7a8129d62fa8819282e (diff)
downloadmagi-2aabe59373c29410c00ae59cd86cb475c961b56c.tar
magi-2aabe59373c29410c00ae59cd86cb475c961b56c.tar.xz
magi-2aabe59373c29410c00ae59cd86cb475c961b56c.zip
magi_response_send, urlenc docs.
-rw-r--r--examples/cookie.c3
-rw-r--r--include/magi/response.h4
-rw-r--r--include/magi/urlenc.h2
-rw-r--r--man/magi.316
-rw-r--r--man/magi_urlenc.351
-rw-r--r--src/response.c6
6 files changed, 75 insertions, 7 deletions
diff --git a/examples/cookie.c b/examples/cookie.c
index c64ca0c..7cb5f33 100644
--- a/examples/cookie.c
+++ b/examples/cookie.c
@@ -22,7 +22,8 @@ void response(magi_request *r)
magi_response_init(&head); /* Setting defaults. */
/* Set cookie "cookie" with value "monster" on clientside: */
magi_response_cookie(&head, "cookie", "monster");
- magi_response_free(&head); /* Send headers and start sending body: */
+ magi_response_send(&head); /* Send headers, */
+ magi_response_free(&head); /* free them and start sending body: */
printf("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' "
"'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>"
"<html xmlns='http://www.w3.org/1999/xhtml'>"
diff --git a/include/magi/response.h b/include/magi/response.h
index 9364fd4..4867c2f 100644
--- a/include/magi/response.h
+++ b/include/magi/response.h
@@ -23,7 +23,9 @@ typedef struct magi_response {
/* Response initialiser, setup defaults. */
void magi_response_init(magi_response *r);
-/* Send response headers and free memory used by it. */
+/* Send response headers. */
+void magi_response_send(magi_response *r);
+/* Free memory used by response headers. */
void magi_response_free(magi_response *r);
/* Just response defaults. (text/html, 200 Ok) */
diff --git a/include/magi/urlenc.h b/include/magi/urlenc.h
index 1b629f9..16310f2 100644
--- a/include/magi/urlenc.h
+++ b/include/magi/urlenc.h
@@ -7,7 +7,7 @@
* will be.
*
* RFC 3986 describes URL-encoding. Briefly it is changing every space into
- * plus sign and every not alpha-numerical and not @c "~-._" character into
+ * plus sign and every not alpha-numerical and not "~-._" character into
* percent sign followed by hexadecimal representation of given character.
*/
diff --git a/man/magi.3 b/man/magi.3
index fcf6679..2db61b4 100644
--- a/man/magi.3
+++ b/man/magi.3
@@ -23,12 +23,22 @@ Main task of the
library is to analyse CGI request and represent it to the user in
.B magi_request
data structure. This is done by calling
-.B magi_parse
+.B magi_parse_head
+and
+.B magi_parse_body
+(such separation allows to determine body processing on head content,
+if there is no need to do so you can use shortcut
+.BR magi_parse )
on initialized via
.B magi_request_init
request variable. After initialization the user is able to configure
-limits on the input and setup callback to process files loaded as
-.IR multipart/form-data .
+limits on the input
+.RB ( magi_request_limits ,
+everything is unlimited as default)
+and setup callback to process files loaded as
+.I multipart/form-data
+.RB ( magi_file_callback ,
+with default addon_max of 1KB).
The
.B magi
library comes with
diff --git a/man/magi_urlenc.3 b/man/magi_urlenc.3
index e69de29..ac0c798 100644
--- a/man/magi_urlenc.3
+++ b/man/magi_urlenc.3
@@ -0,0 +1,51 @@
+.TH MAGI 3 2020-05-02 v0.0.1 "Library Manual"
+.SH NAME
+.B magi_urlenc
+\- implementation of url encoding
+.SH SYNOPSYS
+.B #include <magi.h>
+.P
+int
+.BR magi_urlenc_size "(const char *" plain );
+.P
+void
+.BR magi_urlenc "(const char *" plain ", char *" code );
+.SH DESCRIPTION
+Can be helpful in forming urls in response. Use
+.B magi_urlenc_size
+to find what the size of code will be and then call
+.B magi_urlenc
+for encoding itself.
+.P
+URL encoding is described in
+.IR "RFC 3986" .
+Briefly it is changing every space into plus sign and every not
+alpha-numerical or not one of "~-._" character into percent sign
+followed by hexademical representation of given character byte.
+.P
+.B code
+passed to
+.B magi_urlenc
+should be at least size of
+.BR magi_urlenc_size ( plain ).
+.SH RETURN VALUES
+.BR magi_urlenc_size :
+size of url encoding of
+.BR plain .
+.SH EXAMPLES
+The following forms URL to search in DuckDuckGo for provided
+.RB "char *" query
+in
+.RB "char *" url .
+.P
+.RS
+.nf
+const char *prefix = "http://duckduckgo.com/?q=";
+const int prelen = strlen(prefix);
+const int urlencsize = magi_urlenc_size(query);
+url = malloc(prelen + urlencsize + 1);
+strcpy(url, prefix);
+magi_urlenc(query, url + prelen);
+url[prelen + urlencsize] = 0;
+.fi
+.RE
diff --git a/src/response.c b/src/response.c
index c5b7575..7723e26 100644
--- a/src/response.c
+++ b/src/response.c
@@ -25,12 +25,16 @@ static void response_headers(magi_params *p)
}
}
-void magi_response_free(magi_response *r)
+void magi_response_send(magi_response *r)
{
response_headers(r->head_response);
response_headers(r->head_general);
response_headers(r->head_entity);
fputs("\r\n", stdout);
+}
+
+void magi_response_free(magi_response *r)
+{
magi_params_free(r->head_response);
magi_params_free(r->head_general);
magi_params_free(r->head_entity);