SpriteHTTPD - embedded HTTP server with read-only filesystem and templating, originally developed for ESP8266, now stand-alone and POSIX compatible.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
spritehttpd/spritehttpd/include/cgi-espfs.h

66 lines
1.7 KiB

#pragma once
#include <string.h>
#include "httpd-types.h"
#define HTTPD_ESPFS_TOKEN_LEN 64
typedef struct TplData {
/// Connection. Is set to NULL during final clean-up
HttpdConnData *conn;
/// Currently parsed token. Cleared during clean-up
const char *token;
/// Pointer to arbitrary user data that should be freed/cleaned up
/// during clean-up
void *userData;
} TplData;
/**
* The template substitution callback.
*
* Returns CGI_MORE if more should be sent within the token, CGI_DONE otherwise.
*
* The td.userData pointer can be used to attach arbitrary data to the request.
* If connData is NULL (and token empty), we are doing cleanup - free td.userData, if needed.
*/
typedef httpd_cgi_state (* TplCallback)(TplData *td);
/**
* Serve a static file from EspFs. The file name is in the first CGI arg. If NULL, the URI is used as a file name.
*
* @param connData
* @return CGI state
*/
httpd_cgi_state cgiEspFsStaticFile(HttpdConnData *connData);
/**
* Serve a template from EspFs.
*
* - The first arg is the TplCallback replacer function.
* - The second arg is the file name, if given, otherwise the URI is used as a file name
*
* @param conn
* @return CGI state
*/
httpd_cgi_state cgiEspFsTemplate(HttpdConnData *conn);
/**
* Send template substitution string with known len
*
* @param td - template data
* @param str - string to send
* @param len - string len
* @return 1 = OK
*/
int tplSendN(TplData *td, const char *str, int len);
/**
* Send template substitution string (use strlen)
*
* @param tpd - template data
* @param str - string to send
* @return 1 = OK
*/
static inline int tplSend(TplData *tpd, const char *str) {
return tplSendN(tpd, str, strlen(str));
}