#include #include #include #include #include #define UNUSED(a) ((void) (a)) static void die( char *test, char *fn, fhp_err_t err ) { char buf[1024]; if (fhp_strerror(err, buf, sizeof(buf)) == FHP_OK) { fprintf(stderr, "ERROR: %s(): %s(): %s\n", test, fn, buf); } else { fprintf(stderr, "ERROR: die(): fhp_strerror() failed\n"); } /* exit app */ exit(EXIT_FAILURE); } static const char * str_test_basic = "GET / HTTP/1.1\r\n" "Host: pablotron.org\r\n" "Connection: close\r\n" "\r\n"; static bool test_basic_cb( fhp_t *fhp, fhp_token_t token, uint8_t * const buf, size_t len ) { fhp_err_t err; UNUSED(fhp); UNUSED(buf); // get token name char token_buf[64]; if ((err = fhp_strtoken(token, token_buf, sizeof(token_buf))) != FHP_OK) return false; // debug fprintf(stderr, "test_basic_cb(): token = %s, len = %lu\n", token_buf, len); // return success return true; } static void test_basic(void) { fhp_err_t err; fhp_t fhp; if ((err = fhp_init(&fhp, test_basic_cb, NULL)) != FHP_OK) { die("test_basic", "fhp_init", err); } size_t len = strlen(str_test_basic); if ((err = fhp_push(&fhp, (uint8_t*) str_test_basic, len)) != FHP_OK) { die("test_basic", "fhp_push", err); } } int main(int argc, char *argv[]) { UNUSED(argc); UNUSED(argv); test_basic(); return EXIT_SUCCESS; }