mirror of
https://github.com/bdnugget/kcgi.git
synced 2026-11-07 05:47:27 +00:00
Use style(9) and pkg-config.
This commit is contained in:
1 parent
820775d86c
commit
2c7da2eff5
3 files changed
+26
-28
No files matched your search
+2
-2
@@ -51,7 +51,7 @@ kvalid_png(struct kpair *kp)
|
||||
gdImagePtr im;
|
||||
int rc;
|
||||
im = gdImageCreateFromPngPtr(kp->valsz, kp->val);
|
||||
if (0 != (rc = (NULL != im)))
|
||||
if ((rc = (im != NULL)))
|
||||
gdImageDestroy(im);
|
||||
kp->type = KPAIR__MAX;
|
||||
return rc;
|
||||
@@ -63,7 +63,7 @@ kvalid_jpeg(struct kpair *kp)
|
||||
gdImagePtr im;
|
||||
int rc;
|
||||
im = gdImageCreateFromJpegPtr(kp->valsz, kp->val);
|
||||
if (0 != (rc = (NULL != im)))
|
||||
if ((rc = (im != NULL)))
|
||||
gdImageDestroy(im);
|
||||
kp->type = KPAIR__MAX;
|
||||
return rc;
|
||||
|
||||
+6
-8
@@ -47,14 +47,14 @@
|
||||
<figure class="sample">
|
||||
<pre class="prettyprint linenums">int
|
||||
main(void) {
|
||||
enum kcgi_err er;
|
||||
struct kreq r;
|
||||
enum kcgi_err er;
|
||||
struct kreq r;
|
||||
const char *const pages[1] = { "index" };
|
||||
|
||||
/* Set up our main HTTP context. */
|
||||
|
||||
er = khttp_parse(&r, NULL, 0, pages, 1, 0);
|
||||
if (KCGI_OK != er)
|
||||
if (er != KCGI_OK)
|
||||
return 0;
|
||||
khttp_head(&r, kresps[KRESP_STATUS],
|
||||
"%s", khttps[KHTTP_200]);
|
||||
@@ -72,19 +72,17 @@ main(void) {
|
||||
The difference is that we've used some C++ code to emit <q>Said hello!</q> to the error log.
|
||||
The next part is how we can compile this code.
|
||||
For that, we'll need to use a C++ compiler instead of the C compiler we've been using to date.
|
||||
For the sake of argument, let's assume that the <span class="nm">kcgi</span> headers are libraries are installed in the system directories.
|
||||
However, mostly they'll need <code>-L/usr/local/lib</code> and <code>-I/usr/local/include</code>.
|
||||
</p>
|
||||
<figure class="sample">
|
||||
<pre class="prettyprint lang-sh linenums">% c++ -W -Wall -Wextra -c -o tutorial5.o tutorial5.cc
|
||||
% c++ -static -W -Wall -Wextra -o tutorial5 tutorial5.cc -lkcgi -lz</pre>
|
||||
<pre class="prettyprint lang-sh linenums">% c++ `pkg-config --cflags kcgi` -c -o tutorial5.o tutorial5.cc
|
||||
% c++ -static -o tutorial5 tutorial5.cc `pkg-config --libs kcgi`</pre>
|
||||
</figure>
|
||||
<p>
|
||||
Or just…
|
||||
(and noting again the <code>-static</code>, which we need by being in our file-system jail)
|
||||
</p>
|
||||
<figure class="sample">
|
||||
<pre class="prettyprint lang-sh linenums">% c++ -static -W -Wall -Wextra -o tutorial5 tutorial5.cc -lkcgi -lz</pre>
|
||||
<pre class="prettyprint lang-sh linenums">% c++ -static `pkg-config --cflags --libs kcgi` -o tutorial5 tutorial5.cc</pre>
|
||||
</figure>
|
||||
<p>
|
||||
Now you can install your compiled CGI script just like any CGI script.
|
||||
|
||||
+18
-18
@@ -68,7 +68,7 @@ main(void) {
|
||||
struct kreq r;
|
||||
const char *const pages[1] = { "index" };
|
||||
|
||||
if (KCGI_OK != khttp_parse(&r, NULL, 0, pages, 1, 0))
|
||||
if (khttp_parse(&r, NULL, 0, pages, 1, 0) != KCGI_OK)
|
||||
return 0;
|
||||
khttp_head(&r, kresps[KRESP_STATUS],
|
||||
"%s", khttps[KHTTP_200]);
|
||||
@@ -94,9 +94,9 @@ main(void) {
|
||||
We'll start with the most significant protection: by constraining our application after the context has been parsed.
|
||||
</p>
|
||||
<figure class="sample">
|
||||
<pre class="prettyprint linenums">if (KCGI_OK != khttp_parse(&r, NULL, 0, pages, 1, 0))
|
||||
<pre class="prettyprint linenums">if (khttp_parse(&r, NULL, 0, pages, 1, 0) != KCGI_OK)
|
||||
return 0;
|
||||
if (-1 == pledge("stdio", NULL))
|
||||
if (pledge("stdio", NULL) == -1)
|
||||
return 0;</pre>
|
||||
</figure>
|
||||
<p>
|
||||
@@ -113,22 +113,22 @@ if (-1 == pledge("stdio", NULL))
|
||||
href="https://man.openbsd.org/fork.2">fork(2)</a> its internal handlers.
|
||||
</p>
|
||||
<figure class="sample">
|
||||
<pre class="prettyprint linenums">if (-1 == pledge("stdio proc", NULL))
|
||||
<pre class="prettyprint linenums">if (pledge("stdio proc", NULL) == -1)
|
||||
return 0;
|
||||
if (KCGI_OK != khttp_parse(&r, NULL, 0, pages, 1, 0))
|
||||
if (khttp_parse(&r, NULL, 0, pages, 1, 0) != KCGI_OK)
|
||||
return 0;
|
||||
if (-1 == pledge("stdio", NULL))
|
||||
if (pledge("stdio", NULL) == -1)
|
||||
return 0;</pre>
|
||||
</figure>
|
||||
<p>
|
||||
Or if one is using <a href="khttp_template.3.html">khttp_template(3)</a> to marshall a response:
|
||||
</p>
|
||||
<figure class="sample">
|
||||
<pre class="prettyprint linenums">if (-1 == pledge("stdio rpath proc", NULL))
|
||||
<pre class="prettyprint linenums">if (pledge("stdio rpath proc", NULL) == -1)
|
||||
return 0;
|
||||
if (KCGI_OK != khttp_parse(&r, NULL, 0, pages, 1, 0))
|
||||
if (khttp_parse(&r, NULL, 0, pages, 1, 0) != KCGI_OK)
|
||||
return 0;
|
||||
if (-1 == pledge("stdio rpath", NULL))
|
||||
if (pledge("stdio rpath", NULL) == -1)
|
||||
return 0;</pre>
|
||||
</figure>
|
||||
<p>
|
||||
@@ -149,11 +149,11 @@ main(void) {
|
||||
struct kreq r;
|
||||
const char *const pages[1] = { "index" };
|
||||
|
||||
if (-1 == pledge("stdio proc", NULL))
|
||||
if (pledge("stdio proc", NULL) == -1)
|
||||
return 0;
|
||||
if (KCGI_OK != khttp_parse(&r, NULL, 0, pages, 1, 0))
|
||||
if (khttp_parse(&r, NULL, 0, pages, 1, 0) != KCGI_OK)
|
||||
return 0;
|
||||
if (-1 == pledge("stdio", NULL))
|
||||
if (pledge("stdio", NULL) == -1)
|
||||
return 0;
|
||||
khttp_head(&r, kresps[KRESP_STATUS],
|
||||
"%s", khttps[KHTTP_200]);
|
||||
@@ -189,10 +189,10 @@ main(void) {
|
||||
struct kfcgi *fcgi;
|
||||
enum kcgi_err er;
|
||||
|
||||
if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, pages, 1, 0))
|
||||
if (khttp_fcgi_init(&fcgi, NULL, 0, pages, 1, 0) != KCGI_OK)
|
||||
return 0;
|
||||
for (;;) {
|
||||
if (KCGI_OK != khttp_fcgi_parse(fcgi, &req))
|
||||
if (khttp_fcgi_parse(fcgi, &req) != KCGI_OK)
|
||||
break;
|
||||
khttp_head(&r, kresps[KRESP_STATUS],
|
||||
"%s", khttps[KHTTP_200]);
|
||||
@@ -220,14 +220,14 @@ main(void) {
|
||||
struct kfcgi *fcgi;
|
||||
enum kcgi_err er;
|
||||
|
||||
if (-1 == pledge("unix sendfd recvfd proc stdio", NULL))
|
||||
if (pledge("unix sendfd recvfd proc stdio", NULL) == -1)
|
||||
return 0;
|
||||
if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, pages, 1, 0))
|
||||
if (khttp_fcgi_init(&fcgi, NULL, 0, pages, 1, 0) != KCGI_OK)
|
||||
return 0;
|
||||
if (-1 == pledge("stdio recvfd", NULL))
|
||||
if (pledge("stdio recvfd", NULL) == -1)
|
||||
return 0;
|
||||
for (;;) {
|
||||
if (KCGI_OK != khttp_fcgi_parse(fcgi, &req))
|
||||
if (khttp_fcgi_parse(fcgi, &req) != KCGI_OK)
|
||||
break;
|
||||
khttp_head(&r, kresps[KRESP_STATUS],
|
||||
"%s", khttps[KHTTP_200]);
|
||||
|
||||
Reference in new issue
Block a user