summaryrefslogtreecommitdiff
path: root/vchat-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'vchat-client.c')
-rwxr-xr-xvchat-client.c95
1 files changed, 29 insertions, 66 deletions
diff --git a/vchat-client.c b/vchat-client.c
index b7f993c..d4caf31 100755
--- a/vchat-client.c
+++ b/vchat-client.c
@@ -10,7 +10,7 @@
10 * without even the implied warranty of merchantability or fitness for a 10 * without even the implied warranty of merchantability or fitness for a
11 * particular purpose. In no event shall the copyright holder be liable for 11 * particular purpose. In no event shall the copyright holder be liable for
12 * any direct, indirect, incidental or special damages arising in any way out 12 * any direct, indirect, incidental or special damages arising in any way out
13 * of the use of this software. 13 * of the use of this software.
14 * 14 *
15 */ 15 */
16 16
@@ -24,7 +24,6 @@
24#include <stdio.h> 24#include <stdio.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <errno.h> 26#include <errno.h>
27#include <fcntl.h>
28#include <signal.h> 27#include <signal.h>
29#include <readline/readline.h> 28#include <readline/readline.h>
30#ifndef NO_LOCALE 29#ifndef NO_LOCALE
@@ -66,13 +65,13 @@ static void parsecfg(char *line) {
66 int bytes; 65 int bytes;
67 char *param=line; 66 char *param=line;
68 char *value=NULL; 67 char *value=NULL;
69 68
70 /* handle quotes value is empty, so we can use it */ 69 /* handle quotes value is empty, so we can use it */
71 value = strchr(line,'#'); 70 value = strchr(line,'#');
72 if (value) { /* the line contains a cute little quote */ 71 if (value) { /* the line contains a cute little quote */
73 value[0]='\0'; /* ignore the rest of the line */ 72 value[0]='\0'; /* ignore the rest of the line */
74 } 73 }
75 74
76 /* now split the line into two parts */ 75 /* now split the line into two parts */
77 value = strchr(line,'='); 76 value = strchr(line,'=');
78 if (!value) return; /* exit if strchr fails */ 77 if (!value) return; /* exit if strchr fails */
@@ -86,11 +85,11 @@ static void parsecfg(char *line) {
86 while ((value[bytes-1] == ' ')||(value[bytes-1] == '\t')) { 85 while ((value[bytes-1] == ' ')||(value[bytes-1] == '\t')) {
87 value[bytes-1] = '\0'; 86 value[bytes-1] = '\0';
88 bytes=strlen(value); 87 bytes=strlen(value);
89 } 88 }
90 /* bytes should be strlen(value) */ 89 /* bytes should be strlen(value) */
91 if ( value[bytes-1] == '"' ) value[bytes-1] = '\0'; 90 if ( value[bytes-1] == '"' ) value[bytes-1] = '\0';
92 if ( value[0] == '"' ) value++; 91 if ( value[0] == '"' ) value++;
93 92
94 /* "trim" param */ 93 /* "trim" param */
95 while ((param[0] == ' ')||(param[0] == '\t')) 94 while ((param[0] == ' ')||(param[0] == '\t'))
96 param++; 95 param++;
@@ -102,9 +101,9 @@ static void parsecfg(char *line) {
102 /* bytes should be strlen(param) */ 101 /* bytes should be strlen(param) */
103 if ( param[bytes-1] == '\"' ) param[bytes-1] = '\0'; 102 if ( param[bytes-1] == '\"' ) param[bytes-1] = '\0';
104 if ( param[0] == '\"' ) param++; 103 if ( param[0] == '\"' ) param++;
105 104
106 if ((!param)||(!value)) return; /* failsave */ 105 if ((!param)||(!value)) return; /* failsave */
107 106
108 //fprintf(stderr,"\"%s\" -> \"%s\"\n",param,value); 107 //fprintf(stderr,"\"%s\" -> \"%s\"\n",param,value);
109 setnoption(param,value); 108 setnoption(param,value);
110} 109}
@@ -174,63 +173,30 @@ static void parseknownhosts(char *line) {
174void 173void
175loadcfg (char *file,void (*lineparser) (char *)) 174loadcfg (char *file,void (*lineparser) (char *))
176{ 175{
177 int fd; 176 FILE *fh;
178 int bytes,bufoff=0;
179 char *tmp = NULL;
180#define BUFSIZE 4096 177#define BUFSIZE 4096
181 char buf[BUFSIZE]; /* data buffer */ 178 char buf[BUFSIZE]; /* data buffer */
182 char *ltmp = buf; 179 char *tildex = NULL, *t;
183 char *tildex = NULL; 180
184 buf[BUFSIZE-1] = '\0'; /* sanity stop */ 181 /* Check and expand filename then open file */
185
186 if (!file) return; 182 if (!file) return;
187 if (!file[0]) return; 183 tildex = tilde_expand( file );
188 if (file[0] == '~') 184 if (!tildex) return;
189 tildex = tilde_expand(file); 185 fh = fopen( tildex, "r" );
190 else 186 free( tildex );
191 tildex = file; 187
192 fd = open(tildex,O_RDONLY); 188 if (!fh) {
193 if (fd == -1) { 189 snprintf (errstr, TMPSTRSIZE, "Can't open config-file \"%s\": %s.", file, strerror(errno));
194 snprintf (errstr, TMPSTRSIZE, "Can't open config-file \"%s\": %s.", tildex, strerror(errno)); 190 return;
195 } else {
196 while ((bytes = read(fd,&buf[bufoff],BUFSIZE-bufoff-1))) {
197 if (bytes < 0) {
198 close(fd);
199 return;
200 } else {
201 /* terminate string */
202 buf[bytes + bufoff] = '\0';
203 /* as long as there are lines .. */
204 while ((tmp = strchr (ltmp, '\n')) != NULL) {
205 /* did the server send CR+LF instead of LF with the last line? */
206 if (tmp[-1] == '\r')
207 tmp[-1] = '\0';
208
209 /* remove newline from previous message, advance pointer of next
210 * message */
211 tmp[0] = '\0';
212 tmp++;
213
214 /* we have a last message? give away to line handler! */
215 if (ltmp[0])
216 {
217 lineparser(ltmp);
218 }
219
220 /* move line along .. */
221 ltmp = tmp;
222 }
223 /* buffer exhausted, move partial line to start of buffer and go
224 * on .. */
225 bufoff = (bytes+bufoff) - (ltmp-buf);
226 if (bufoff > 0)
227 memmove (buf, ltmp, bufoff);
228 else
229 bufoff = 0;
230 }
231 }
232 close(fd);
233 } 191 }
192
193 while ( fgets( buf, sizeof(buf), fh ) ) {
194 if( ( t = strchr( buf, '\n' ) ) )
195 *t = 0;
196 lineparser(buf);
197 }
198
199 fclose(fh);
234} 200}
235 201
236void 202void
@@ -463,7 +429,7 @@ void usage( char *name) {
463 printf ("usage: %s [-C config-file] [-F formats] [-l] [-z] [-s host] [-p port] [-c channel] [-n nickname]\n",name); 429 printf ("usage: %s [-C config-file] [-F formats] [-l] [-z] [-s host] [-p port] [-c channel] [-n nickname]\n",name);
464 puts (" -C load a second config-file, overriding the first one"); 430 puts (" -C load a second config-file, overriding the first one");
465 puts (" -F load format strings (skins) from this file"); 431 puts (" -F load format strings (skins) from this file");
466 puts (" -l local connect (no SSL + connects localhost:2323)"); 432 puts (" -l local connect (no SSL)");
467 puts (" -z don't use certificate files"); 433 puts (" -z don't use certificate files");
468 printf (" -s set server (default \"%s\")\n",getstroption(CF_SERVERHOST)); 434 printf (" -s set server (default \"%s\")\n",getstroption(CF_SERVERHOST));
469 printf (" -p set port (default %s)\n",getstroption(CF_SERVERPORT)); 435 printf (" -p set port (default %s)\n",getstroption(CF_SERVERPORT));
@@ -518,9 +484,6 @@ main (int argc, char **argv)
518 loadformats(GLOBAL_FORMAT_FILE); 484 loadformats(GLOBAL_FORMAT_FILE);
519 loadformats(getstroption (CF_FORMFILE)); 485 loadformats(getstroption (CF_FORMFILE));
520 486
521 if ( !getintoption(CF_USESSL) && !strcmp(getstroption(CF_SERVERPORT),"2325"))
522 setstroption(CF_SERVERPORT,"2323");
523
524 /* install signal handler */ 487 /* install signal handler */
525 signal (SIGINT, cleanup); 488 signal (SIGINT, cleanup);
526 signal (SIGHUP, cleanup); 489 signal (SIGHUP, cleanup);