OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gsPlatformUtil.h
1
3#ifndef __GSUTILITY_H__
4#define __GSUTILITY_H__
5
6
7#include "gsPlatform.h"
8
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14
17// Async DNS lookup
18
19// async way to resolve a hostname to an IP
20typedef struct GSIResolveHostnameInfo * GSIResolveHostnameHandle;
21#define GSI_STILL_RESOLVING_HOSTNAME 0
22#define GSI_ERROR_RESOLVING_HOSTNAME 0xFFFFFFFF
23
24// start resolving a hostname
25// returns 0 on success, -1 on error
26int gsiStartResolvingHostname(const char * hostname, GSIResolveHostnameHandle * handle);
27// cancel a resolve in progress
28void gsiCancelResolvingHostname(GSIResolveHostnameHandle handle);
29// returns GSI_STILL_RESOLVING if still resolving the hostname
30// returns GSI_ERROR_RESOLVING if it was unable to resolve the hostname
31// on success, returns the IP of the host in network byte order
32unsigned int gsiGetResolvedIP(GSIResolveHostnameHandle handle);
33
34
37// Get rid of compiler warnings when parameters are never used
38// (Mainly used in sample apps and callback for platform switches)
39#if (defined(__MWERKS__) && !defined(_NITRO)) || defined(WIN32)
40 #define GSI_UNUSED(x) x
41#elif defined(_PS2) || defined(_NITRO) || defined(_PS3) || defined(_MACOSX)
42 #define GSI_UNUSED(x) {void* y=&x;y=NULL;}
43#elif defined(_PSP)
44#define GSI_UNUSED(x) (void)x;
45
46#else
47 #define GSI_UNUSED(x)
48#endif
49
50
53// Cross platform random number generator
54void Util_RandSeed(unsigned long seed); // to seed it
55int Util_RandInt(int low, int high); // retrieve a random int
56
57
60// Base 64 encoding (printable characters)
61void B64Encode(const char *input, char *output, int inlen, int encodingType);
62void B64Decode(const char *input, char *output, int inlen, int * outlen, int encodingType);
63
64// returns the length of the binary data represented by the base64 input string
65int B64DecodeLen(const char *input, int encodingType);
66
67typedef struct
68{
69 const char *input;
70 int len;
71 int encodingType;
73
74void B64InitEncodeStream(B64StreamData *data, const char *input, int len, int encodingType);
75
76// returns gsi_false if the stream has ended
77gsi_bool B64EncodeStream(B64StreamData *data, char output[4]);
78
79
82#define XXTEA_KEY_SIZE 17
83gsi_i8 * gsXxteaEncrypt(const gsi_i8 * iStr, gsi_i32 iLength, gsi_i8 key[XXTEA_KEY_SIZE], gsi_i32 *oLength);
84gsi_i8 * gsXxteaDecrypt(const gsi_i8 * iStr, gsi_i32 iLength, gsi_i8 key[XXTEA_KEY_SIZE], gsi_i32 *oLength);
85
86#ifndef max
87#define max(a,b) (((a) > (b)) ? (a) : (b))
88#define min(a,b) (((a) < (b)) ? (a) : (b))
89#endif
90
91#if defined(_DEBUG)
92 void gsiCheckStack(void);
93#else
94 #define gsiCheckStack()
95#endif
96
97
100// time functions
101
102gsi_time current_time(); // milliseconds
103gsi_time current_time_hires(); // microseconds
104void msleep(gsi_time msec); // milliseconds
105
106// GSI equivalent of common C-lib time functions
107struct tm * gsiSecondsToDate(const time_t *timp); //gmtime
108time_t gsiDateToSeconds(struct tm *tb); //mktime
109char * gsiSecondsToString(const time_t *timp); //ctime
110
111
114// Misc utilities
115
116
117#if defined(_NITRO)
118 time_t time(time_t *timer);
119
120 #define gmtime(t) gsiSecondsToDate(t)
121 #define ctime(t) gsiSecondsToString(t)
122 #define mktime(t) gsiDateToSeconds(t)
123#elif defined(_REVOLUTION)
124 time_t gsiTimeInSec(time_t *timer);
125 struct tm *gsiGetGmTime(time_t *theTime);
126 char *gsiCTime(time_t *theTime);
127 #define time(t) gsiTimeInSec(t)
128 #define gmtime(t) gsiGetGmTime(t)
129 #define ctime(t) gsiCTime(t)
130#else
131 #include <time.h>
132#endif
133
134
135 #ifndef SOMAXCONN
136 #define SOMAXCONN 5
137#endif
138
139typedef const char * (* GetUniqueIDFunction)();
140
141extern GetUniqueIDFunction GOAGetUniqueID;
142
143// Prototypes so the compiler won't warn
144#ifdef _PS2
145extern int wprintf(const wchar_t*,...);
146#endif
147
148
149// 64-bit Integer reads and writes
150gsi_i64 gsiStringToInt64(const char *theNumberStr);
151void gsiInt64ToString(char theNumberStr[33], gsi_i64 theNumber);
154#ifdef __cplusplus
155}
156#endif
157
158#endif //__GSUTILITY_H__
159
Definition gsPlatformUtil.h:68
Definition gsPlatformUtil.c:43