Move host, port, pass, webp to self

weechat-hashes
Curtis McEnroe 2018-12-02 23:22:18 -05:00
parent 0e1297e068
commit 452aeb5ecf
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
3 changed files with 22 additions and 33 deletions

25
chat.c
View File

@ -56,38 +56,33 @@ static char *prompt(const char *prompt) {
}
int main(int argc, char *argv[]) {
char *host = NULL;
char *port = "6697";
char *pass = NULL;
char *webirc = NULL;
int opt;
while (0 < (opt = getopt(argc, argv, "NW:h:j:l:n:p:r:u:vw:"))) {
switch (opt) {
break; case 'N': self.notify = true;
break; case 'W': webirc = strdup(optarg);
break; case 'h': host = strdup(optarg);
break; case 'W': freedup(&self.webp, optarg);
break; case 'h': freedup(&self.host, optarg);
break; case 'j': freedup(&self.join, optarg);
break; case 'l': logOpen(optarg);
break; case 'n': selfNick(optarg);
break; case 'p': port = strdup(optarg);
break; case 'n': freedup(&self.nick, optarg);
break; case 'p': freedup(&self.port, 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 'w': pass = strdup(optarg);
break; case 'w': freedup(&self.pass, optarg);
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.user) selfUser(self.nick);
if (!self.user) freedup(&self.user, self.nick);
if (!self.real) freedup(&self.real, self.nick);
inputTab();
uiInit();
uiDraw();
ircInit(host, port, pass, webirc);
ircInit();
eventLoop();
}

5
chat.h
View File

@ -31,7 +31,10 @@
#define errx(...) do { uiHide(); errx(__VA_ARGS__); } while (0)
struct {
char *host;
char *port;
char *pass;
char *webp;
char *nick;
char *user;
char *real;
@ -103,7 +106,7 @@ void handle(char *line);
void input(struct Tag tag, char *line);
void inputTab(void);
void ircInit(char *host, char *port, char *pass, char *webPass);
void ircInit(void);
int ircConnect(void);
bool ircRead(void);
void ircWrite(const char *ptr, size_t len);

25
irc.c
View File

@ -31,23 +31,14 @@
#include "chat.h"
static struct {
char *host;
char *port;
char *pass;
char *webirc;
int sock;
struct tls_config *config;
struct tls *client;
int sock;
} irc = {
.sock = -1,
};
void ircInit(char *host, char *port, char *pass, char *webirc) {
irc.host = host;
irc.port = port;
irc.pass = pass;
irc.webirc = webirc;
void ircInit(void) {
irc.config = tls_config_new();
int error = tls_config_set_ciphers(irc.config, "compat");
if (error) errx(EX_SOFTWARE, "tls_config");
@ -63,7 +54,7 @@ int ircConnect(void) {
error = tls_configure(irc.client, irc.config);
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 hints = {
@ -71,7 +62,7 @@ int ircConnect(void) {
.ai_socktype = SOCK_STREAM,
.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));
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);
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));
const char *ssh = getenv("SSH_CLIENT");
if (irc.webirc && ssh) {
if (self.webp && ssh) {
int len = strlen(ssh);
const char *sp = strchr(ssh, ' ');
if (sp) len = sp - ssh;
ircFmt(
"WEBIRC %s %s %.*s %.*s\r\n",
irc.webirc, self.user, len, ssh, len, ssh
self.webp, self.user, len, ssh, len, ssh
);
}
/// FIXME
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("USER %s 0 * :%s\r\n", self.user, self.real);