source: lib/misc.h @ aa3b61e

Last change on this file since aa3b61e was 73f0a01, checked in by dequis <dx@…>, at 2015-05-31T02:31:24Z

Move twitter_parse_id() to parse_int64() in misc.c

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2012 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* Misc. functions                                                      */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
23  Fifth Floor, Boston, MA  02110-1301  USA
24*/
25
26#ifndef _MISC_H
27#define _MISC_H
28
29#include <gmodule.h>
30#include <time.h>
31
32struct ns_srv_reply {
33        int prio;
34        int weight;
35        int port;
36        char name[];
37};
38
39#ifndef NAMESER_HAS_NS_TYPES
40
41#define NS_MAXDNAME 1025
42#define NS_INT16SZ  2
43#define NS_INT32SZ  4
44
45#define NS_GET16(s, cp) do { \
46                register const unsigned char *t_cp = (const unsigned char *) (cp); \
47                (s) = ((guint16) t_cp[0] << 8) \
48                      | ((guint16) t_cp[1]) \
49                ; \
50                (cp) += NS_INT16SZ; \
51} while (0)
52
53#define NS_GET32(s, cp) do { \
54                register const unsigned char *t_cp = (const unsigned char *) (cp); \
55                (s) = ((guint16) t_cp[0] << 24) \
56                      | ((guint16) t_cp[1] << 16) \
57                      | ((guint16) t_cp[2] << 8) \
58                      | ((guint16) t_cp[3]) \
59                ; \
60                (cp) += NS_INT32SZ; \
61} while (0)
62
63#define ns_rr_rdlen(rr) ((rr).rdlength + 0)
64#define ns_rr_rdata(rr) ((rr).rdata + 0)
65
66struct _ns_flagdata { int mask, shift; };
67
68typedef struct __ns_rr {
69        char name[NS_MAXDNAME];
70        guint16 type;
71        guint16 rr_class;
72        guint32 ttl;
73        guint16 rdlength;
74        const unsigned char* rdata;
75} ns_rr;
76
77typedef enum __ns_sect {
78        ns_s_qd = 0,
79        ns_s_zn = 0,
80        ns_s_an = 1,
81        ns_s_pr = 1,
82        ns_s_ns = 2,
83        ns_s_ud = 2,
84        ns_s_ar = 3,
85        ns_s_max = 4
86} ns_sect;
87
88typedef struct __ns_msg {
89        const unsigned char* _msg;
90        const unsigned char* _eom;
91        guint16 _id;
92        guint16 _flags;
93        guint16 _counts[ns_s_max];
94        const unsigned char* _sections[ns_s_max];
95        ns_sect _sect;
96        int _rrnum;
97        const unsigned char* _msg_ptr;
98} ns_msg;
99
100typedef enum __ns_class {
101        ns_c_invalid = 0,
102        ns_c_in = 1,
103        ns_c_2 = 2,
104        ns_c_chaos = 3,
105        ns_c_hs = 4,
106        ns_c_none = 254,
107        ns_c_any = 255,
108        ns_c_max = 65536
109} ns_class;
110
111
112/* TODO : fill out the rest */
113typedef enum __ns_type {
114        ns_t_srv = 33
115} ns_type;
116
117#endif /* NAMESER_HAS_NS_INITPARSE */
118
119G_MODULE_EXPORT void strip_linefeed(gchar *text);
120G_MODULE_EXPORT char *add_cr(char *text);
121G_MODULE_EXPORT char *strip_newlines(char *source);
122
123G_MODULE_EXPORT time_t get_time(int year, int month, int day, int hour, int min, int sec);
124G_MODULE_EXPORT time_t mktime_utc(struct tm *tp);
125double gettime(void);
126
127G_MODULE_EXPORT void strip_html(char *msg);
128G_MODULE_EXPORT char *escape_html(const char *html);
129G_MODULE_EXPORT void http_decode(char *s);
130G_MODULE_EXPORT void http_encode(char *s);
131
132G_MODULE_EXPORT char *ipv6_wrap(char *src);
133G_MODULE_EXPORT char *ipv6_unwrap(char *src);
134
135G_MODULE_EXPORT signed int do_iconv(char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf);
136
137G_MODULE_EXPORT void random_bytes(unsigned char *buf, int count);
138
139G_MODULE_EXPORT int is_bool(char *value);
140G_MODULE_EXPORT int bool2int(char *value);
141
142G_MODULE_EXPORT struct ns_srv_reply **srv_lookup(char *service, char *protocol, char *domain);
143G_MODULE_EXPORT void srv_free(struct ns_srv_reply **srv);
144
145G_MODULE_EXPORT char *word_wrap(const char *msg, int line_len);
146G_MODULE_EXPORT gboolean ssl_sockerr_again(void *ssl);
147G_MODULE_EXPORT int md5_verify_password(char *password, char *hash);
148G_MODULE_EXPORT char **split_command_parts(char *command, int limit);
149G_MODULE_EXPORT char *get_rfc822_header(const char *text, const char *header, int len);
150G_MODULE_EXPORT int truncate_utf8(char *string, int maxlen);
151G_MODULE_EXPORT gboolean parse_int64(char *string, int base, guint64 *number);
152
153#endif
Note: See TracBrowser for help on using the repository browser.