comparison mcabber/src/main.c @ 169:0ed6099b5a54

[/trunk] Changeset 181 by mikael * Default logging directory is now "$HOME/.mcabber/histo/" * Default configuration file is now "$HOME/.mcabber/mcabberrc" (~/.mcabberrc should still work) * Switch parsecfg.c to glib
author mikael
date Wed, 04 May 2005 19:33:03 +0000
parents b4921dbf8709
children ea5e101fd29e
comparison
equal deleted inserted replaced
168:6ad156673b19 169:0ed6099b5a54
6 #include <signal.h> 6 #include <signal.h>
7 #include <termios.h> 7 #include <termios.h>
8 #include <getopt.h> 8 #include <getopt.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/wait.h> 10 #include <sys/wait.h>
11 #include <glib.h>
11 12
12 #include "jabglue.h" 13 #include "jabglue.h"
13 #include "screen.h" 14 #include "screen.h"
14 #include "parsecfg.h" 15 #include "parsecfg.h"
15 #include "roster.h" 16 #include "roster.h"
65 } 66 }
66 67
67 char *compose_jid(const char *username, const char *servername, 68 char *compose_jid(const char *username, const char *servername,
68 const char *resource) 69 const char *resource)
69 { 70 {
70 char *jid = malloc(strlen(username)+strlen(servername)+strlen(resource)+3); 71 char *jid = g_new(strlen(username)+strlen(servername)+strlen(resource)+3);
71 strcpy(jid, username); 72 strcpy(jid, username);
72 strcat(jid, "@"); 73 strcat(jid, "@");
73 strcat(jid, servername); 74 strcat(jid, servername);
74 strcat(jid, "/"); 75 strcat(jid, "/");
75 strcat(jid, resource); 76 strcat(jid, resource);
82 printf(EMAIL "\n"); 83 printf(EMAIL "\n");
83 } 84 }
84 85
85 int main(int argc, char **argv) 86 int main(int argc, char **argv)
86 { 87 {
87 char configFile[4096]; 88 char *configFile = NULL;
88 char *username, *password, *resource; 89 char *username, *password, *resource;
89 char *servername, *portstring; 90 char *servername, *portstring;
90 char *jid; 91 char *jid;
91 char *optstring; 92 char *optstring;
92 int key; 93 int key;
102 ut_InitDebug(0, NULL); 103 ut_InitDebug(0, NULL);
103 104
104 ut_WriteLog("Setting signals handlers...\n"); 105 ut_WriteLog("Setting signals handlers...\n");
105 signal(SIGTERM, sig_handler); 106 signal(SIGTERM, sig_handler);
106 signal(SIGCHLD, sig_handler); 107 signal(SIGCHLD, sig_handler);
107
108 sprintf(configFile, "%s/.mcabberrc", getenv("HOME"));
109 108
110 /* Parse command line options */ 109 /* Parse command line options */
111 while (1) { 110 while (1) {
112 int c = getopt(argc, argv, "hf:"); 111 int c = getopt(argc, argv, "hf:");
113 if (c == -1) { 112 if (c == -1) {
117 case 'h': 116 case 'h':
118 printf("Usage: %s [-f mcabberrc_file]\n\n", argv[0]); 117 printf("Usage: %s [-f mcabberrc_file]\n\n", argv[0]);
119 printf("Thanks to AjMacias for cabber!\n\n"); 118 printf("Thanks to AjMacias for cabber!\n\n");
120 return 0; 119 return 0;
121 case 'f': 120 case 'f':
122 strncpy(configFile, optarg, 1024); 121 configFile = g_strdup(optarg);
123 break; 122 break;
124 } 123 }
125 } 124 }
126 125
127 ut_WriteLog("Setting config file: %s\n", configFile); 126 if (configFile)
128 127 ut_WriteLog("Setting config file: %s\n", configFile);
129 128
130 /* Parsing config file... */ 129 /* Parsing config file... */
131 ut_WriteLog("Parsing config file...\n"); 130 ut_WriteLog("Parsing config file...\n");
132 cfg_file(configFile); 131 cfg_file(configFile);
132 if (configFile) g_free(configFile);
133 133
134 optstring = cfg_read("debug"); 134 optstring = cfg_read("debug");
135 if (optstring) 135 if (optstring)
136 ut_InitDebug(1, optstring); 136 ut_InitDebug(1, optstring);
137 137
184 ut_WriteLog("Connecting to server: %s:%d\n", servername, port); 184 ut_WriteLog("Connecting to server: %s:%d\n", servername, port);
185 scr_LogPrint("Connecting to server: %s:%d", servername, port); 185 scr_LogPrint("Connecting to server: %s:%d", servername, port);
186 186
187 jid = compose_jid(username, servername, resource); 187 jid = compose_jid(username, servername, resource);
188 jc = jb_connect(jid, port, ssl, password); 188 jc = jb_connect(jid, port, ssl, password);
189 free(jid); 189 g_free(jid);
190 if (!jc) { 190 if (!jc) {
191 ut_WriteLog("\terror!!!\n"); 191 ut_WriteLog("\terror!!!\n");
192 fprintf(stderr, "Error connecting to (%s)\n", servername); 192 fprintf(stderr, "Error connecting to (%s)\n", servername);
193 scr_TerminateCurses(); 193 scr_TerminateCurses();
194 return -2; 194 return -2;