1 |
/** |
2 |
* tools.h: Misc tools |
3 |
* |
4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
5 |
* Rights to this code are as documented in COPYING. |
6 |
* |
7 |
* |
8 |
* Portions of this file were derived from sources bearing the following license: |
9 |
* Copyright © 2003-2004 E. Will et al. |
10 |
* Copyright © 2005-2006 Atheme Development Group |
11 |
* Rights to this code are as documented in doc/pod/license.pod. |
12 |
* |
13 |
* $Id: tools.h,v 1.9 2007-09-16 18:54:42 pippijn Exp $ |
14 |
*/ |
15 |
|
16 |
#ifndef _TOOLS_H |
17 |
#define _TOOLS_H |
18 |
|
19 |
#include <object.h> |
20 |
|
21 |
/** |
22 |
* Warns operators and console users that an error occurred |
23 |
*/ |
24 |
#define warn(msg) \ |
25 |
do \ |
26 |
{ \ |
27 |
slog (LG_INFO, "%s(%d) [%s]: critical: " msg, \ |
28 |
__FILE__, __LINE__, CURFUNC); \ |
29 |
wallops ("%s(%d) [%s]: critical: " msg, \ |
30 |
__FILE__, __LINE__, CURFUNC);\ |
31 |
} while (0) |
32 |
|
33 |
/** |
34 |
* Performs a soft assertion. If the assertion fails, we wallops () and log. |
35 |
*/ |
36 |
#define soft_assert(cond) \ |
37 |
if (!(cond)) \ |
38 |
{ \ |
39 |
slog (LG_INFO, "%s(%d) [%s]: critical: Assertion '%s' failed.", \ |
40 |
__FILE__, __LINE__, CURFUNC, #cond); \ |
41 |
wallops ("%s(%d) [%s]: critical: Assertion '%s' failed.", \ |
42 |
__FILE__, __LINE__, CURFUNC, #cond); \ |
43 |
} |
44 |
|
45 |
/** |
46 |
* Same as soft_assert, but returns if an assertion fails. |
47 |
*/ |
48 |
#define return_if_fail(cond) \ |
49 |
if (!(cond)) \ |
50 |
{ \ |
51 |
slog (LG_INFO, "%s(%d) [%s]: critical: Assertion '%s' failed.", \ |
52 |
__FILE__, __LINE__, CURFUNC, #cond); \ |
53 |
wallops ("%s(%d) [%s]: critical: Assertion '%s' failed.", \ |
54 |
__FILE__, __LINE__, CURFUNC, #cond); \ |
55 |
return; \ |
56 |
} |
57 |
|
58 |
/** |
59 |
* Same as return_if_fail, but returns a given value if an assertion fails. |
60 |
*/ |
61 |
#define return_val_if_fail(cond, val) \ |
62 |
if (!(cond)) \ |
63 |
{ \ |
64 |
slog (LG_INFO, "%s(%d) [%s]: critical: Assertion '%s' failed.", \ |
65 |
__FILE__, __LINE__, CURFUNC, #cond); \ |
66 |
wallops ("%s(%d) [%s]: critical: Assertion '%s' failed.", \ |
67 |
__FILE__, __LINE__, CURFUNC, #cond); \ |
68 |
return (val); \ |
69 |
} |
70 |
|
71 |
/* email stuff */ |
72 |
/* the following struct is not used yet */ |
73 |
struct email_t |
74 |
{ |
75 |
char *sender; |
76 |
char *reciever; |
77 |
char *subject; |
78 |
char *body; |
79 |
char **headers; |
80 |
|
81 |
void *miscellaneous; /* module defined data */ |
82 |
void (*callback_sent) (email_t *); /* callback on email send */ |
83 |
}; |
84 |
|
85 |
E int sendemail (user_t *from, int type, myuser_t *mu, char const * const param); |
86 |
|
87 |
/* email types (meaning of param argument) */ |
88 |
enum email_type |
89 |
{ |
90 |
EMAIL_REGISTER = 1, /* register an account/nick (verification code) */ |
91 |
EMAIL_SENDPASS = 2, /* send a password to a user (password) */ |
92 |
EMAIL_SETEMAIL = 3, /* change email address (verification code) */ |
93 |
EMAIL_MEMO = 4, /* emailed memos (memo text) */ |
94 |
EMAIL_SETPASS = 5 /* send a password change key (verification code) */ |
95 |
}; |
96 |
|
97 |
/* function.c */ |
98 |
/* misc string stuff */ |
99 |
E char *gen_pw (int sz); |
100 |
E void tb2sp (char *line); |
101 |
E char *replace (char *s, int size, char const * const oldstr, char const * const newstr); |
102 |
|
103 |
E int validemail (char *email); |
104 |
E bool validhostmask (char *host); |
105 |
E char const *sbytes (float x); |
106 |
E float bytes (float x); |
107 |
|
108 |
E unsigned long makekey (void); |
109 |
|
110 |
/* tokenize.c */ |
111 |
E int sjtoken (char *message, char delimiter, char **parv, int limit = 256); |
112 |
E int tokenize (char *message, char **parv); |
113 |
|
114 |
inline int |
115 |
sjtoken (char const * const message, char delimiter, char **parv, int limit = 256) |
116 |
{ |
117 |
char *tmp = sstrdup (message); |
118 |
int parc = sjtoken (tmp, delimiter, parv, limit); |
119 |
gc.insert (tmp); |
120 |
|
121 |
return parc; |
122 |
} |
123 |
|
124 |
/* ubase64.c */ |
125 |
E char const * const uinttobase64 (char *buf, uint64_t v, int64_t count); |
126 |
E unsigned int base64touint (char *buf); |
127 |
|
128 |
#endif |