/* This is the very basic example, showing work with form fields to append * addon specified by user in form into some file (i.e. "file_to_append"). */ #include #include void append(struct magi_request *r) { char *data = magi_request_param(r, "addon"); if (data) { /* If field "addon" was in request: */ FILE *file = fopen("file_to_append", "a"); fputs(data, file); /* Append addon into the file. */ fclose(file); printf("

Appended!

"); /* And display success message. */ } } void response(struct magi_request *r) { magi_response_default(); /* Pass default headers and send body: */ printf("" "" "Append to File" ""); append(r); printf("
" "" "" "
" ""); } int main() { struct magi_request request; magi_request_init(&request); /* Setting defaults. */ if (magi_parse(&request)) { /* If parsing was done successful */ response(&request); /* we need to response the request. */ } else { /* And display error overwise: */ magi_error_response(request.error); } magi_request_free(&request); /* Don't forget to free everything after. */ return 0; }