ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/tools.h
Revision: 1.8
Committed: Sun Sep 9 20:05:51 2007 UTC (19 years ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.7: +12 -73 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

File Contents

# User Rev Content
1 pippijn 1.1 /*
2 pippijn 1.4 * Copyright © 2003-2004 E. Will et al.
3     * Copyright © 2005-2006 Atheme Development Group
4 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
5 pippijn 1.1 *
6     * Misc tools
7     *
8 pippijn 1.8 * $Id: tools.h,v 1.7 2007-08-30 19:56:20 pippijn Exp $
9 pippijn 1.1 */
10    
11     #ifndef _TOOLS_H
12     #define _TOOLS_H
13    
14 pippijn 1.7 #include <object.h>
15    
16 pippijn 1.6 /**
17 pippijn 1.1 * Warns operators and console users that an error occurred
18     */
19 pippijn 1.6 #define warn(msg) \
20 pippijn 1.1 do \
21     { \
22 pippijn 1.6 slog (LG_INFO, "%s(%d) [%s]: critical: " msg, \
23     __FILE__, __LINE__, CURFUNC); \
24     wallops ("%s(%d) [%s]: critical: " msg, \
25     __FILE__, __LINE__, CURFUNC);\
26 pippijn 1.1 } while (0)
27    
28 pippijn 1.6 /**
29     * Performs a soft assertion. If the assertion fails, we wallops () and log.
30 pippijn 1.1 */
31 pippijn 1.6 #define soft_assert(cond) \
32     if (!(cond)) \
33     { \
34     slog (LG_INFO, "%s(%d) [%s]: critical: Assertion '%s' failed.", \
35     __FILE__, __LINE__, CURFUNC, #cond); \
36     wallops ("%s(%d) [%s]: critical: Assertion '%s' failed.", \
37     __FILE__, __LINE__, CURFUNC, #cond); \
38     }
39 pippijn 1.1
40 pippijn 1.6 /**
41 pippijn 1.1 * Same as soft_assert, but returns if an assertion fails.
42     */
43 pippijn 1.6 #define return_if_fail(cond) \
44     if (!(cond)) \
45     { \
46     slog (LG_INFO, "%s(%d) [%s]: critical: Assertion '%s' failed.", \
47     __FILE__, __LINE__, CURFUNC, #cond); \
48     wallops ("%s(%d) [%s]: critical: Assertion '%s' failed.", \
49     __FILE__, __LINE__, CURFUNC, #cond); \
50     return; \
51     }
52 pippijn 1.1
53 pippijn 1.6 /**
54 pippijn 1.4 * Same as return_if_fail, but returns a given value if an assertion fails.
55 pippijn 1.1 */
56 pippijn 1.6 #define return_val_if_fail(cond, val) \
57     if (!(cond)) \
58     { \
59     slog (LG_INFO, "%s(%d) [%s]: critical: Assertion '%s' failed.", \
60     __FILE__, __LINE__, CURFUNC, #cond); \
61     wallops ("%s(%d) [%s]: critical: Assertion '%s' failed.", \
62     __FILE__, __LINE__, CURFUNC, #cond); \
63     return (val); \
64     }
65 pippijn 1.1
66     /* email stuff */
67     /* the following struct is not used yet */
68     struct email_t
69     {
70     char *sender;
71     char *reciever;
72     char *subject;
73     char *body;
74     char **headers;
75    
76     void *miscellaneous; /* module defined data */
77     void (*callback_sent) (email_t *); /* callback on email send */
78     };
79    
80 pippijn 1.4 E int sendemail (user_t *from, int type, myuser_t *mu, char const * const param);
81 pippijn 1.1
82     /* email types (meaning of param argument) */
83 pippijn 1.6 enum email_type
84     {
85     EMAIL_REGISTER = 1, /* register an account/nick (verification code) */
86     EMAIL_SENDPASS = 2, /* send a password to a user (password) */
87     EMAIL_SETEMAIL = 3, /* change email address (verification code) */
88     EMAIL_MEMO = 4, /* emailed memos (memo text) */
89     EMAIL_SETPASS = 5 /* send a password change key (verification code) */
90     };
91 pippijn 1.1
92     /* function.c */
93     /* misc string stuff */
94     E char *gen_pw (int sz);
95     E void tb2sp (char *line);
96 pippijn 1.4 E char *replace (char *s, int size, char const * const oldstr, char const * const newstr);
97 pippijn 1.8
98     /* reverse of atoi() */
99     template<typename T>
100     static inline char *
101     itoa (T num)
102     {
103     static char ret[32];
104     itoa (num, ret);
105     return ret;
106     }
107    
108 pippijn 1.1 E int validemail (char *email);
109     E bool validhostmask (char *host);
110 pippijn 1.4 E char const *sbytes (float x);
111 pippijn 1.1 E float bytes (float x);
112    
113     E unsigned long makekey (void);
114    
115     /* time stuff */
116     #if HAVE_GETTIMEOFDAY
117     E void s_time (struct timeval *sttime);
118     E void e_time (struct timeval sttime, struct timeval *ttime);
119     E int tv2ms (struct timeval *tv);
120     #endif
121     E char *time_ago (time_t event);
122     E char *timediff (time_t seconds);
123    
124 pippijn 1.6 #ifdef timersub
125     #undef timersub
126     inline void
127     timersub (timeval *tvp, timeval *uvp, timeval *vvp)
128     {
129     vvp->tv_sec = tvp->tv_sec - uvp->tv_sec;
130     vvp->tv_usec = tvp->tv_usec - uvp->tv_usec;
131     if (vvp->tv_usec < 0)
132     {
133     vvp->tv_sec--;
134     vvp->tv_usec += 1000000;
135     }
136     }
137 pippijn 1.1 #endif
138    
139     /* tokenize.c */
140 pippijn 1.3 E int sjtoken (char *message, char delimiter, char **parv, int limit = 256);
141 pippijn 1.1 E int tokenize (char *message, char **parv);
142    
143 pippijn 1.5 inline int
144     sjtoken (char const * const message, char delimiter, char **parv, int limit = 256)
145     {
146     char *tmp = sstrdup (message);
147     int parc = sjtoken (tmp, delimiter, parv, limit);
148 pippijn 1.6 gc.insert (tmp);
149 pippijn 1.5
150     return parc;
151     }
152    
153 pippijn 1.1 /* ubase64.c */
154 pippijn 1.4 E char const * const uinttobase64 (char *buf, uint64_t v, int64_t count);
155 pippijn 1.1 E unsigned int base64touint (char *buf);
156    
157     #endif