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

ircprintf -> server::printf

parent 7a3d788e
...@@ -36,20 +36,20 @@ _COMMAND(copyover) { ...@@ -36,20 +36,20 @@ _COMMAND(copyover) {
} }
_COMMAND(ping) { _COMMAND(ping) {
ircprintf(server, "PRIVMSG %s :PONG", state->channel); server->printf("PRIVMSG %s :PONG", state->channel);
return 0; return 0;
} }
_COMMAND(report) { _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; return 0;
} }
_COMMAND(arguments) { _COMMAND(arguments) {
char **argvp = argv; char **argvp = argv;
ircprintf(server, "PRIVMSG %s :argc: %d", state->channel, argc); server->printf("PRIVMSG %s :argc: %d", state->channel, argc);
while(*argvp) { while(*argvp) {
ircprintf(server, "PRIVMSG %s :Argument: %s", state->channel, *argvp); server->printf("PRIVMSG %s :Argument: %s", state->channel, *argvp);
argvp++; argvp++;
} }
return 0; return 0;
......
...@@ -28,18 +28,18 @@ void dispatch_event(server *server, char *name, struct sender *sender, char *msg ...@@ -28,18 +28,18 @@ void dispatch_event(server *server, char *name, struct sender *sender, char *msg
_EVENT(001) { _EVENT(001) {
char *nick = strsep(&msgbuf, " "); char *nick = strsep(&msgbuf, " ");
server->nick = strdup(nick); server->nick = strdup(nick);
ircprintf(server, "JOIN #bacon"); server->printf("JOIN #bacon");
} }
// 433 Nickname In Use // 433 Nickname In Use
_EVENT(433) { _EVENT(433) {
strsep(&msgbuf, " "); strsep(&msgbuf, " ");
char *nick = strsep(&msgbuf, " "); char *nick = strsep(&msgbuf, " ");
ircprintf(server, "NICK %s_", nick); server->printf("NICK %s_", nick);
} }
_EVENT(PING) { _EVENT(PING) {
ircprintf(server, "PONG %s", msgbuf); server->printf("PONG %s", msgbuf);
} }
_EVENT(PRIVMSG) { _EVENT(PRIVMSG) {
...@@ -81,7 +81,7 @@ _EVENT(PRIVMSG) { ...@@ -81,7 +81,7 @@ _EVENT(PRIVMSG) {
state.channel = (priv ? sender->nick : recipient); state.channel = (priv ? sender->nick : recipient);
if(dispatch_command(server, commandname, argc, argv, &state) == -1) { 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); free(argv);
......
...@@ -53,7 +53,7 @@ void do_copyover(char *requester) { ...@@ -53,7 +53,7 @@ void do_copyover(char *requester) {
free(fn); free(fn);
//if(requester) // Yes, we're actually queueing this for when the copyover comes back and the socket is ready. Clever?! //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; uint8_t *tag_data = NULL;
uint32_t tags_size = 0; uint32_t tags_size = 0;
...@@ -148,8 +148,8 @@ void _new_server(char *hostname) { ...@@ -148,8 +148,8 @@ void _new_server(char *hostname) {
control_fd = 0; control_fd = 0;
_D("Got control fd %d\n", control_fd); _D("Got control fd %d\n", control_fd);
ircprintf(newserver, "USER 1 2 3 4"); // TODO: YEAH newserver->printf("USER 1 2 3 4"); // TODO: YEAH
ircprintf(newserver, "NICK oligosII"); newserver->printf("NICK oligosII");
servers.push_back(newserver); servers.push_back(newserver);
} }
...@@ -157,27 +157,6 @@ void init_irc(int argc, char **argv) { ...@@ -157,27 +157,6 @@ void init_irc(int argc, char **argv) {
_new_server(argv[1]); _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) { void handle_irc(server *server, char *msgbuf) {
struct sender sender; struct sender sender;
memset(&sender, 0, sizeof(sender)); memset(&sender, 0, sizeof(sender));
...@@ -288,7 +267,7 @@ void event_loop() { ...@@ -288,7 +267,7 @@ void event_loop() {
} else if(strncmp(buf, "conn ", 5) == 0) { } else if(strncmp(buf, "conn ", 5) == 0) {
_new_server(buf+5); _new_server(buf+5);
//} else if(strncmp(buf, "send ", 5) == 0) { //} else if(strncmp(buf, "send ", 5) == 0) {
//ircprintf(server, "%s", buf+5); //server->printf("%s", buf+5);
} }
} }
......
...@@ -22,7 +22,6 @@ struct command_state { ...@@ -22,7 +22,6 @@ struct command_state {
#define READ_BUF_LEN 4096 #define READ_BUF_LEN 4096
#define WRITE_BUF_LEN (200*1024) #define WRITE_BUF_LEN (200*1024)
class server; #include "server.h"
void ircprintf(server *server, const char *format, ...);
#endif /* end of include guard: OLIGOS_H */ #endif /* end of include guard: OLIGOS_H */
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include "dady/dady.h" #include "dady/dady.h"
#include "server.h" #include "server.h"
#include <stdarg.h>
/* {{{ DADY */ /* {{{ DADY */
static int _serv_internal_tag_cb(uint32_t tagtype, uint32_t len, uint8_t *data, struct dady_callback *cb, server *server) { static int _serv_internal_tag_cb(uint32_t tagtype, uint32_t len, uint8_t *data, struct dady_callback *cb, server *server) {
switch(tagtype) { switch(tagtype) {
...@@ -78,3 +80,24 @@ server::~server() { ...@@ -78,3 +80,24 @@ server::~server() {
if(this->nick) if(this->nick)
free(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: ...@@ -17,6 +17,8 @@ public:
server(); server();
server(uint8_t *data, uint32_t size); server(uint8_t *data, uint32_t size);
void printf(const char *format, ...);
uint8_t *freeze(uint32_t *outlen); uint8_t *freeze(uint32_t *outlen);
~server(); ~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