-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.h
119 lines (106 loc) · 3.71 KB
/
tools.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//Copyright Anoop Kumar Narayanan <anoop.kumar.narayanan@gmail.com> , LICENSE - GPLv2 / GPLv3
#ifndef HTTP_TOOLS_H
#define HTTP_TOOLS_H
#include <sqlite3.h>
#include <apptypes.h>
//#include <prio.h>
//#include <prlong.h>
//#include <prerror.h>
//#include <prthread.h>
#include <ctime>
using namespace std;
#define CHUNK_HDR_SIZE 8
class ChunkHdr {
public:
unsigned char *start;
unsigned char *clength;
unsigned int rspace;
ChunkHdr() : start ( NULL ), clength ( NULL ), rspace ( SMALLBUF ) {}
~ChunkHdr() {
start = NULL;
clength = NULL;
rspace = 0;
}
void getValues ( unsigned char **s, unsigned char ** c, unsigned int *l ) {
*s = start;
*c = clength;
*l = rspace;
}
void setValues ( unsigned char *s, unsigned char * c, unsigned int l ) {
start = s;
clength = c;
rspace = l;
}
};
class CSVReader {
private:
int cNum;
int pCol;
int offset;
int escape;
char escapeChar;
char cols[32][256];
void ( *readData ) ( char **, int, void * );
void *data;
public:
CSVReader ( int cNum, void ( *readdata ) ( char **, int, void * ), void* data, char eChar );
~CSVReader() {}
int parseData ( char *, int );
};
#define SEND_THREAD_DATA( socket, buffer, length ) \
{ \
unsigned int bytesW = 0; \
int temp; \
do{ \
temp = PR_Send( (socket), (buffer)+bytesW, (length)-bytesW ); \
if( temp > 0 ) \
bytesW += temp; \
else \
{ \
PRErrorCode error = PR_GetError(); \
if( error == PR_WOULD_BLOCK_ERROR ) \
{ \
PR_Sleep(1); \
} \
else \
{ \
bytesW = 0; \
break; \
} \
} \
} \
while( bytesW < (length) ); \
if( bytesW != (length) ) \
{ \
debuglog ( "Error: Unable to send data \n"); \
(length) = -1; \
} else { \
(length) = 0; \
} \
}
char hexCharToHexBin ( char c );
void httpencode ( char *to, char *from, int length );
void httpdecode ( char *to, char *from );
int httpdecodepartial ( char *to, char *from, int len );
int convertHttpDateToNsprDate ( char *date, struct tm * );
const char* convertIndexToWeekDay ( int wdayIndex );
const char* convertIndexToMonth ( int monthIndex );
void convertMd5ToHexMd5 ( char *md5, char *hexmd5 );
void convertRandomsToHex ( char *randoms, char *hex );
int addDate ( char *hdr, const char *field, struct tm &temp );
unsigned int createChunk ( unsigned char *buffer, unsigned int &buflen, unsigned char **start, unsigned char **clength );
void appendChunkData ( unsigned char **start, unsigned int &length, unsigned int &rspace, unsigned char *databuf, unsigned int dlength, unsigned char **incompete );
void appendChunkString ( unsigned char **start, unsigned int &length, unsigned int &rspace, unsigned char *databuf, unsigned char **incompete );
void appendChunkChar ( unsigned char **start, unsigned int &length, unsigned int &rspace, unsigned char data );
void truncateChunk ( unsigned char *clen, unsigned int &len );
void lastChunk ( unsigned char *buf, unsigned int &len );
void readConfigFile ( const char *fileName, const char delim, void ( *callback ) ( char *, char* ) );
int catstring ( char *result, char *data, int &rn );
int mergestring ( char *result, char *buf, char *data, int &, int & );
int mergeremaining ( char *result, char *buf );
#ifdef OS_WIN
char* strtok_r ( char *buf, char *delim, char **restart );
void gmtime_r ( const time_t *date, struct tm *temp );
#endif
int rand_reentrant ( unsigned int *ctx );
#endif