/****************************************************************************** * * Copyright (c) 2017-2019 by Löwenware Ltd * Please, refer LICENSE file for legal information * ******************************************************************************/ /** * @file hello-world.c * @author Ilja Kartašov * @brief AISL usage example: Hello World * * @see https://lowenware.com/aisl/ */ #include #include /* Include library meta header */ #include #define DEFAULT_HTTP_PORT 8080 /**< Default HTTP server port */ static void hello_world(aisl_evt_t const evt, void * p_ctx) { if (evt->code != AISL_EVENT_STREAM_REQUEST) return; aisl_status_t status; aisl_stream_t s = evt->source; const char html[] = "" "" "Hello World" "" "" "

Hello World

" "

Powered by AISL

" "" ""; status = aisl_response(s, AISL_HTTP_OK, sizeof(html)-1); if (status == AISL_SUCCESS) { if (aisl_write(s, html, sizeof(html)-1) != -1) { aisl_flush(s); } else aisl_reject(s); } (void) p_ctx; } int main(int argc, char ** argv) { aisl_t aisl; /**< AISL instance pointer */ aisl_status_t status; /**< AISL status code */ struct aisl_cfg cfg = AISL_CFG_DEFAULT; struct aisl_cfg_srv srv = { .host = "0.0.0.0", .port = DEFAULT_HTTP_PORT, .secure = false }; cfg.srv = &srv; cfg.srv_cnt = 1; cfg.callback = hello_world; /* Initialize instance */ if ( (aisl = aisl_new(&cfg)) != NULL ) { /* launch application loop */ fprintf(stdout, "Entering main loop" ); for(;;) { status = aisl_run_cycle(aisl); if ( status != AISL_SUCCESS ) aisl_sleep(aisl, 500); } aisl_free(aisl); } else fprintf(stderr, "Failed to initialize AISL"); return 0; }