/*
nterfacer
- Copyright (C) 2004 Chris Porter.
+ Copyright (C) 2004-2006 Chris Porter.
+ v1.07a
+ - dumb config bug
+ v1.07
+ - made sure buf[0] = '\0'
+ v1.06
+ - tidy up
v1.05
- added application level ping support
v1.04
#include <sys/ioctl.h>
#include <netdb.h>
#include <string.h>
+#include <strings.h>
#include "../lib/sstring.h"
#include "../lib/irc_string.h"
#include "../core/config.h"
#include "../core/events.h"
+#include "../lib/version.h"
#include "nterfacer.h"
#include "logging.h"
+MODULE_VERSION("$Id: nterfacer.c 663 2006-05-16 17:27:36Z newserv $")
+
struct service_node *tree = NULL;
struct esocket_events nterfacer_events;
struct esocket *nterfacer_sock;
unsigned short nterfacer_token = BLANK_TOKEN;
struct nterface_auto_log *nrl;
-struct service_node *ping;
+struct service_node *ping = NULL;
int ping_handler(struct rline *ri, int argc, char **argv);
snprintf(buf, sizeof(buf), "hostname%d", i);
item->hostname = getcopyconfigitem("nterfacer", buf, "", 100);
if(!item->hostname) {
- nterface_log(nrl, NL_ERROR, "No hostname found for item %d.", item->hostname->content, i);
+ nterface_log(nrl, NL_ERROR, "No hostname found for item %d.", i);
continue;
}
listen(fd, 5);
- if(ioctl(fd, FIONBIO, &opt) !=0) {
+ if(ioctl(fd, FIONBIO, &opt)) {
nterface_log(nrl, NL_ERROR, "Unable to set listen socket non-blocking.");
return -1;
}
return NULL;
}
- hp->function = (handler_function *)fp;
+ hp->function = fp;
hp->args = args;
hp->next = service->handlers;
return;
}
- if(ioctl(newfd, FIONBIO, &opt) !=0) {
- nterface_log(nrl, NL_ERROR, "Unable to set listen socket non-blocking.");
+ if(ioctl(newfd, FIONBIO, &opt)) {
+ nterface_log(nrl, NL_ERROR, "Unable to set accepted socket non-blocking.");
return;
}
return 1;
}
- return esocket_write_line(sock, "%s %s", hex, int_to_hex(socket->ournonce, hexbuf, NONCE_LEN));
+ if(esocket_write_line(sock, "%s %s", hex, int_to_hex(socket->ournonce, hexbuf, NONCE_LEN)))
+ return BUF_ERROR;
+ return 0;
}
break;
case SS_VERSIONED:
if(!ret) {
switch_buffer_mode(sock, socket->permit->password->content, socket->ournonce, theirnonce);
} else {
- return ret;
+ return BUF_ERROR;
}
} else {
nterface_log(nrl, NL_INFO, "Bad CR drop: %s", socket->permit->hostname->content);
if(reason == RE_SOCKET_ERROR)
return BUF_ERROR;
if(reason != RE_BAD_LINE) {
- return esocket_write_line(sock, "%d,E%d,%s", number, reason, request_error(reason));
+ if(esocket_write_line(sock, "%d,E%d,%s", number, reason, request_error(reason)))
+ return BUF_ERROR;
+ return 0;
} else {
return 1;
}
}
int nterfacer_new_rline(char *line, struct esocket *socket, int *number) {
- char *sp, *p, *parsebuf, *pp, commandbuf[MAX_BUFSIZE], *args[MAX_ARGS], *newp;
+ char *sp, *p, *parsebuf = NULL, *pp, commandbuf[MAX_BUFSIZE], *args[MAX_ARGS], *newp;
int argcount;
struct service_node *service;
struct rline *prequest;
*newp = '\0';
}
if(argcount < hl->args) {
- if(argcount)
+ if(argcount && parsebuf)
free(parsebuf);
return RE_WRONG_ARG_COUNT;
}
prequest = (struct rline *)malloc(sizeof(struct rline));
if(!prequest) {
MemError();
- if(argcount)
+ if(argcount && parsebuf)
free(parsebuf);
return RE_MEM_ERROR;
}
prequest->service = service;
prequest->handler = hl;
+ prequest->buf[0] = '\0';
prequest->curpos = prequest->buf;
prequest->tag = NULL;
prequest->id = *number;
prequest->socket = socket;
rlines = prequest;
- re = ((handler_function)hl->function)(prequest, argcount, args);
+ re = (hl->function)(prequest, argcount, args);
- if(argcount)
+ if(argcount && parsebuf)
free(parsebuf);
return re;
char buf[MAX_BUFSIZE], escapedbuf[MAX_BUFSIZE * 2 + 1], *p, *tp;
struct rline *pp, *lp = NULL;
va_list ap;
+ int retval = RE_OK;
if(li->socket) {
va_start(ap, format);
if((*p == ',') || (*p == '\\'))
*tp++ = '\\';
- esocket_write_line(li->socket, "%d,OE%d,%s", li->id, error_code, escapedbuf);
+ if(esocket_write_line(li->socket, "%d,OE%d,%s", li->id, error_code, escapedbuf))
+ retval = RE_SOCKET_ERROR;
}
for(pp=rlines;pp;lp=pp,pp=pp->next) {
}
}
- return RE_OK;
+ return retval;
}
int ri_final(struct rline *li) {