diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-04-27 14:54:50 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-04-27 14:54:50 +0200 |
commit | 0d2646b246def5144dee17963d165fb222b27d26 (patch) | |
tree | 21475f9850d31a83d65e5f6692daca28355ae5c5 /main.c | |
parent | initial commit (diff) | |
download | ircxmpp-0d2646b246def5144dee17963d165fb222b27d26.tar ircxmpp-0d2646b246def5144dee17963d165fb222b27d26.tar.gz ircxmpp-0d2646b246def5144dee17963d165fb222b27d26.tar.bz2 ircxmpp-0d2646b246def5144dee17963d165fb222b27d26.tar.lz ircxmpp-0d2646b246def5144dee17963d165fb222b27d26.tar.xz ircxmpp-0d2646b246def5144dee17963d165fb222b27d26.tar.zst ircxmpp-0d2646b246def5144dee17963d165fb222b27d26.zip |
Diffstat (limited to '')
-rw-r--r-- | main.c | 40 |
1 files changed, 26 insertions, 14 deletions
@@ -101,7 +101,7 @@ void bridge_forward (const char * from, const char * msg, struct ircxmpp * ircxm } else bridge = *bridge_resp; if (side == IRC) { - irc_cmd_join(bridge->irc, ircxmpp->channel, NULL /* password */); /* da smo gotovo joinani */ + irc_cmd_join(bridge->irc, ircxmpp->channel, ircxmpp->channel_password); irc_run_once(bridge); if (msg) irc_cmd_msg(bridge->irc, ircxmpp->channel, msg); @@ -244,13 +244,13 @@ void dump_event (irc_session_t * s, const char * e, const char * o, const char * void event_connect (irc_session_t * s, const char * e, const char * o, const char ** p, unsigned c) { dump_event(s, e, o, p, c); struct bridge * bridge = (struct bridge *) irc_get_ctx(s); - irc_cmd_join(s, bridge->ircxmpp->channel, NULL /* password */); + irc_cmd_join(s, bridge->ircxmpp->channel, bridge->ircxmpp->channel_password); } void event_connect_control (irc_session_t * s, const char * e, const char * o, const char ** p, unsigned c) { dump_event(s, e, o, p, c); struct ircxmpp * ircxmpp = (struct ircxmpp *) irc_get_ctx(s); - irc_cmd_join(s, ircxmpp->channel, NULL); + irc_cmd_join(s, ircxmpp->channel, ircxmpp->channel_password); } void event_privmsg (irc_session_t * s, const char * e, const char * o, const char ** p, unsigned c) { dump_event(s, e, o, p, c); /* SAME FOR _control. do NOT use irc_get_ctx here!!! */ @@ -300,16 +300,25 @@ void event_join_control (irc_session_t * s, const char * e, const char * o, cons void event_nick_control (irc_session_t * s, const char * e, const char * o, const char ** p, unsigned c) { dump_event(s, e, o, p, c); /* o je originalen nick, p[0] je nov nick */ + if (!c) + return; struct ircxmpp * ircxmpp = (struct ircxmpp *) irc_get_ctx(s); struct bridge ** bridge = find_bridge(&ircxmpp->bridges, o /* indeed n!u@h */, IRC); if (!bridge || !*bridge) return; free_bridge(bridge, "nick change from irc"); - bridge_forward(o, NULL, ircxmpp, XMPP); /* and now connect */ + char buf[512]; + snprintf(buf, 512, "%s%s", p[0], strchr(o, '!') ? strchr(o, '!') + : "neznan uporabnik@neznan strežnik"); + bridge_forward(buf, NULL, ircxmpp, XMPP); /* and now connect */ } void event_topic_control (irc_session_t * s, const char * e, const char * o, const char ** p, unsigned c) { dump_event(s, e, o, p, c); /* o je avtor, p[0] je kanal, p[1] je nova tema/zadeva */ + struct ircxmpp * ircxmpp = (struct ircxmpp *) irc_get_ctx(s); + char buf[1024]; + snprintf(buf, 1024, "/me je nastavil IRC temo na: %s", p[1]); + bridge_forward(o, buf, ircxmpp, XMPP); } /* TODO */ void event_numeric (irc_session_t * s, unsigned int e, const char * o, const char ** p, unsigned c) { char b[512]; @@ -494,21 +503,24 @@ int shouldexit = 0; void signalhandler (int s) { shouldexit += s+1; /* only for -Wunused-parameter */ } -int main (int argc, char ** argv) { +int main (void) { srand(time(NULL)); struct ircxmpp ircxmpp; memset(&ircxmpp, '\0', sizeof(ircxmpp)); xmpp_log_t *log; - if (argc != 1+6) { - fprintf(stderr, "Usage: ircxmpp <jid> <pass> <hostname> <port> <channel> <muc>\n"); + if (!getenv("IX_JID") || !getenv("IX_PASS") || !getenv("IX_HOST") || !getenv("IX_PORT") + || !getenv("IX_CHANNEL") || !getenv("IX_MUC")) { + fprintf(stderr, "Usage: IX_JID=jid@xmpp.server IX_PASS=pass IX_HOST=irc.server " + "IX_PORT=6666 IX_CHANNEL=#channel IX_MUC=muc@xmpp.srv ircxmpp\n"); return 1; } - ircxmpp.jid = argv[1]; - ircxmpp.password = argv[2]; - ircxmpp.hostname = argv[3]; - ircxmpp.port = atoi(argv[4]); - ircxmpp.channel = argv[5]; - ircxmpp.muc = argv[6]; + ircxmpp.jid = getenv("IX_JID"); + ircxmpp.password = getenv("IX_PASS"); + ircxmpp.hostname = getenv("IX_HOST"); + ircxmpp.port = atoi(getenv("IX_PORT")); + ircxmpp.channel = getenv("IX_CHANNEL"); + ircxmpp.muc = getenv("IX_MUC"); + ircxmpp.channel_password = getenv("IX_CHPASS"); xmpp_initialize(); log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); init_irc_control(&ircxmpp); @@ -574,7 +586,7 @@ cont: } struct timespec ts = { .tv_sec = 0, - .tv_nsec = 1e8 /* 0.1s per event loop */ + .tv_nsec = getenv("IX_LOOPDELAY") ? atoi(getenv("IX_LOOPDELAY"))/1000 : 1e8 }; nanosleep(&ts, NULL); } |