a few core updates to support sqlsrv as a module

This commit is contained in:
Mark 2004-07-29 18:34:35 +00:00
parent 8c0fb41ea4
commit 3dfffac2d7
10 changed files with 103 additions and 39 deletions

View file

@ -325,7 +325,7 @@
/*#define HAVE_STRLCPY 1*/
/* Define to 1 if you have the `strndup' function. */
#define HAVE_STRNDUP 1
/*#define HAVE_STRNDUP 1*/
/* Define to 1 if you have the `strnlen' function. */
/*#define HAVE_STRNLEN 1*/

View file

@ -513,10 +513,10 @@ typedef struct _Client {
char info[MAXREALNAME];
char version[MAXHOST];
unsigned int flags;
void *moddata[NUM_MODULES];
time_t tsconnect;
struct in_addr ip;
char hostip[HOSTIPLEN];
void *moddata[NUM_MODULES];
} _Client;
/** @brief me structure
@ -550,6 +550,8 @@ typedef struct tme {
time_t now;
char strnow[STR_TIME_T_SIZE];
char version[VERSIONSIZE];
int dobind;
struct sockaddr_in lsa;
} tme;
EXPORTVAR extern tme me;
@ -744,6 +746,14 @@ typedef int (*sock_func) (int sock_no, char *name);
typedef int (*before_poll_func) (void *data, struct pollfd *);
typedef void (*after_poll_func) (void *data, struct pollfd *, unsigned int);
/*
TEMP while moving sqlsrv to module API
*/
#ifdef NEOSTATSCORE
typedef void (*rta_hook_func) (fd_set *read_fd_set, fd_set *write_fd_set);
extern rta_hook_func rta_hook_1;
extern rta_hook_func rta_hook_2;
#endif
/* socket interface type */
#define SOCK_POLL 1
@ -961,25 +971,23 @@ typedef struct _Bot {
Client * u;
}_Bot;
EXPORTFUNC int ModuleConfig(bot_setting* bot_settings);
EXPORTFUNC int ModuleConfig(bot_setting *bot_settings);
EXPORTFUNC int add_timer (TIMER_TYPE type, timer_function func, const char* name, int interval);
EXPORTFUNC int del_timer (const char *timer_name);
EXPORTFUNC int set_timer_interval (const char *timer_name, int interval);
EXPORTFUNC Timer *find_timer(const char *timer_name);
EXPORTFUNC int add_sock (sock_func readfunc, sock_func writefunc, sock_func errfunc, const char *sock_name, int socknum);
EXPORTFUNC int add_sockpoll (before_poll_func beforepoll, after_poll_func afterpoll, const char *sock_name, void *data);
EXPORTFUNC int del_sock (const char *name);
EXPORTFUNC int add_sock (const char *sock_name, int socknum, sock_func readfunc, sock_func writefunc, sock_func errfunc);
EXPORTFUNC int add_sockpoll (const char *sock_name, void *data, before_poll_func beforepoll, after_poll_func afterpoll);
EXPORTFUNC int del_sock (const char *sock_name);
EXPORTFUNC Sock *find_sock (const char *sock_name);
EXPORTFUNC Bot * init_bot (BotInfo *botinfo);
EXPORTFUNC Bot *find_bot (const char *bot_name);
/* sock.c */
EXPORTFUNC int sock_connect (int socktype, unsigned long ipaddr, int port, const char *name, sock_func func_read, sock_func func_write, sock_func func_error);
EXPORTFUNC int sock_disconnect (const char *name);
EXPORTFUNC Bot *init_bot (BotInfo *botinfo);
EXPORTFUNC Bot *find_bot (const char *bot_name);
/* keeper interface */
#define CFGSTR 1
@ -1126,7 +1134,9 @@ EXPORTFUNC int dns_lookup (char *str, adns_rrtype type, void (*callback) (char *
/* services.c */
EXPORTFUNC int add_services_cmd_list (bot_cmd* bot_cmd_list);
EXPORTFUNC int add_services_set_list (bot_setting *bot_setting_list);
EXPORTFUNC int del_services_cmd_list (bot_cmd* bot_cmd_list);
EXPORTFUNC int del_services_set_list (bot_setting *bot_setting_list);
EXPORTFUNC Client * find_valid_user(Bot* botptr, Client * u, const char* target_nick);
/* transfer.c stuff */
@ -1225,7 +1235,11 @@ EXPORTFUNC void GetUserList(UserListHandler handler);
typedef void (*ServerListHandler) (Client * s);
EXPORTFUNC void GetServerList(ServerListHandler handler);
EXPORTFUNC hash_t * GetServerHash(void);
EXPORTFUNC hash_t *GetServerHash (void);
EXPORTFUNC hash_t *GetBanHash (void);
EXPORTFUNC hash_t *GetChannelHash (void);
EXPORTFUNC hash_t *GetUserHash (void);
EXPORTFUNC hash_t *GetModuleHash (void);
EXPORTFUNC int HaveFeature (int mask);

View file

@ -15,6 +15,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pcre", "lib\pcre\pcre.vcpro
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rta", "lib\rtawin32\rta.vcproj", "{C41CD6E3-30A4-4BB9-BA51-F97B2CD77D56}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@ -37,6 +41,10 @@ Global
{934FCDE5-D077-4619-B79C-A62580EA1E4A}.Debug.Build.0 = Debug|Win32
{934FCDE5-D077-4619-B79C-A62580EA1E4A}.Release.ActiveCfg = Release|Win32
{934FCDE5-D077-4619-B79C-A62580EA1E4A}.Release.Build.0 = Release|Win32
{C41CD6E3-30A4-4BB9-BA51-F97B2CD77D56}.Debug.ActiveCfg = Debug|Win32
{C41CD6E3-30A4-4BB9-BA51-F97B2CD77D56}.Debug.Build.0 = Debug|Win32
{C41CD6E3-30A4-4BB9-BA51-F97B2CD77D56}.Release.ActiveCfg = Release|Win32
{C41CD6E3-30A4-4BB9-BA51-F97B2CD77D56}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection

View file

@ -25,21 +25,21 @@
#include "modules.h"
#include "services.h"
static hash_t *banshash;
static hash_t *banhash;
static Ban *
new_ban (const char *mask)
{
Ban *ban;
if (hash_isfull (banshash)) {
if (hash_isfull (banhash)) {
nlog (LOG_CRITICAL, "new_ban: bans hash is full");
return NULL;
}
dlog(DEBUG2, "new_ban: %s", mask);
ban = scalloc (sizeof (Ban));
strlcpy (ban->mask, mask, MAXHOST);
hnode_create_insert (banshash, ban, ban->mask);
hnode_create_insert (banhash, ban, ban->mask);
return ban;
}
@ -88,7 +88,7 @@ DelBan(const char* type, const char* user, const char* host, const char* mask,
hnode_t *bansnode;
SET_SEGV_LOCATION();
bansnode = hash_lookup (banshash, mask);
bansnode = hash_lookup (banhash, mask);
if (!bansnode) {
nlog (LOG_WARNING, "DelBan: unknown ban %s", mask);
return;
@ -109,7 +109,7 @@ DelBan(const char* type, const char* user, const char* host, const char* mask,
sfree (cmdparams->av);
sfree (cmdparams);
hash_delete (banshash, bansnode);
hash_delete (banhash, bansnode);
hnode_destroy (bansnode);
sfree (ban);
}
@ -122,7 +122,7 @@ BanDump (void)
hnode_t *bansnode;
irc_chanalert (ns_botptr, "Ban Listing:");
hash_scan_begin (&ss, banshash);
hash_scan_begin (&ss, banhash);
while ((bansnode = hash_scan_next (&ss)) != NULL) {
ban = hnode_get (bansnode);
irc_chanalert (ns_botptr, "Ban: %s ", ban->mask);
@ -136,25 +136,29 @@ void FiniBans (void)
hnode_t *bansnode;
hscan_t hs;
hash_scan_begin(&hs, banshash);
hash_scan_begin(&hs, banhash);
while ((bansnode = hash_scan_next(&hs)) != NULL ) {
ban = hnode_get (bansnode);
hash_delete (banshash, bansnode);
hash_delete (banhash, bansnode);
hnode_destroy (bansnode);
sfree (ban);
}
hash_destroy(banshash);
hash_destroy(banhash);
}
int
InitBans (void)
{
banshash = hash_create (-1, 0, 0);
if (!banshash) {
banhash = hash_create (-1, 0, 0);
if (!banhash) {
nlog (LOG_CRITICAL, "Unable to create bans hash");
return NS_FAILURE;
}
return NS_SUCCESS;
}
hash_t *GetBanHash (void)
{
return banhash;
}

View file

@ -594,3 +594,7 @@ void GetChannelList(ChannelListHandler handler)
handler(c);
}
}
hash_t *GetChannelHash (void)
{
return channelhash;
}

View file

@ -1169,6 +1169,18 @@ int del_all_bot_settings (Bot *bot_ptr)
return NS_SUCCESS;
}
int add_services_set_list (bot_setting *bot_setting_list)
{
add_bot_setting_list (ns_botptr, bot_setting_list);
return NS_SUCCESS;
}
int del_services_set_list (bot_setting *bot_setting_list)
{
del_bot_setting_list (ns_botptr, bot_setting_list);
return NS_SUCCESS;
}
int bot_set_nick_cb(CmdParams* cmdparams, SET_REASON reason)
{
/* Ignore bootup callback */

View file

@ -350,6 +350,12 @@ load_module (const char *modfilename, Client * u)
irc_prefmsg (ns_botptr, u, "Module %s loaded, %s", info_ptr->name, info_ptr->description);
irc_globops (NULL, "Module %s loaded", info_ptr->name);
}
/*
TEMP while moving sqlsrv to module API
*/
rta_hook_1 = ns_dlsym (dl_handle, "rta_hook_1");
rta_hook_2 = ns_dlsym (dl_handle, "rta_hook_2");
return mod_ptr;
}
@ -679,3 +685,8 @@ void DisableEvent (Event event)
{
GET_CUR_MODULE()->event_list[event]->flags |= EVENT_FLAG_DISABLED;
}
hash_t *GetModuleHash (void)
{
return modulehash;
}

View file

@ -294,7 +294,7 @@ void RequestServerUptimes (void)
}
}
hash_t * GetServerHash (void)
hash_t *GetServerHash (void)
{
return serverhash;
}

View file

@ -50,8 +50,6 @@ struct pollfd { int fd; short events; short revents; };
static void recvlog (char *line);
static struct sockaddr_in lsa;
static int dobind;
/* @brief Module Socket List hash */
static hash_t *sockethash;
/* @brief server socket */
@ -60,6 +58,9 @@ char recbuf[BUFSIZE];
static struct timeval *TimeOut;
static struct pollfd *ufds;
typedef void (*rta_hook_func) (fd_set *read_fd_set, fd_set *write_fd_set);
rta_hook_func rta_hook_1 = NULL;
rta_hook_func rta_hook_2 = NULL;
/** @brief Connect to a server
*
@ -79,16 +80,16 @@ ConnectTo (char *host, int port)
struct sockaddr_in sa;
int s;
dobind = 0;
me.dobind = 0;
/* bind to a local ip */
memset (&lsa, 0, sizeof (lsa));
memset (&me.lsa, 0, sizeof (me.lsa));
if (me.local[0] != 0) {
if ((hp = gethostbyname (me.local)) == NULL) {
nlog (LOG_WARNING, "Warning, Couldn't bind to IP address %s", me.local);
} else {
memcpy ((char *) &lsa.sin_addr, hp->h_addr, hp->h_length);
lsa.sin_family = hp->h_addrtype;
dobind = 1;
memcpy ((char *) &me.lsa.sin_addr, hp->h_addr, hp->h_length);
me.lsa.sin_family = hp->h_addrtype;
me.dobind = 1;
}
}
if ((hp = gethostbyname (host)) == NULL) {
@ -99,8 +100,8 @@ ConnectTo (char *host, int port)
sfree(hp);
return NS_FAILURE;
}
if (dobind > 0) {
if (bind (s, (struct sockaddr *) &lsa, sizeof (lsa)) < 0) {
if (me.dobind > 0) {
if (bind (s, (struct sockaddr *) &me.lsa, sizeof (me.lsa)) < 0) {
nlog (LOG_WARNING, "bind(): Warning, Couldn't bind to IP address %s", strerror (errno));
}
}
@ -211,7 +212,9 @@ read_loop ()
/* add the fds for the curl library as well */
/* XXX Should this be a pollsize or maxfdsunused... not sure yet */
curl_multi_fdset(curlmultihandle, &readfds, &writefds, &errfds, &maxfdsunused);
if (rta_hook_1) {
rta_hook_1 (&readfds, &writefds);
}
SelectResult = select (FD_SETSIZE, &readfds, &writefds, &errfds, TimeOut);
me.now = time(NULL);
ircsnprintf (me.strnow, STR_TIME_T_SIZE, "%lu", (long)me.now);
@ -226,6 +229,9 @@ read_loop ()
while(CURLM_CALL_MULTI_PERFORM == curl_multi_perform(curlmultihandle, &maxfdsunused)) {
}
transfer_status();
if (rta_hook_2) {
rta_hook_2 (&readfds, &writefds);
}
if (FD_ISSET (servsock, &readfds)) {
for (j = 0; j < BUFSIZE; j++) {
#ifdef WIN32
@ -429,8 +435,8 @@ sock_connect (int socktype, unsigned long ipaddr, int port, const char *name, so
return NS_FAILURE;
/* bind to an IP address */
if (dobind > 0) {
if (bind (s, (struct sockaddr *) &lsa, sizeof (lsa)) < 0) {
if (me.dobind > 0) {
if (bind (s, (struct sockaddr *) &me.lsa, sizeof (me.lsa)) < 0) {
nlog (LOG_WARNING, "sock_connect(): Warning, Couldn't bind to IP address %s", strerror (errno));
}
}
@ -470,7 +476,7 @@ sock_connect (int socktype, unsigned long ipaddr, int port, const char *name, so
}
}
add_sock (func_read, func_write, func_error, name, s);
add_sock (name, s, func_read, func_write, func_error);
return s;
}
@ -637,7 +643,7 @@ find_sock (const char *sock_name)
* @return pointer to socket if found, NULL if not found
*/
int
add_sock (sock_func readfunc, sock_func writefunc, sock_func errfunc, const char *sock_name, int socknum)
add_sock (const char *sock_name, int socknum, sock_func readfunc, sock_func writefunc, sock_func errfunc)
{
Sock *sock;
Module* moduleptr;
@ -680,7 +686,7 @@ add_sock (sock_func readfunc, sock_func writefunc, sock_func errfunc, const char
* @return pointer to socket if found, NULL if not found
*/
int
add_sockpoll (before_poll_func beforepoll, after_poll_func afterpoll, const char *sock_name, void *data)
add_sockpoll (const char *sock_name, void *data, before_poll_func beforepoll, after_poll_func afterpoll)
{
Sock *sock;
Module* moduleptr;

View file

@ -602,3 +602,8 @@ DelFakeUser(const char *mask)
u = find_user (nick);
deluser(u);
}
hash_t *GetUserHash (void)
{
return userhash;
}