Changeset b7ee89b
- Timestamp:
- Oct 17, 2009, 6:08:15 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 6ea3890
- Parents:
- 435001d
- git-author:
- Karl Ramm <kcr@1ts.org> (09/24/09 11:05:55)
- git-committer:
- Karl Ramm <kcr@1ts.org> (10/17/09 18:08:15)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
functions.c
r08e414a rb7ee89b 1363 1363 owl_fmtext fm; 1364 1364 FILE *file; 1365 char buff[1024];1365 char *s = NULL; 1366 1366 1367 1367 file=fopen(filename, "r"); … … 1372 1372 1373 1373 owl_fmtext_init_null(&fm); 1374 while (fgets(buff, 1024, file)) { 1375 owl_fmtext_append_normal(&fm, buff); 1376 /* owl_fmtext_append_normal(&fm, "\n"); */ 1377 } 1374 while (owl_getline(&s, file)) 1375 owl_fmtext_append_normal(&fm, s); 1376 owl_free(s); 1378 1377 1379 1378 owl_function_popless_fmtext(&fm); … … 2022 2021 const char *redirect = " 2>&1 < /dev/null"; 2023 2022 char *newbuff; 2024 char *out, buff2[1024]; 2025 int size; 2023 char *out; 2026 2024 FILE *p; 2027 2025 … … 2041 2039 owl_popexec_new(newbuff); 2042 2040 } else { 2043 p=popen(newbuff, "r"); 2044 out=owl_malloc(1024); 2045 size=1024; 2046 strcpy(out, ""); 2047 while (fgets(buff2, 1024, p)!=NULL) { 2048 size+=1024; 2049 out=owl_realloc(out, size); 2050 strcat(out, buff2); 2051 } 2041 p = popen(newbuff, "r"); 2042 out = owl_slurp(p); 2052 2043 pclose(p); 2053 2044 … … 3338 3329 char *path; 3339 3330 FILE *file; 3340 char buff[LINE];3331 char *s = NULL; 3341 3332 int fail_silent = 0; 3342 3333 … … 3347 3338 path = owl_util_makepath(filename); 3348 3339 } 3349 file =fopen(path, "r");3340 file = fopen(path, "r"); 3350 3341 owl_free(path); 3351 3342 if (!file) { … … 3355 3346 return; 3356 3347 } 3357 while (fgets(buff, LINE, file)!=NULL) { 3358 if (buff[0] == '\0' || buff[0] == '#') continue; 3359 if (buff[strlen(buff) - 1] == '\n') 3360 buff[strlen(buff) - 1] = '\0'; 3361 owl_function_command(buff); 3362 } 3348 while (owl_getline_chomp(&s, file)) { 3349 if (s[0] == '\0' || s[0] == '#') 3350 continue; 3351 owl_function_command(s); 3352 } 3353 3354 owl_free(s); 3363 3355 fclose(file); 3364 3356 } -
zephyr.c
rdcc3f80 rb7ee89b 246 246 FILE *file; 247 247 char *tmp, *start; 248 char buffer[1024], subsfile[1024]; 248 char *buffer = NULL; 249 char *subsfile; 249 250 ZSubscription_t *subs; 250 251 int subSize = 1024; 251 int count , ret;252 int count; 252 253 struct stat statbuff; 253 254 254 255 subs = owl_malloc(sizeof(ZSubscription_t) * subSize); 255 if (filename==NULL) { 256 sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs"); 257 } else { 258 strcpy(subsfile, filename); 259 } 260 261 ret=stat(subsfile, &statbuff); 262 if (ret) { 263 if (error_on_nofile==1) return(-1); 264 return(0); 256 if (filename == NULL) 257 subsfile = owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g)); 258 else 259 subsfile = owl_strdup(filename); 260 261 if (stat(subsfile, &statbuff) != 0) { 262 if (error_on_nofile == 1) 263 return -1; 264 return 0; 265 265 } 266 266 267 267 ZResetAuthentication(); 268 count=0; 269 file=fopen(subsfile, "r"); 270 if (!file) return(-1); 271 while ( fgets(buffer, 1024, file)!=NULL ) { 272 if (buffer[0]=='#' || buffer[0]=='\n' || buffer[0]=='\n') continue; 273 274 if (buffer[0]=='-') { 275 start=buffer+1; 276 } else { 277 start=buffer; 278 } 279 268 count = 0; 269 file = fopen(subsfile, "r"); 270 owl_free(subsfile); 271 if (!file) 272 return -1; 273 while (owl_getline(&buffer, file)) { 274 if (buffer[0] == '#' || buffer[0] == '\n') 275 continue; 276 277 if (buffer[0] == '-') 278 start = buffer + 1; 279 else 280 start = buffer; 281 280 282 if (count >= subSize) { 281 283 subSize *= 2; … … 284 286 285 287 /* add it to the list of subs */ 286 if ((tmp=strtok(start, ",\n\r"))==NULL) continue; 287 subs[count].zsub_class=owl_strdup(tmp); 288 if ((tmp=strtok(NULL, ",\n\r"))==NULL) continue; 289 subs[count].zsub_classinst=owl_strdup(tmp); 290 if ((tmp=strtok(NULL, " \t\n\r"))==NULL) continue; 291 subs[count].zsub_recipient=owl_strdup(tmp); 292 288 if ((tmp = strtok(start, ",\n\r")) == NULL) 289 continue; 290 subs[count].zsub_class = owl_strdup(tmp); 291 if ((tmp=strtok(NULL, ",\n\r")) == NULL) 292 continue; 293 subs[count].zsub_classinst = owl_strdup(tmp); 294 if ((tmp = strtok(NULL, " \t\n\r")) == NULL) 295 continue; 296 subs[count].zsub_recipient = owl_strdup(tmp); 297 293 298 /* if it started with '-' then add it to the global punt list, and 294 299 * remove it from the list of subs. */ 295 if (buffer[0] =='-') {300 if (buffer[0] == '-') { 296 301 owl_function_zpunt(subs[count].zsub_class, subs[count].zsub_classinst, subs[count].zsub_recipient, 0); 297 302 owl_free(subs[count].zsub_class); 298 303 owl_free(subs[count].zsub_classinst); 299 304 owl_free(subs[count].zsub_recipient); 300 } 301 else { 305 } else { 302 306 count++; 303 307 } 304 308 } 305 309 fclose(file); 306 307 ret = owl_zephyr_loadsubs_helper(subs, count); 308 return(ret); 309 #else 310 return(0); 310 if (buffer) 311 owl_free(buffer); 312 313 return owl_zephyr_loadsubs_helper(subs, count); 314 #else 315 return 0; 311 316 #endif 312 317 } … … 362 367 ZSubscription_t *subs; 363 368 int numSubs = 100; 364 char subsfile[1024], buffer[1024]; 365 int count, ret; 369 char *subsfile; 370 char *buffer = NULL; 371 int count; 366 372 struct stat statbuff; 367 373 368 374 subs = owl_malloc(numSubs * sizeof(ZSubscription_t)); 369 375 370 if (filename==NULL) { 371 sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".anyone"); 372 } else { 373 strcpy(subsfile, filename); 374 } 375 376 ret=stat(subsfile, &statbuff); 377 if (ret) return(0); 378 379 ret=0; 376 if (filename==NULL) 377 subsfile = owl_sprintf("%s/%s", owl_global_get_homedir(&g), ".anyone"); 378 else 379 subsfile = owl_strdup(filename); 380 381 if (stat(subsfile, &statbuff) == -1) 382 return 0; 380 383 381 384 ZResetAuthentication(); 382 count=0; 383 file=fopen(subsfile, "r"); 385 count = 0; 386 file = fopen(subsfile, "r"); 387 owl_free(subsfile); 384 388 if (file) { 385 while ( fgets(buffer, 1024, file)!=NULL ) { 386 if (buffer[0] == '\0' || buffer[0] == '#' || buffer[0] == '\n') continue; 387 389 while (owl_getline_chomp(&buffer, file)) { 390 if (buffer[0] == '\0' || buffer[0] == '#') 391 continue; 392 388 393 if (count == numSubs) { 389 394 numSubs *= 2; … … 391 396 } 392 397 393 if (buffer[strlen(buffer) - 1] == '\n') 394 buffer[strlen(buffer) - 1] = '\0'; 395 subs[count].zsub_class=owl_strdup("login"); 396 subs[count].zsub_recipient=owl_strdup("*"); 397 if (strchr(buffer, '@')) { 398 subs[count].zsub_classinst=owl_strdup(buffer); 399 } else { 400 subs[count].zsub_classinst=owl_sprintf("%s@%s", buffer, ZGetRealm()); 401 } 398 subs[count].zsub_class = owl_strdup("login"); 399 subs[count].zsub_recipient = owl_strdup("*"); 400 subs[count].zsub_classinst = long_zuser(buffer); 402 401 403 402 count++; … … 405 404 fclose(file); 406 405 } else { 407 count=0;408 ret=-1;409 }410 411 ret = owl_zephyr_loadsubs_helper(subs, count); 412 return (ret);413 #else 414 return (0);406 return 0; 407 } 408 if (buffer) 409 owl_free(buffer); 410 411 return owl_zephyr_loadsubs_helper(subs, count); 412 #else 413 return 0; 415 414 #endif 416 415 } … … 953 952 { 954 953 #ifdef HAVE_LIBZEPHYR 955 char *line, subsfile[LINE], buff[LINE];954 char *line, *subsfile, *s = NULL; 956 955 FILE *file; 957 958 line=owl_zephyr_makesubline(class, inst, recip); 959 960 if (filename==NULL) { 961 sprintf(subsfile, "%s/%s", owl_global_get_homedir(&g), ".zephyr.subs");962 } else {963 strcpy(subsfile, filename);964 }956 int duplicate = 0; 957 958 line = owl_zephyr_makesubline(class, inst, recip); 959 960 if (filename == NULL) 961 subsfile = owl_sprintf("%s/.zephyr.subs", owl_global_get_homedir(&g)); 962 else 963 subsfile = owl_strdup(filename); 965 964 966 965 /* if the file already exists, check to see if the sub is already there */ 967 file =fopen(subsfile, "r");966 file = fopen(subsfile, "r"); 968 967 if (file) { 969 while ( fgets(buff, LINE, file)!=NULL) {970 if ( !strcasecmp(buff, line)) {968 while (owl_getline(&s, file)) { 969 if (strcasecmp(s, line) == 0) { 971 970 owl_function_error("Subscription already present in %s", subsfile); 972 owl_free(line); 973 fclose(file); 974 return; 971 duplicate++; 975 972 } 976 973 } 977 974 fclose(file); 978 } 979 980 /* if we get here then we didn't find it */ 981 file=fopen(subsfile, "a"); 982 if (!file) { 983 owl_function_error("Error opening file %s for writing", subsfile); 984 owl_free(line); 985 return; 986 } 987 fputs(line, file); 988 fclose(file); 989 owl_function_makemsg("Subscription added"); 990 975 owl_free(s); 976 } 977 978 if (!duplicate) { 979 file = fopen(subsfile, "a"); 980 if (file) { 981 fputs(line, file); 982 fclose(file); 983 owl_function_makemsg("Subscription added"); 984 } else { 985 owl_function_error("Error opening file %s for writing", subsfile); 986 } 987 } 988 991 989 owl_free(line); 992 990 #endif … … 1277 1275 { 1278 1276 #ifdef HAVE_LIBZEPHYR 1279 char *ourfile, *tmp, buff[LINE];1277 char *ourfile, *tmp, *s = NULL; 1280 1278 FILE *f; 1281 1279 1282 if (filename==NULL) { 1283 ourfile=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); 1284 } else { 1285 ourfile=owl_strdup(filename); 1286 } 1287 1288 f=fopen(ourfile, "r"); 1280 if (filename == NULL) 1281 ourfile = owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); 1282 else 1283 ourfile = owl_strdup(filename); 1284 1285 f = fopen(ourfile, "r"); 1289 1286 if (!f) { 1290 1287 owl_function_error("Error opening file %s: %s", ourfile, strerror(errno) ? strerror(errno) : ""); 1291 1288 owl_free(ourfile); 1292 return(-1); 1293 } 1294 1295 while (fgets(buff, LINE, f)!=NULL) { 1289 return -1; 1290 } 1291 owl_free(ourfile); 1292 1293 while (owl_getline_chomp(&s, f)) { 1296 1294 /* ignore comments, blank lines etc. */ 1297 if (buff[0]=='#') continue; 1298 if (buff[0]=='\n') continue; 1299 if (buff[0]=='\0') continue; 1300 1301 /* strip the \n */ 1302 buff[strlen(buff)-1]='\0'; 1303 1304 /* ingore from # on */ 1305 tmp=strchr(buff, '#'); 1306 if (tmp) tmp[0]='\0'; 1307 1308 /* ingore from SPC */ 1309 tmp=strchr(buff, ' '); 1310 if (tmp) tmp[0]='\0'; 1311 1312 /* stick on the local realm. */ 1313 if (!strchr(buff, '@')) { 1314 strcat(buff, "@"); 1315 strcat(buff, ZGetRealm()); 1316 } 1317 owl_list_append_element(in, owl_strdup(buff)); 1295 if (s[0] == '#' || s[0] == '\0') 1296 continue; 1297 1298 /* ignore from # on */ 1299 tmp = strchr(s, '#'); 1300 if (tmp) 1301 tmp[0] = '\0'; 1302 1303 /* ignore from SPC */ 1304 tmp = strchr(s, ' '); 1305 if (tmp) 1306 tmp[0] = '\0'; 1307 1308 owl_list_append_element(in, long_zuser(s)); 1318 1309 } 1319 1310 fclose(f); 1320 owl_free(ourfile); 1321 return(0); 1322 #else 1323 return(-1); 1311 return 0; 1312 #else 1313 return -1; 1324 1314 #endif 1325 1315 }
Note: See TracChangeset
for help on using the changeset viewer.