source: lib/misc.h @ 885d294

Last change on this file since 885d294 was 6f10697, checked in by dequis <dx@…>, at 2015-01-16T19:50:23Z

Fix incorrect Free Software Foundation address

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[e27661d]1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
[0e788f5]4  * Copyright 2002-2012 Wilmer van der Gaast and others                *
[e27661d]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;
[6f10697]22  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
23  Fifth Floor, Boston, MA  02110-1301  USA
[e27661d]24*/
25
[1719464]26#ifndef _MISC_H
27#define _MISC_H
28
29#include <gmodule.h>
30#include <time.h>
[e27661d]31
[36e9f62]32struct ns_srv_reply
33{
34        int prio;
35        int weight;
36        int port;
37        char name[];
38};
39
[632627e]40#ifndef NAMESER_HAS_NS_TYPES
41
42#define NS_MAXDNAME 1025
43#define NS_INT16SZ  2
44#define NS_INT32SZ  4
45
46#define NS_GET16(s, cp) do { \
47        register const unsigned char *t_cp = (const unsigned char*)(cp); \
48        (s) = ((guint16)t_cp[0] << 8) \
49            | ((guint16)t_cp[1]) \
50            ; \
51        (cp) += NS_INT16SZ; \
52} while(0)
53
54#define NS_GET32(s, cp) do { \
55        register const unsigned char *t_cp = (const unsigned char*)(cp); \
56        (s) = ((guint16)t_cp[0] << 24) \
57            | ((guint16)t_cp[1] << 16) \
58            | ((guint16)t_cp[2] << 8) \
59            | ((guint16)t_cp[3]) \
60            ; \
61        (cp) += NS_INT32SZ; \
62} while(0)
63
64#define ns_rr_rdlen(rr) ((rr).rdlength + 0)
65#define ns_rr_rdata(rr) ((rr).rdata + 0)
66
67struct _ns_flagdata { int mask, shift; };
68
69typedef struct __ns_rr {
70        char name[NS_MAXDNAME];
71        guint16 type;
72        guint16 rr_class;
73        guint32 ttl;
74        guint16 rdlength;
75        const unsigned char* rdata;
76} ns_rr;
77
78typedef enum __ns_sect {
79        ns_s_qd = 0,
80        ns_s_zn = 0,
81        ns_s_an = 1,
82        ns_s_pr = 1,
83        ns_s_ns = 2,
84        ns_s_ud = 2,
85        ns_s_ar = 3,
86        ns_s_max =4
87} ns_sect;
88
89typedef struct __ns_msg
90{
91        const unsigned char* _msg;
92        const unsigned char* _eom;
93        guint16 _id;
94        guint16 _flags;
95        guint16 _counts[ns_s_max];
96        const unsigned char* _sections[ns_s_max];
97        ns_sect _sect;
98        int _rrnum;
99        const unsigned char* _msg_ptr;
100} ns_msg;
101
102typedef enum __ns_class {
103        ns_c_invalid = 0,
104        ns_c_in = 1,
105        ns_c_2 = 2,
106        ns_c_chaos = 3,
107        ns_c_hs = 4,
108        ns_c_none = 254,
109        ns_c_any = 255,
110        ns_c_max = 65536
111} ns_class;
112
113
114/* TODO : fill out the rest */
115typedef enum __ns_type {
116        ns_t_srv = 33
117} ns_type;
118
119#endif /* NAMESER_HAS_NS_INITPARSE */
120
[e27661d]121G_MODULE_EXPORT void strip_linefeed( gchar *text );
122G_MODULE_EXPORT char *add_cr( char *text );
123G_MODULE_EXPORT char *strip_newlines(char *source);
124
125G_MODULE_EXPORT time_t get_time( int year, int month, int day, int hour, int min, int sec );
[2e3a857]126G_MODULE_EXPORT time_t mktime_utc( struct tm *tp );
[e27661d]127double gettime( void );
128
129G_MODULE_EXPORT void strip_html( char *msg );
130G_MODULE_EXPORT char *escape_html( const char *html );
131G_MODULE_EXPORT void http_decode( char *s );
132G_MODULE_EXPORT void http_encode( char *s );
133
134G_MODULE_EXPORT char *ipv6_wrap( char *src );
135G_MODULE_EXPORT char *ipv6_unwrap( char *src );
136
137G_MODULE_EXPORT signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf );
[1719464]138
139G_MODULE_EXPORT void random_bytes( unsigned char *buf, int count );
[e27661d]140
[5100caa]141G_MODULE_EXPORT int is_bool( char *value );
142G_MODULE_EXPORT int bool2int( char *value );
143
[ffdf2e7]144G_MODULE_EXPORT struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain );
145G_MODULE_EXPORT void srv_free( struct ns_srv_reply **srv );
[36e9f62]146
[c6ca3ee]147G_MODULE_EXPORT char *word_wrap( const char *msg, int line_len );
[d52111a]148G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl );
[4e8db1c]149G_MODULE_EXPORT int md5_verify_password( char *password, char *hash );
[269580c]150G_MODULE_EXPORT char **split_command_parts( char *command, int limit );
[55ccc9a0]151G_MODULE_EXPORT char *get_rfc822_header( const char *text, const char *header, int len );
[24b8bbb]152
[e27661d]153#endif
Note: See TracBrowser for help on using the repository browser.