-
Notifications
You must be signed in to change notification settings - Fork 0
/
secctp.h
94 lines (74 loc) · 2.35 KB
/
secctp.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef SECCTP_H
#define SECCTP_H
#include <arpa/inet.h>
/* Some useful constants */
#ifndef VERSION
#define VERSION "SecCTP/1.0"
#endif
#ifndef NULL
#define NULL 0
#endif
#define PWD_LENGTH 20
#define UNAME_LENGTH 20
#define MAX_CRED_LENGTH (UNAME_LENGTH+PWD_LENGTH)
#define DEFAULT_CREDS "secctp:pass"
#define AUTH_TAG "Authorization: Basic "
#define TRANS_TAG "Transaction: Payment "
#define AUTH_RETRIES 3
#define DELIM "\r\n" //Message line delimeter for convenience
#define MAX_HEADER_SIZE 1024
//Header constants
#define DATE_FORMAT "Date: %a, %d %b %Y %H:%M:%S %Z\r\n"
#define LANG "Accept-Language: en-gb, en\r\n" //Only accept engligh for now
/* Some macros */
#define phrase(status_code) (((status_code) == SECOK) ? "Ok": \
((status_code) == OTHER) ? "See Other" : \
((status_code) == BAD) ? "Bad Request" : \
((status_code) == UNAUTH) ? "Unauthorized" : \
((status_code) == TIMEOUT) ? "Request Timeout" : \
((status_code) == SERVER_ERR) ? "Internal Server Error" :\
((status_code) == NOT_IMPL) ? "Not Implemented" : "Invalid status code")
#define check_code(status_code) (((status_code) == SECOK) || \
((status_code) == OTHER) || \
((status_code) == BAD) || \
((status_code) == UNAUTH) || \
((status_code) == FORBIDDEN) || \
((status_code) == TIMEOUT) || \
((status_code) == SERVER_ERR) || \
((status_code) == NOT_IMPL) ? 1 : 0 )
#define eos(s) ((s)+strlen(s))
/* Methods */
#define INFO "INFO"
#define GET "GET"
#define POST "POST"
/* Status Codes */
#define SECOK 200 //Renamed to avoid conflict with ncurses.h defined OK
#define OTHER 303
#define BAD 400
#define UNAUTH 401
#define FORBIDDEN 403
#define TIMEOUT 408
#define SERVER_ERR 500
#define NOT_IMPL 501
//Some useful typedefs
typedef enum msgType {HELLO=0,REQ, RESP} msgType;
typedef struct msgContents{
msgType type;
char * headers;
char * body;
char * method;
char * version;
int status;
char * resource;
} msgContents;
typedef struct transaction {
struct in_addr client_addr;
double amount;
} transaction;
//SecCTP helper functions
int generateHello(char *msg, char *method,char *headers, char *body);
int generateReq(char *msg, char *method, char *uri,char *headers, char *body);
int generateResp(char *msg, int status_code,char *headers, char *body);
int parseMessage(msgContents *contents, char *msg);
int authorization(char *headers);
#endif //#ifndef SECCTP_H