summaryrefslogtreecommitdiff
path: root/ext/msession/reqclient.h
blob: 5478970a00396a8766840a0eb148833927b3f553 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
   +----------------------------------------------------------------------+
   | msession 1.0                                                         |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2002 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available at through the world-wide-web at                           |
   | http://www.php.net/license/2_02.txt.                                 |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors: Mark Woodward <markw@mohawksoft.com>                        |
   |    Portions copyright the PHP group.                                 |
   +----------------------------------------------------------------------+
 */

enum REQ_TYPES
{
	REQ_ERR,
	REQ_OK,
	REQ_STAT,
	REQ_SETVAL,
	REQ_GETVAL,
	REQ_CREATE,
	REQ_DROP,
	REQ_GETALL,
	REQ_FIND,
	REQ_COUNT,
	REQ_FLUSH,
	REQ_SLOCK,
	REQ_SUNLOCK,
	REQ_TIMEOUT,
	REQ_INC,
	REQ_DATAGET,
	REQ_DATASET,
	REQ_LIST,
	REQ_LISTVAR,
	REQ_UNIQ,
	REQ_RANDSTR,
	REQ_PLUGIN,
	REQ_LAST,
	REQ_POPEN=1024,
	REQ_PCLOSE
};

typedef struct _requestPacket
{
	int	version;
	int	stat;
	int	len;
	int	session;
	int	name;
	int	value;
	int 	param;
	char	datum[0];
}REQ;

typedef struct _requestBuf
{
	unsigned int type;
	unsigned int size;
	REQ	req;
}REQB;

#define MAX_REQ		16384

#define REQB_STATIC	1
#define REQB_DYNAMIC	2

#define STATIC_REQB( len )	\
	char buffer [ len ]; 	\
	REQB *preq = StaticRequestBuffer(buffer, len);

#if defined (__cplusplus)
extern "C" {
#endif

#define SIZEREQB(REQB,SIZE) (((REQB)->size >= (unsigned int) SIZE) ? REQB : SizeRequestBuffer(REQB,SIZE))
REQB *AllocateRequestBuffer(unsigned size);
void FreeRequestBuffer(REQB *req);
REQB *SizeRequestBuffer(REQB *req, unsigned int size);
REQB *StaticRequestBuffer(char *buffer, unsigned int cb);

int FormatRequest(REQB **buffer, int stat, const char *session, const char *name, const char *value, int param);
int FormatRequestMulti(REQB **buffer, int stat, char *session, int n, char **pairs, int param);
int DoSingleRequest(char *hostname, int port, REQB **preq);
void *OpenReqConn(char *hostname, int port);
void CloseReqConn(void *conn);
int DoRequest(void *conn, REQB **preq);
char *ReqErr(int param);

#define ASSERT_STAT(PREQ) if(PREQ->stat != REQ_OK) \
	{fprintf(stderr, "Error in Request %s %d %s\n", \
		__FILE__,__LINE__, ReqErr(PREQ->param)); exit(-1); }

#if defined (__cplusplus)
	// C API but with class definitions
	int ReadRequestTimeout(REQB **ppreq, MSock *sock, int timeout);
	int ReadRequest(REQB **preq, MSock *sock);
	int WriteRequest(REQB *preq, MSock *sock);
}
#endif