]> jfr.im git - irc/quakenet/newserv.git/blob - nterface/library.h
*sigh*
[irc/quakenet/newserv.git] / nterface / library.h
1 /*
2 nterface library functions
3 Copyright (C) 2003-2004 Chris Porter.
4 */
5
6 #ifndef __nterface_library_H
7 #define __nterface_library_H
8
9 #include "../core/error.h"
10
11 #define RE_OK 0x00
12 #define RE_MEM_ERROR 0x01
13 #define RE_BAD_LINE 0x02
14 #define RE_REQUEST_REJECTED 0x03
15 #define RE_SERVICE_NOT_FOUND 0x04
16 #define RE_CONNECTION_CLOSED 0x05
17 #define RE_TRANSPORT_NOT_FOUND 0x06
18 #define RE_COMMAND_NOT_FOUND 0x07
19 #define RE_WRONG_ARG_COUNT 0x08
20 #define RE_TOO_MANY_ARGS 0x09
21 #define RE_SERVICER_NOT_FOUND 0x0A
22 #define RE_SOCKET_ERROR 0x0B
23
24 #define snc(err, f) strncpy(err, f, sizeof(err) - 1)
25 #define TwentyByteHex(output, buf) snprintf(output, sizeof(output), "%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], buf[15], buf[16], buf[17], buf[18], buf[19]);
26
27 #define MemError() Error("nterface", ERR_FATAL, "Memory allocation error, file: %s line: %d", __FILE__, __LINE__);
28
29 #define CHALLENGE_ENTROPYLEN 20
30 #define CHALLENGE_ENTROPYBUF 10
31 #define CHALLENGE_RANDOM_LOCATION "/dev/urandom"
32
33 #define MemCheck(x) \
34 if(!x) { \
35 MemError(); \
36 return; \
37 }
38
39 #define MemCheckR(x, y) \
40 if(!x) { \
41 MemError(); \
42 return y; \
43 }
44
45 int getcopyconfigitemint(char *section, char *key, int def, int *value);
46 int getcopyconfigitemintpositive(char *section, char *key, int def);
47 int protected_atoi(char *buf, int *value);
48 int positive_atoi(char *data);
49 char *challenge_response(char *challenge, char *password);
50 char *get_random_hex(void);
51 char *request_error(int errn);
52 int get_challenge_entropy(unsigned char *data);
53 int generate_nonce(unsigned char *nonce, int nterfacer);
54 char *int_to_hex(unsigned char *input, char *buf, int len);
55 int hex_to_int(char *input, unsigned char *buf, int buflen);
56
57 #endif