-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpd.h
64 lines (49 loc) · 1.52 KB
/
httpd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* httpd.h
*
* Copyright (C) 2018 < Daniel Finneran, dan@thebsdbox.co.uk >
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the GPL license. See the LICENSE file for details.
*/
#include <stddef.h>
typedef struct {
// RFC requestLine
char *method;
char *URI;
char *HTTPVersion;
// Helper lines
char *requestLine; // Status Line (GET/POST) etc.
char *headers; // Headers
char *messageBody; // The remaining part (messageBody) of the httpResponse
} httpRequest;
typedef struct {
// Helper lines
int responseCode; // Response to a request
size_t messageLength; // Size of the reponse message for Content Length response
char *messageBody; // The response message
} httpResponse;
#define BUFFER_SIZE 1024*1024
//#define MAX_FILE_SIZE 5*1024
//#define TRUE 1
//#define FALSE 0
//#define EXIT_SUCCESS 0
//#define EXIT_FAILURE 1
//
//#define OV_HTTPD_GET 1
//#define OV_HTTPD_HEAD 2
//#define OV_HTTPD_POST 3
void startListenLoop(void);
httpRequest *processHttpRequest(char *rawData);
void setPort(size_t port);
void setContentType(char *type);
int setHTTPResponse(char *messageBody, int responseCode);
void createINETSocket(void);
void bindToINETSocketWithPort(void);
void startListener(void);
void acceptConnection(void);
#ifndef HTTPDCALLBACK_H
#define HTTPDCALLBACK_H
void SetPostFunction( char *(*postCallbackFunction)(httpRequest *));
void SetGetFunction( char *(*postCallbackFunction)(httpRequest *));
#endif