vitalnix user management suite 3.2.0


Description

The libvxcgi library provides functions commonly used in CGI environments.

Function overview

#include <vitalnix/libvxcgi/libvxcgi.h>

int vxcgi_authenticate(const char *user, const char *password);
char *vxcgi_read_data(int argc, const char **argv);
struct HXbtree *vxcgi_split(char *str);

vxcgi_authenticate

Authenticate the user using the given password. Returns an AEE code, carrying the PAM error code as a negative return value. (E.g. -7 for PAM_AUTH_ERR and -10 for PAM_USER_UNKNOWN.)

vxcgi_read_data

Returns the CGI POST data, or in case of a GET query, the query string. If called from the command-line, that is, if getenv("REQUEST_METHOD") == NULL, a copy of argv[1] is returned, which is assumed to be in application/x-www-form-urlencoded encoding. Note that the returned string is allocated and therefore must be freed at a later time.

If you do not intend to pass any argc/argv, call vxcgi_read_data with (0, NULL).

vxcgi_split

Splits the string according to application/x-www-form-urlencoded rules and returns the key-value pairs in a struct HXbtree. The string must be writable, as it will be modified and freed. The caller should preferably duplicate it beforehand.

Example

Here is how to quickly get a HXbtree out of the query string:

struct HXbtree *data = vxcgi_split(vxcgi_read_data(argc, argv));

and to get the "user" parameter if the query string:

char *u = HXbtree_get(data, "user");