KHTTP_FCGI_TEST(3) Library Functions Manual KHTTP_FCGI_TEST(3)

khttp_fcgi_testtest whether kcgi is using FastCGI

library “libkcgi”

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>

int
khttp_fcgi_test();

Tests whether the kcgi(3) application is being run under a FastCGI or regular CGI socket. This function may only be run prior to khttp_fcgi_init(3). Afterward, its behaviour is undefined.

The following example starts an application in FastCGI or regular CGI mode depending upon the environment.

int
main(void)
{
  struct kreq	 req;
  struct kfcgi	*fcgi;
  enum kcgi_err	 er;

  if (!khttp_fcgi_test()) {
    er = khttp_parse(&req, NULL, 0, NULL, 0, 0);
    if (er != KCGI_OK)
      err(1, "khttp_parse: %s", kcgi_strerror(er));
    /* Do something. */
    khttp_free(&req);
    return 0;
  }

  er = khttp_fcgi_init(&fcgi, NULL, 0, NULL, 0, 0);
  if (er != KCGI_OK)
    errx(1, "khttp_fcgi_init: %s", kcgi_strerror(er));
  for (;;) {
    er = khttp_fcgi_parse(fcgi, &req);
    if (er != KCGI_OK)
      err(1, "khttp_fcgi_parse: %s", kcgi_strerror(er));
    if (KCGI_EXIT == er) {
      khttp_free(&req);
      break;
    }
    /* Do something. */
    khttp_free(&req);
  }
  khttp_fcgi_free(fcgi);
  return 0;
}

kcgi(3)

Written by Kristaps Dzonsons <kristaps@bsd.lv>.

September 23, 2021 OpenBSD 6.7