Move host, port, pass, webp to self
parent
0e1297e068
commit
452aeb5ecf
25
chat.c
25
chat.c
|
@ -56,38 +56,33 @@ static char *prompt(const char *prompt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char *host = NULL;
|
|
||||||
char *port = "6697";
|
|
||||||
char *pass = NULL;
|
|
||||||
char *webirc = NULL;
|
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while (0 < (opt = getopt(argc, argv, "NW:h:j:l:n:p:r:u:vw:"))) {
|
while (0 < (opt = getopt(argc, argv, "NW:h:j:l:n:p:r:u:vw:"))) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
break; case 'N': self.notify = true;
|
break; case 'N': self.notify = true;
|
||||||
break; case 'W': webirc = strdup(optarg);
|
break; case 'W': freedup(&self.webp, optarg);
|
||||||
break; case 'h': host = strdup(optarg);
|
break; case 'h': freedup(&self.host, optarg);
|
||||||
break; case 'j': freedup(&self.join, optarg);
|
break; case 'j': freedup(&self.join, optarg);
|
||||||
break; case 'l': logOpen(optarg);
|
break; case 'l': logOpen(optarg);
|
||||||
break; case 'n': selfNick(optarg);
|
break; case 'n': freedup(&self.nick, optarg);
|
||||||
break; case 'p': port = strdup(optarg);
|
break; case 'p': freedup(&self.port, optarg);
|
||||||
break; case 'r': freedup(&self.real, optarg);
|
break; case 'r': freedup(&self.real, optarg);
|
||||||
break; case 'u': selfUser(optarg);
|
break; case 'u': freedup(&self.user, optarg);
|
||||||
break; case 'v': self.verbose = true;
|
break; case 'v': self.verbose = true;
|
||||||
break; case 'w': pass = strdup(optarg);
|
break; case 'w': freedup(&self.pass, optarg);
|
||||||
break; default: return EX_USAGE;
|
break; default: return EX_USAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!port) err(EX_OSERR, "strdup");
|
|
||||||
|
|
||||||
if (!host) host = prompt("Host: ");
|
if (!self.host) self.host = prompt("Host: ");
|
||||||
|
if (!self.port) freedup(&self.port, "6697");
|
||||||
if (!self.nick) self.nick = prompt("Name: ");
|
if (!self.nick) self.nick = prompt("Name: ");
|
||||||
if (!self.user) selfUser(self.nick);
|
if (!self.user) freedup(&self.user, self.nick);
|
||||||
if (!self.real) freedup(&self.real, self.nick);
|
if (!self.real) freedup(&self.real, self.nick);
|
||||||
|
|
||||||
inputTab();
|
inputTab();
|
||||||
uiInit();
|
uiInit();
|
||||||
uiDraw();
|
uiDraw();
|
||||||
ircInit(host, port, pass, webirc);
|
ircInit();
|
||||||
eventLoop();
|
eventLoop();
|
||||||
}
|
}
|
||||||
|
|
5
chat.h
5
chat.h
|
@ -31,7 +31,10 @@
|
||||||
#define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0)
|
#define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0)
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
char *host;
|
||||||
char *port;
|
char *port;
|
||||||
|
char *pass;
|
||||||
|
char *webp;
|
||||||
char *nick;
|
char *nick;
|
||||||
char *user;
|
char *user;
|
||||||
char *real;
|
char *real;
|
||||||
|
@ -103,7 +106,7 @@ void handle(char *line);
|
||||||
void input(struct Tag tag, char *line);
|
void input(struct Tag tag, char *line);
|
||||||
void inputTab(void);
|
void inputTab(void);
|
||||||
|
|
||||||
void ircInit(char *host, char *port, char *pass, char *webPass);
|
void ircInit(void);
|
||||||
int ircConnect(void);
|
int ircConnect(void);
|
||||||
bool ircRead(void);
|
bool ircRead(void);
|
||||||
void ircWrite(const char *ptr, size_t len);
|
void ircWrite(const char *ptr, size_t len);
|
||||||
|
|
25
irc.c
25
irc.c
|
@ -31,23 +31,14 @@
|
||||||
#include "chat.h"
|
#include "chat.h"
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
char *host;
|
|
||||||
char *port;
|
|
||||||
char *pass;
|
|
||||||
char *webirc;
|
|
||||||
int sock;
|
|
||||||
struct tls_config *config;
|
struct tls_config *config;
|
||||||
struct tls *client;
|
struct tls *client;
|
||||||
|
int sock;
|
||||||
} irc = {
|
} irc = {
|
||||||
.sock = -1,
|
.sock = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
void ircInit(char *host, char *port, char *pass, char *webirc) {
|
void ircInit(void) {
|
||||||
irc.host = host;
|
|
||||||
irc.port = port;
|
|
||||||
irc.pass = pass;
|
|
||||||
irc.webirc = webirc;
|
|
||||||
|
|
||||||
irc.config = tls_config_new();
|
irc.config = tls_config_new();
|
||||||
int error = tls_config_set_ciphers(irc.config, "compat");
|
int error = tls_config_set_ciphers(irc.config, "compat");
|
||||||
if (error) errx(EX_SOFTWARE, "tls_config");
|
if (error) errx(EX_SOFTWARE, "tls_config");
|
||||||
|
@ -63,7 +54,7 @@ int ircConnect(void) {
|
||||||
error = tls_configure(irc.client, irc.config);
|
error = tls_configure(irc.client, irc.config);
|
||||||
if (error) errx(EX_SOFTWARE, "tls_configure: %s", tls_error(irc.client));
|
if (error) errx(EX_SOFTWARE, "tls_configure: %s", tls_error(irc.client));
|
||||||
|
|
||||||
uiFmt(TagStatus, UICold, "Traveling to %s", irc.host);
|
uiFmt(TagStatus, UICold, "Traveling to %s", self.host);
|
||||||
|
|
||||||
struct addrinfo *head;
|
struct addrinfo *head;
|
||||||
struct addrinfo hints = {
|
struct addrinfo hints = {
|
||||||
|
@ -71,7 +62,7 @@ int ircConnect(void) {
|
||||||
.ai_socktype = SOCK_STREAM,
|
.ai_socktype = SOCK_STREAM,
|
||||||
.ai_protocol = IPPROTO_TCP,
|
.ai_protocol = IPPROTO_TCP,
|
||||||
};
|
};
|
||||||
error = getaddrinfo(irc.host, irc.port, &hints, &head);
|
error = getaddrinfo(self.host, self.port, &hints, &head);
|
||||||
if (error) errx(EX_NOHOST, "getaddrinfo: %s", gai_strerror(error));
|
if (error) errx(EX_NOHOST, "getaddrinfo: %s", gai_strerror(error));
|
||||||
|
|
||||||
for (struct addrinfo *ai = head; ai; ai = ai->ai_next) {
|
for (struct addrinfo *ai = head; ai; ai = ai->ai_next) {
|
||||||
|
@ -90,24 +81,24 @@ int ircConnect(void) {
|
||||||
error = fcntl(irc.sock, F_SETFD, FD_CLOEXEC);
|
error = fcntl(irc.sock, F_SETFD, FD_CLOEXEC);
|
||||||
if (error) err(EX_IOERR, "fcntl");
|
if (error) err(EX_IOERR, "fcntl");
|
||||||
|
|
||||||
error = tls_connect_socket(irc.client, irc.sock, irc.host);
|
error = tls_connect_socket(irc.client, irc.sock, self.host);
|
||||||
if (error) errx(EX_PROTOCOL, "tls_connect: %s", tls_error(irc.client));
|
if (error) errx(EX_PROTOCOL, "tls_connect: %s", tls_error(irc.client));
|
||||||
|
|
||||||
const char *ssh = getenv("SSH_CLIENT");
|
const char *ssh = getenv("SSH_CLIENT");
|
||||||
if (irc.webirc && ssh) {
|
if (self.webp && ssh) {
|
||||||
int len = strlen(ssh);
|
int len = strlen(ssh);
|
||||||
const char *sp = strchr(ssh, ' ');
|
const char *sp = strchr(ssh, ' ');
|
||||||
if (sp) len = sp - ssh;
|
if (sp) len = sp - ssh;
|
||||||
ircFmt(
|
ircFmt(
|
||||||
"WEBIRC %s %s %.*s %.*s\r\n",
|
"WEBIRC %s %s %.*s %.*s\r\n",
|
||||||
irc.webirc, self.user, len, ssh, len, ssh
|
self.webp, self.user, len, ssh, len, ssh
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// FIXME
|
/// FIXME
|
||||||
if (self.user[0] == '~') selfUser(&self.user[1]);
|
if (self.user[0] == '~') selfUser(&self.user[1]);
|
||||||
|
|
||||||
if (irc.pass) ircFmt("PASS :%s\r\n", irc.pass);
|
if (self.pass) ircFmt("PASS :%s\r\n", self.pass);
|
||||||
ircFmt("NICK %s\r\n", self.nick);
|
ircFmt("NICK %s\r\n", self.nick);
|
||||||
ircFmt("USER %s 0 * :%s\r\n", self.user, self.real);
|
ircFmt("USER %s 0 * :%s\r\n", self.user, self.real);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue