Commit 370188a2 authored by Dustin L. Howett's avatar Dustin L. Howett

ircprintf -> server::printf

parent 7a3d788e
......@@ -36,20 +36,20 @@ _COMMAND(copyover) {
}
_COMMAND(ping) {
ircprintf(server, "PRIVMSG %s :PONG", state->channel);
server->printf("PRIVMSG %s :PONG", state->channel);
return 0;
}
_COMMAND(report) {
ircprintf(server, "PRIVMSG %s :Compile date: %s %s", state->channel, __DATE__, __TIME__);
server->printf("PRIVMSG %s :Compile date: %s %s", state->channel, __DATE__, __TIME__);
return 0;
}
_COMMAND(arguments) {
char **argvp = argv;
ircprintf(server, "PRIVMSG %s :argc: %d", state->channel, argc);
server->printf("PRIVMSG %s :argc: %d", state->channel, argc);
while(*argvp) {
ircprintf(server, "PRIVMSG %s :Argument: %s", state->channel, *argvp);
server->printf("PRIVMSG %s :Argument: %s", state->channel, *argvp);
argvp++;
}
return 0;
......
......@@ -28,18 +28,18 @@ void dispatch_event(server *server, char *name, struct sender *sender, char *msg
_EVENT(001) {
char *nick = strsep(&msgbuf, " ");
server->nick = strdup(nick);
ircprintf(server, "JOIN #bacon");
server->printf("JOIN #bacon");
}
// 433 Nickname In Use
_EVENT(433) {
strsep(&msgbuf, " ");
char *nick = strsep(&msgbuf, " ");
ircprintf(server, "NICK %s_", nick);
server->printf("NICK %s_", nick);
}
_EVENT(PING) {
ircprintf(server, "PONG %s", msgbuf);
server->printf("PONG %s", msgbuf);
}
_EVENT(PRIVMSG) {
......@@ -81,7 +81,7 @@ _EVENT(PRIVMSG) {
state.channel = (priv ? sender->nick : recipient);
if(dispatch_command(server, commandname, argc, argv, &state) == -1) {
ircprintf(server, "PRIVMSG %s :Unknown command: %s", priv?sender->nick:recipient, commandname);
server->printf("PRIVMSG %s :Unknown command: %s", priv?sender->nick:recipient, commandname);
}
free(argv);
......
......@@ -53,7 +53,7 @@ void do_copyover(char *requester) {
free(fn);
//if(requester) // Yes, we're actually queueing this for when the copyover comes back and the socket is ready. Clever?!
//ircprintf(server, "PRIVMSG %s :--- COPYOVER COMPLETE ---", requester);
//server->printf("PRIVMSG %s :--- COPYOVER COMPLETE ---", requester);
uint8_t *tag_data = NULL;
uint32_t tags_size = 0;
......@@ -148,8 +148,8 @@ void _new_server(char *hostname) {
control_fd = 0;
_D("Got control fd %d\n", control_fd);
ircprintf(newserver, "USER 1 2 3 4"); // TODO: YEAH
ircprintf(newserver, "NICK oligosII");
newserver->printf("USER 1 2 3 4"); // TODO: YEAH
newserver->printf("NICK oligosII");
servers.push_back(newserver);
}
......@@ -157,27 +157,6 @@ void init_irc(int argc, char **argv) {
_new_server(argv[1]);
}
void ircprintf(server *server, const char *format, ...) {
char *intermediate;
va_list ap;
va_start(ap, format);
vasprintf(&intermediate, format, ap);
va_end(ap);
_D("-> \"%s\"\n", intermediate);
if(WRITE_BUF_LEN - server->nbytes_write < strlen(intermediate)+2) {
fprintf(stderr, "ERROR: Write buffer filled up!\n");
free(intermediate);
return;
}
server->nbytes_write += snprintf(server->writebuf + server->nbytes_write, WRITE_BUF_LEN - server->nbytes_write, "%s\r\n", intermediate);
_D("SENDQ: %llu/%d bytes consumed.\n", server->nbytes_write, WRITE_BUF_LEN);
free(intermediate);
}
void handle_irc(server *server, char *msgbuf) {
struct sender sender;
memset(&sender, 0, sizeof(sender));
......@@ -288,7 +267,7 @@ void event_loop() {
} else if(strncmp(buf, "conn ", 5) == 0) {
_new_server(buf+5);
//} else if(strncmp(buf, "send ", 5) == 0) {
//ircprintf(server, "%s", buf+5);
//server->printf("%s", buf+5);
}
}
......
......@@ -22,7 +22,6 @@ struct command_state {
#define READ_BUF_LEN 4096
#define WRITE_BUF_LEN (200*1024)
class server;
void ircprintf(server *server, const char *format, ...);
#include "server.h"
#endif /* end of include guard: OLIGOS_H */
......@@ -3,6 +3,8 @@
#include "dady/dady.h"
#include "server.h"
#include <stdarg.h>
/* {{{ DADY */
static int _serv_internal_tag_cb(uint32_t tagtype, uint32_t len, uint8_t *data, struct dady_callback *cb, server *server) {
switch(tagtype) {
......@@ -78,3 +80,24 @@ server::~server() {
if(this->nick)
free(this->nick);
}
void server::printf(const char *format, ...) {
char *intermediate;
va_list ap;
va_start(ap, format);
vasprintf(&intermediate, format, ap);
va_end(ap);
_D("-> \"%s\"\n", intermediate);
if(WRITE_BUF_LEN - nbytes_write < strlen(intermediate)+2) {
fprintf(stderr, "ERROR: Write buffer filled up!\n");
free(intermediate);
return;
}
nbytes_write += snprintf(writebuf + nbytes_write, WRITE_BUF_LEN - nbytes_write, "%s\r\n", intermediate);
_D("SENDQ: %llu/%d bytes consumed.\n", nbytes_write, WRITE_BUF_LEN);
free(intermediate);
}
......@@ -17,6 +17,8 @@ public:
server();
server(uint8_t *data, uint32_t size);
void printf(const char *format, ...);
uint8_t *freeze(uint32_t *outlen);
~server();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment