aboutsummaryrefslogtreecommitdiffstats
path: root/bitlbee.h
blob: f10e66d26b95de6491c539cdb0e172fc52f1dd4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2002-2004 Wilmer van der Gaast and others                *
  \********************************************************************/

/* Main file                                                            */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License with
  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef _BITLBEE_H
#define _BITLBEE_H

#define _GNU_SOURCE /* Stupid GNU :-P */

#define PACKAGE "BitlBee"
#define BITLBEE_VERSION "1.2"
#define VERSION BITLBEE_VERSION

#define MAX_STRING 511

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <fcntl.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#ifndef _WIN32
#include <syslog.h>
#include <errno.h>
#endif

#include <glib.h>
#include <gmodule.h>

/* The following functions should not be used if we want to maintain Windows compatibility... */
#undef free
#define free		__PLEASE_USE_THE_GLIB_MEMORY_ALLOCATION_SYSTEM__
#undef malloc
#define malloc		__PLEASE_USE_THE_GLIB_MEMORY_ALLOCATION_SYSTEM__
#undef calloc
#define calloc		__PLEASE_USE_THE_GLIB_MEMORY_ALLOCATION_SYSTEM__
#undef realloc
#define realloc		__PLEASE_USE_THE_GLIB_MEMORY_ALLOCATION_SYSTEM__
#undef strdup
#define strdup		__PLEASE_USE_THE_GLIB_STRDUP_FUNCTIONS_SYSTEM__
#undef strndup
#define strndup		__PLEASE_USE_THE_GLIB_STRDUP_FUNCTIONS_SYSTEM__
#undef snprintf
#define snprintf	__PLEASE_USE_G_SNPRINTF__
#undef strcasecmp
#define strcasecmp	__PLEASE_USE_G_STRCASECMP__
#undef strncasecmp
#define strncasecmp	__PLEASE_USE_G_STRNCASECMP__

/* And the following functions shouldn't be used anymore to keep compatibility
   with other event handling libs than GLib. */
#undef g_timeout_add
#define g_timeout_add		__PLEASE_USE_B_TIMEOUT_ADD__
#undef g_timeout_add_full
#define g_timeout_add_full	__PLEASE_USE_B_TIMEOUT_ADD__
#undef g_io_add_watch
#define g_io_add_watch		__PLEASE_USE_B_INPUT_ADD__
#undef g_io_add_watch_full
#define g_io_add_watch_full	__PLEASE_USE_B_INPUT_ADD__
#undef g_source_remove
#define g_source_remove		__PLEASE_USE_B_EVENT_REMOVE__
#undef g_source_remove_by_user_data
#define g_source_remove_by_user_data	__PLEASE_USE_B_SOURCE_REMOVE_BY_USER_DATA__
#undef g_main_run
#define g_main_run		__PLEASE_USE_B_MAIN_RUN__
#undef g_main_quit
#define g_main_quit		__PLEASE_USE_B_MAIN_QUIT__

#ifndef G_GNUC_MALLOC
/* Doesn't exist in GLib <=2.4 while everything else in BitlBee should
   work with it, so let's fake this one. */
#define G_GNUC_MALLOC
#endif

#define _( x ) x

#define ROOT_NICK "root"
#define ROOT_CHAN "&bitlbee"
#define ROOT_FN "User manager"

#define NS_NICK "NickServ"

#define DEFAULT_AWAY "Away from computer"
#define CONTROL_TOPIC "Welcome to the control channel. Type \2help\2 for help information."
#define IRCD_INFO "BitlBee <http://www.bitlbee.org/>"

#define MAX_NICK_LENGTH 24

#define HELP_FILE VARDIR "help.txt"
#define CONF_FILE_DEF ETCDIR "bitlbee.conf"

#include "irc.h"
#include "storage.h"
#include "set.h"
#include "nogaim.h"
#include "commands.h"
#include "account.h"
#include "nick.h"
#include "conf.h"
#include "log.h"
#include "ini.h"
#include "help.h"
#include "query.h"
#include "sock.h"
#include "misc.h"
#include "proxy.h"

typedef struct global {
	/* In forked mode, child processes store the fd of the IPC socket here. */
	int listen_socket;
	gint listen_watch_source_id;
	help_t *help;
	char *conf_file;
	conf_t *conf;
	GList *storage; /* The first backend in the list will be used for saving */
	char *helpfile;
	int restart;
} global_t;

int bitlbee_daemon_init( void );
int bitlbee_inetd_init( void );

gboolean bitlbee_io_current_client_read( gpointer data, gint source, b_input_condition cond );
gboolean bitlbee_io_current_client_write( gpointer data, gint source, b_input_condition cond );

void root_command_string( irc_t *irc, user_t *u, char *command, int flags );
void root_command( irc_t *irc, char *command[] );
gboolean bitlbee_shutdown( gpointer data, gint fd, b_input_condition cond );

char *set_eval_root_nick( set_t *set, char *new_nick );

extern global_t global;

#endif
irc; char *name; char mode[8]; int flags; char *topic; char *topic_who; time_t topic_time; GSList *users; struct set *set; const struct irc_channel_funcs *f; } irc_channel_t; struct irc_channel_funcs { gboolean (*privmsg)( irc_channel_t *iu, const char *msg ); }; extern const struct bee_ui_funcs irc_ui_funcs; /* irc.c */ extern GSList *irc_connection_list; irc_t *irc_new( int fd ); void irc_abort( irc_t *irc, int immed, char *format, ... ) G_GNUC_PRINTF( 3, 4 ); void irc_free( irc_t *irc ); void irc_process( irc_t *irc ); char **irc_parse_line( char *line ); char *irc_build_line( char **cmd ); void irc_write( irc_t *irc, char *format, ... ) G_GNUC_PRINTF( 2, 3 ); void irc_write_all( int now, char *format, ... ) G_GNUC_PRINTF( 2, 3 ); void irc_vawrite( irc_t *irc, char *format, va_list params ); int irc_check_login( irc_t *irc ); void irc_umode_set( irc_t *irc, const char *s, gboolean allow_priv ); /* irc_channel.c */ irc_channel_t *irc_channel_new( irc_t *irc, const char *name ); irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name ); int irc_channel_free( irc_channel_t *ic ); int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu ); int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu ); gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu ); int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who ); gboolean irc_channel_name_ok( const char *name ); /* irc_commands.c */ void irc_exec( irc_t *irc, char **cmd ); /* irc_send.c */ void irc_send_num( irc_t *irc, int code, char *format, ... ) G_GNUC_PRINTF( 3, 4 ); void irc_send_login( irc_t *irc ); void irc_send_motd( irc_t *irc ); void irc_usermsg( irc_t *irc, char *format, ... ); void irc_send_join( irc_channel_t *ic, irc_user_t *iu ); void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason ); void irc_send_names( irc_channel_t *ic ); void irc_send_topic( irc_channel_t *ic, gboolean topic_change ); void irc_send_whois( irc_user_t *iu ); void irc_send_who( irc_t *irc, GSList *l, const char *channel ); void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix ); void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg ); void irc_send_nick( irc_user_t *iu, const char *new ); /* irc_user.c */ irc_user_t *irc_user_new( irc_t *irc, const char *nick ); int irc_user_free( irc_t *irc, const char *nick ); irc_user_t *irc_user_by_name( irc_t *irc, const char *nick ); int irc_user_set_nick( irc_user_t *iu, const char *new ); gint irc_user_cmp( gconstpointer a_, gconstpointer b_ ); #endif