ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/tools.h
Revision: 1.10
Committed: Sat Sep 22 14:27:26 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +1 -35 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# User Rev Content
1 pippijn 1.9 /**
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 pippijn 1.4 * Copyright © 2003-2004 E. Will et al.
10     * Copyright © 2005-2006 Atheme Development Group
11 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
12 pippijn 1.1 *
13 pippijn 1.10 * $Id: tools.h,v 1.9 2007-09-16 18:54:42 pippijn Exp $
14 pippijn 1.1 */
15    
16     #ifndef _TOOLS_H
17     #define _TOOLS_H
18    
19 pippijn 1.7 #include <object.h>
20    
21 pippijn 1.6 /**
22 pippijn 1.1 * Warns operators and console users that an error occurred
23     */
24 pippijn 1.6 #define warn(msg) \
25 pippijn 1.1 do \
26     { \
27 pippijn 1.6 slog (LG_INFO, "%s(%d) [%s]: critical: " msg, \
28     __FILE__, __LINE__, CURFUNC); \
29     wallops ("%s(%d) [%s]: critical: " msg, \
30     __FILE__, __LINE__, CURFUNC);\
31 pippijn 1.1 } while (0)
32    
33 pippijn 1.6 /**
34     * Performs a soft assertion. If the assertion fails, we wallops () and log.
35 pippijn 1.1 */
36 pippijn 1.6 #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 pippijn 1.1
45 pippijn 1.6 /**
46 pippijn 1.1 * Same as soft_assert, but returns if an assertion fails.
47     */
48 pippijn 1.6 #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 pippijn 1.1
58 pippijn 1.6 /**
59 pippijn 1.4 * Same as return_if_fail, but returns a given value if an assertion fails.
60 pippijn 1.1 */
61 pippijn 1.6 #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 pippijn 1.1
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 pippijn 1.4 E int sendemail (user_t *from, int type, myuser_t *mu, char const * const param);
86 pippijn 1.1
87     /* email types (meaning of param argument) */
88 pippijn 1.6 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 pippijn 1.1
97     /* function.c */
98     /* misc string stuff */
99     E char *gen_pw (int sz);
100     E void tb2sp (char *line);
101 pippijn 1.4 E char *replace (char *s, int size, char const * const oldstr, char const * const newstr);
102 pippijn 1.8
103 pippijn 1.1 E int validemail (char *email);
104     E bool validhostmask (char *host);
105 pippijn 1.4 E char const *sbytes (float x);
106 pippijn 1.1 E float bytes (float x);
107    
108     E unsigned long makekey (void);
109    
110     /* tokenize.c */
111 pippijn 1.3 E int sjtoken (char *message, char delimiter, char **parv, int limit = 256);
112 pippijn 1.1 E int tokenize (char *message, char **parv);
113    
114 pippijn 1.5 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 pippijn 1.6 gc.insert (tmp);
120 pippijn 1.5
121     return parc;
122     }
123    
124 pippijn 1.1 /* ubase64.c */
125 pippijn 1.4 E char const * const uinttobase64 (char *buf, uint64_t v, int64_t count);
126 pippijn 1.1 E unsigned int base64touint (char *buf);
127    
128     #endif