--- a/.hgignore Sun Jul 10 15:47:31 2005 +0100
+++ b/.hgignore Sun Jul 10 22:36:55 2005 +0100
@@ -9,7 +9,7 @@
\.sw.($|/)
^mcabber/lastchange$
-^mcabber/cscope.out$
+/cscope.out$
^mcabber/src/mcabber$
(^|/)Makefile($|/)
(^|/)config\.(h(\.in|)|log|cache|guess|status)($|/)
--- a/mcabber/TODO Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/TODO Sun Jul 10 22:36:55 2005 +0100
@@ -45,7 +45,7 @@
- /say_to <jid> blabla
- /info [jid]
(request info to the server if the buddy is not in the roster)
- - /server connect|disconnect|register|unregister
+ - /server register|unregister
- /auth request|send [jid]
- /search <jid>|name
(server search)
--- a/mcabber/doc/mcabber.1 Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/doc/mcabber.1 Sun Jul 10 22:36:55 2005 +0100
@@ -56,7 +56,7 @@
.SH "OPTIONS"
.TP
---help, \-h
+\-\-help, \-h
Quick help usage message
.TP
@@ -130,10 +130,18 @@
The clear command is actually an alias for "/buffer clear"\&.
.TP
+\fB/connect\fR
+Establish connection to the Jabber server\&.
+
+.TP
\fB/del\fR
Delete the current buddy from our roster, unsubscribe from its presence notification and unsubscribe it from ours\&.
.TP
+\fB/disconnect\fR
+Terminate connection to the Jabber server\&. Note: the roster is only available when the connection to the server is active, so the buddylist is empty when disconnected\&.
+
+.TP
\fB/group\fR fold|unfold|toggle
The group command changes the current group display\&.
--- a/mcabber/doc/mcabber.1.html Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/doc/mcabber.1.html Sun Jul 10 22:36:55 2005 +0100
@@ -260,6 +260,12 @@
The <b>clear</b> command is actually an alias for "/buffer clear".
</dd>
<dt><b>
+/connect
+</b></dt>
+<dd>
+ Establish connection to the Jabber server.
+</dd>
+<dt><b>
/del
</b></dt>
<dd>
@@ -267,6 +273,14 @@
notification and unsubscribe it from ours.
</dd>
<dt><b>
+/disconnect
+</b></dt>
+<dd>
+ Terminate connection to the Jabber server. Note: the roster is only
+ available when the connection to the server is active, so the
+ buddylist is empty when disconnected.
+</dd>
+<dt><b>
/group fold|unfold|toggle
</b></dt>
<dd>
@@ -488,7 +502,7 @@
<div id="footer">
<p>
Version 0.6.2<br />
-Last updated 08-Jul-2005 23:29:01 CEST
+Last updated 10-Jul-2005 16:33:35 CEST
</p>
</div>
</div>
--- a/mcabber/doc/mcabber.1.txt Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/doc/mcabber.1.txt Sun Jul 10 22:36:55 2005 +0100
@@ -110,10 +110,18 @@
/clear::
The 'clear' command is actually an alias for "/buffer clear".
+/connect::
+ Establish connection to the Jabber server.
+
/del::
Delete the current buddy from our roster, unsubscribe from its presence
notification and unsubscribe it from ours.
+/disconnect::
+ Terminate connection to the Jabber server. Note: the roster is only
+ available when the connection to the server is active, so the
+ buddylist is empty when disconnected.
+
/group fold|unfold|toggle::
The 'group' command changes the current group display.
--- a/mcabber/src/commands.c Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/src/commands.c Sun Jul 10 22:36:55 2005 +0100
@@ -48,6 +48,8 @@
void do_set(char *arg);
void do_alias(char *arg);
void do_bind(char *arg);
+void do_connect(char *arg);
+void do_disconnect(char *arg);
// Global variable for the commands list
static GSList *Commands;
@@ -79,7 +81,9 @@
cmd_add("buffer", "Manipulate current buddy's buffer (chat window)",
COMPL_BUFFER, 0, &do_buffer);
cmd_add("clear", "Clear the dialog window", 0, 0, &do_clear);
+ cmd_add("connect", "Connect to the server", 0, 0, &do_connect);
cmd_add("del", "Delete the current buddy", 0, 0, &do_del);
+ cmd_add("disconnect", "Disconnect from server", 0, 0, &do_disconnect);
cmd_add("group", "Change group display settings", COMPL_GROUP, 0, &do_group);
//cmd_add("help", "Display some help", COMPL_CMD, 0, NULL);
cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info);
@@ -769,3 +773,13 @@
settings_set(SETTINGS_TYPE_BINDING, keycode, value);
}
+void do_connect(char *arg)
+{
+ mcabber_connect();
+}
+
+void do_disconnect(char *arg)
+{
+ jb_disconnect();
+}
+
--- a/mcabber/src/commands.h Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/src/commands.h Sun Jul 10 22:36:55 2005 +0100
@@ -17,5 +17,7 @@
int process_command(char *line);
char *expandalias(char *line);
+extern void mcabber_connect(void);
+
#endif /* __COMMANDS_H__ */
--- a/mcabber/src/jabglue.c Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/src/jabglue.c Sun Jul 10 22:36:55 2005 +0100
@@ -40,7 +40,7 @@
time_t LastPingTime;
unsigned int KeepaliveDelay;
static unsigned int prio;
-static int s_id = 1; // FIXME which use??
+static int s_id;
static int regmode, regdone;
static enum imstatus mystatus = offline;
unsigned char online;
@@ -117,6 +117,19 @@
return alias;
}
+char *compose_jid(const char *username, const char *servername,
+ const char *resource)
+{
+ char *jid = g_new(char,
+ strlen(username)+strlen(servername)+strlen(resource)+3);
+ strcpy(jid, username);
+ strcat(jid, "@");
+ strcat(jid, servername);
+ strcat(jid, "/");
+ strcat(jid, resource);
+ return jid;
+}
+
jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass)
{
if (!port) {
@@ -126,16 +139,18 @@
port = JABBERPORT;
}
- if (jc)
- free(jc);
+ //if (jc)
+ // free(jc); XXX
+ s_id = 1;
jc = jab_new((char*)jid, (char*)pass, port, ssl);
+ /* These 3 functions can deal with a NULL jc, no worry... */
jab_logger(jc, file_logger);
jab_packet_handler(jc, &packethandler);
jab_state_handler(jc, &statehandler);
- if (jc->user) {
+ if (jc && jc->user) {
online = TRUE;
jstate = STATE_CONNECTING;
statehandler(0, -1);
@@ -147,7 +162,12 @@
void jb_disconnect(void)
{
+ if (!jc) return;
+
statehandler(jc, JCONN_STATE_OFF);
+ jab_delete(jc);
+ //free(jc); XXX
+ jc = NULL;
}
inline void jb_reset_keepalive()
--- a/mcabber/src/jabglue.h Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/src/jabglue.h Sun Jul 10 22:36:55 2005 +0100
@@ -36,6 +36,8 @@
search
};
+char *compose_jid(const char *username, const char *servername,
+ const char *resource);
jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass);
void jb_disconnect(void);
void jb_main();
--- a/mcabber/src/main.c Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/src/main.c Sun Jul 10 22:36:55 2005 +0100
@@ -34,9 +34,8 @@
// ut_WriteLog("Error in waitpid: errno=%d\n", errno);
signal(SIGCHLD, sig_handler);
} else if (signum == SIGTERM) {
- // bud_TerminateBuddies();
+ jb_disconnect();
scr_TerminateCurses();
- jb_disconnect();
printf("Killed by SIGTERM\nBye!\n");
exit(EXIT_SUCCESS);
} else {
@@ -66,17 +65,52 @@
return (ssize_t)nread;
}
-char *compose_jid(const char *username, const char *servername,
- const char *resource)
+void mcabber_connect(void)
{
- char *jid = g_new(char,
- strlen(username)+strlen(servername)+strlen(resource)+3);
- strcpy(jid, username);
- strcat(jid, "@");
- strcat(jid, servername);
- strcat(jid, "/");
- strcat(jid, resource);
- return jid;
+ const char *username, *password, *resource, *servername;
+ char *jid;
+ int ssl;
+ unsigned int port;
+
+ servername = settings_opt_get("server");
+ username = settings_opt_get("username");
+ password = settings_opt_get("password");
+ resource = settings_opt_get("resource");
+
+ if (!servername) {
+ scr_LogPrint("Server name has not been specified!\n");
+ return;
+ }
+ if (!username) {
+ scr_LogPrint("User name has not been specified!\n");
+ return;
+ }
+ if (!password) {
+ scr_LogPrint("Password has not been specified!\n");
+ return;
+ }
+ if (!resource)
+ resource = "mcabber";
+
+ ssl = (settings_opt_get_int("ssl") > 0);
+ port = (unsigned int) settings_opt_get_int("port");
+
+ jb_set_priority(settings_opt_get_int("priority"));
+
+ /* Connect to server */
+ ut_WriteLog("Connecting to server: %s:%d\n", servername, port);
+ scr_LogPrint("Connecting to server: %s:%d", servername, port);
+
+ jid = compose_jid(username, servername, resource);
+ jc = jb_connect(jid, port, ssl, password);
+ g_free(jid);
+
+ if (!jc) {
+ ut_WriteLog("\tConnection error!!!\n");
+ scr_LogPrint("Error connecting to (%s)\n", servername);
+ }
+
+ jb_reset_keepalive();
}
void credits(void)
@@ -88,20 +122,17 @@
int main(int argc, char **argv)
{
char *configFile = NULL;
- const char *username, *password, *resource, *servername;
- char *jid;
const char *optstring;
int optval, optval2;
- int ssl;
int key;
- unsigned int port;
unsigned int ping;
int ret = 0;
unsigned int refresh = 0;
credits();
- /* SET THIS >0 TO ENABLE LOG */
+ /* Set this >0 to enable log */
+ /* Note: debug can be enabled via the config file */
ut_InitDebug(0, NULL);
ut_WriteLog("Setting signals handlers...\n");
@@ -136,28 +167,20 @@
optstring = settings_opt_get("debug");
if (optstring) ut_InitDebug(1, optstring);
- servername = settings_opt_get("server");
- username = settings_opt_get("username");
- password = settings_opt_get("password");
- resource = settings_opt_get("resource");
+ // If no password is stored, we ask for it before entering
+ // ncurses mode
+ if (!settings_opt_get("password")) {
+ char *password, *p;
+ size_t passsize = 64;
+ printf("Please enter password: ");
+ my_getpass((char**)&password, &passsize);
+ printf("\n");
+ for (p = (char*)password; *p; p++)
+ ;
+ for ( ; p > (char*)password ; p--)
+ if (*p == '\n' || *p == '\r') *p = 0;
- if (!servername) {
- printf("Server name has not been specified in the config file!\n");
- return -1;
- }
- if (!username) {
- printf("User name has not been specified in the config file!\n");
- return -1;
- }
- if (!password) {
- char *p;
- size_t passsize = 64;
- printf("Please enter password: ");
- my_getpass((char**)&password, &passsize);
- printf("\n");
- for (p = (char*)password; *p; p++);
- for ( ; p > (char*)password ; p--)
- if (*p == '\n' || *p == '\r') *p = 0;
+ settings_set(SETTINGS_TYPE_OPTION, "password", password);
}
/* Initialize N-Curses */
@@ -170,32 +193,12 @@
optval = (settings_opt_get_int("logging") > 0);
optval2 = (settings_opt_get_int("load_logs") > 0);
if (optval || optval2)
- hlog_enable(optval, settings_opt_get("logging_dir"),
- optval2);
+ hlog_enable(optval, settings_opt_get("logging_dir"), optval2);
optstring = settings_opt_get("events_command");
if (optstring)
hk_ext_cmd_init(optstring);
- ssl = (settings_opt_get_int("ssl") > 0);
- port = (unsigned int) settings_opt_get_int("port");
-
- jb_set_priority(settings_opt_get_int("priority"));
-
- /* Connect to server */
- ut_WriteLog("Connecting to server: %s:%d\n", servername, port);
- scr_LogPrint("Connecting to server: %s:%d", servername, port);
-
- jid = compose_jid(username, servername, resource);
- jc = jb_connect(jid, port, ssl, password);
- g_free(jid);
- if (!jc) {
- ut_WriteLog("\terror!!!\n");
- fprintf(stderr, "Error connecting to (%s)\n", servername);
- scr_TerminateCurses();
- return -2;
- }
-
ping = 40;
if (settings_opt_get("pinginterval"))
ping = (unsigned int) settings_opt_get_int("pinginterval");
@@ -205,13 +208,15 @@
if (settings_opt_get_int("hide_offline_buddies") > 0)
buddylist_set_hide_offline_buddies(TRUE);
+ // Connection
+ mcabber_connect();
+
/* Initialize commands system */
cmd_init();
ut_WriteLog("Entering into main loop...\n\n");
ut_WriteLog("Ready to send/receive messages...\n");
- jb_reset_keepalive();
while (ret != 255) {
key = scr_Getch();
@@ -233,7 +238,6 @@
}
jb_disconnect();
- //bud_TerminateBuddies();
scr_TerminateCurses();
printf("\n\nHave a nice day!\nBye!\n");
--- a/mcabber/src/parsecfg.c Sun Jul 10 15:47:31 2005 +0100
+++ b/mcabber/src/parsecfg.c Sun Jul 10 22:36:55 2005 +0100
@@ -8,6 +8,11 @@
#include "settings.h"
#include "utils.h"
+// cfg_file(filename)
+// Read and parse config file "filename". If filename is NULL,
+// try to open the configuration file at the default locations.
+//
+// This function comes from Cabber, and has been slightly modified.
int cfg_file(char *filename)
{
FILE *fp;