Changeset 5a95b69 for functions.c
- Timestamp:
- Dec 20, 2003, 1:35:36 PM (21 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 72836b5
- Parents:
- c8735aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
functions.c
r8c46404 r5a95b69 1429 1429 n=owl_message_get_notice(m); 1430 1430 1431 owl_fmtext_append_normal(&fm, " Kind : "); 1432 if (n->z_kind==UNSAFE) { 1433 owl_fmtext_append_normal(&fm, "UNSAFE\n"); 1434 } else if (n->z_kind==UNACKED) { 1435 owl_fmtext_append_normal(&fm, "UNACKED\n"); 1436 } else if (n->z_kind==ACKED) { 1437 owl_fmtext_append_normal(&fm, "ACKED\n"); 1438 } else if (n->z_kind==HMACK) { 1439 owl_fmtext_append_normal(&fm, "HMACK\n"); 1440 } else if (n->z_kind==HMCTL) { 1441 owl_fmtext_append_normal(&fm, "HMCTL\n"); 1442 } else if (n->z_kind==SERVACK) { 1443 owl_fmtext_append_normal(&fm, "SERVACK\n"); 1444 } else if (n->z_kind==SERVNAK) { 1445 owl_fmtext_append_normal(&fm, "SERVNACK\n"); 1446 } else if (n->z_kind==CLIENTACK) { 1447 owl_fmtext_append_normal(&fm, "CLIENTACK\n"); 1448 } else if (n->z_kind==STAT) { 1449 owl_fmtext_append_normal(&fm, "STAT\n"); 1450 } else { 1451 owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n"); 1431 if (!owl_message_is_pseudo(m)) { 1432 owl_fmtext_append_normal(&fm, " Kind : "); 1433 if (n->z_kind==UNSAFE) { 1434 owl_fmtext_append_normal(&fm, "UNSAFE\n"); 1435 } else if (n->z_kind==UNACKED) { 1436 owl_fmtext_append_normal(&fm, "UNACKED\n"); 1437 } else if (n->z_kind==ACKED) { 1438 owl_fmtext_append_normal(&fm, "ACKED\n"); 1439 } else if (n->z_kind==HMACK) { 1440 owl_fmtext_append_normal(&fm, "HMACK\n"); 1441 } else if (n->z_kind==HMCTL) { 1442 owl_fmtext_append_normal(&fm, "HMCTL\n"); 1443 } else if (n->z_kind==SERVACK) { 1444 owl_fmtext_append_normal(&fm, "SERVACK\n"); 1445 } else if (n->z_kind==SERVNAK) { 1446 owl_fmtext_append_normal(&fm, "SERVNACK\n"); 1447 } else if (n->z_kind==CLIENTACK) { 1448 owl_fmtext_append_normal(&fm, "CLIENTACK\n"); 1449 } else if (n->z_kind==STAT) { 1450 owl_fmtext_append_normal(&fm, "STAT\n"); 1451 } else { 1452 owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n"); 1453 } 1452 1454 } 1453 1455 owl_fmtext_append_normal(&fm, " Host : "); 1454 1456 owl_fmtext_append_normal(&fm, owl_message_get_hostname(m)); 1455 owl_fmtext_append_normal(&fm, "\n"); 1456 sprintf(buff, " Port : %i\n", n->z_port); 1457 owl_fmtext_append_normal(&fm, buff); 1458 1459 owl_fmtext_append_normal(&fm, " Auth : "); 1460 owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n)); 1461 owl_fmtext_append_normal(&fm, "\n"); 1462 1463 /* fix this */ 1464 sprintf(buff, " Checkd Ath: %i\n", n->z_checked_auth); 1465 sprintf(buff, "%s Multi notc: %s\n", buff, n->z_multinotice); 1466 sprintf(buff, "%s Num other : %i\n", buff, n->z_num_other_fields); 1467 sprintf(buff, "%s Msg Len : %i\n", buff, n->z_message_len); 1468 owl_fmtext_append_normal(&fm, buff); 1457 1458 if (!owl_message_is_pseudo(m)) { 1459 owl_fmtext_append_normal(&fm, "\n"); 1460 sprintf(buff, " Port : %i\n", n->z_port); 1461 owl_fmtext_append_normal(&fm, buff); 1462 1463 owl_fmtext_append_normal(&fm, " Auth : "); 1464 owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n)); 1465 owl_fmtext_append_normal(&fm, "\n"); 1466 1467 /* fix this */ 1468 sprintf(buff, " Checkd Ath: %i\n", n->z_checked_auth); 1469 sprintf(buff, "%s Multi notc: %s\n", buff, n->z_multinotice); 1470 sprintf(buff, "%s Num other : %i\n", buff, n->z_num_other_fields); 1471 sprintf(buff, "%s Msg Len : %i\n", buff, n->z_message_len); 1472 owl_fmtext_append_normal(&fm, buff); 1473 1474 sprintf(buff, " Fields : %i\n", owl_zephyr_get_num_fields(n)); 1475 owl_fmtext_append_normal(&fm, buff); 1476 1477 fields=owl_zephyr_get_num_fields(n); 1478 for (i=0; i<fields; i++) { 1479 sprintf(buff, " Field %i : ", i+1); 1480 1481 ptr=owl_zephyr_get_field(n, i+1, &len); 1482 if (!ptr) break; 1483 if (len<30) { 1484 strncpy(tmpbuff, ptr, len); 1485 tmpbuff[len]='\0'; 1486 } else { 1487 strncpy(tmpbuff, ptr, 30); 1488 tmpbuff[30]='\0'; 1489 strcat(tmpbuff, "..."); 1490 } 1491 1492 for (j=0; j<strlen(tmpbuff); j++) { 1493 if (tmpbuff[j]=='\n') tmpbuff[j]='~'; 1494 if (tmpbuff[j]=='\r') tmpbuff[j]='!'; 1495 } 1496 1497 strcat(buff, tmpbuff); 1498 strcat(buff, "\n"); 1499 owl_fmtext_append_normal(&fm, buff); 1500 } 1501 owl_fmtext_append_normal(&fm, " Default Fm:"); 1502 owl_fmtext_append_normal(&fm, n->z_default_format); 1503 } 1469 1504 1470 sprintf(buff, " Fields : %i\n", owl_zephyr_get_num_fields(n));1471 owl_fmtext_append_normal(&fm, buff);1472 1473 fields=owl_zephyr_get_num_fields(n);1474 for (i=0; i<fields; i++) {1475 sprintf(buff, " Field %i : ", i+1);1476 1477 ptr=owl_zephyr_get_field(n, i+1, &len);1478 if (!ptr) break;1479 if (len<30) {1480 strncpy(tmpbuff, ptr, len);1481 tmpbuff[len]='\0';1482 } else {1483 strncpy(tmpbuff, ptr, 30);1484 tmpbuff[30]='\0';1485 strcat(tmpbuff, "...");1486 }1487 1488 for (j=0; j<strlen(tmpbuff); j++) {1489 if (tmpbuff[j]=='\n') tmpbuff[j]='~';1490 if (tmpbuff[j]=='\r') tmpbuff[j]='!';1491 }1492 1493 strcat(buff, tmpbuff);1494 strcat(buff, "\n");1495 owl_fmtext_append_normal(&fm, buff);1496 }1497 owl_fmtext_append_normal(&fm, " Default Fm:");1498 owl_fmtext_append_normal(&fm, n->z_default_format);1499 1505 } 1500 1506 #endif … … 3020 3026 } 3021 3027 3022 /* Popup a buddylisting. If file is NULL use the default .anyone */3023 void owl_function_buddylist(int aim, int zephyr, char *file )3024 { 3025 int i, j, idle;3028 /* Popup a buddylisting. If filename is NULL use the default .anyone */ 3029 void owl_function_buddylist(int aim, int zephyr, char *filename) 3030 { 3031 int i, j, x, idle; 3026 3032 owl_fmtext fm; 3027 3033 owl_buddylist *bl; 3028 3034 owl_buddy *b; 3035 owl_list anyone; 3029 3036 char *foo, *timestr; 3030 3037 #ifdef HAVE_LIBZEPHYR 3031 char * ourfile, *tmp, buff[LINE], *line;3038 char *tmp, *user, *line; 3032 3039 ZLocations_t location[200]; 3033 FILE *f;3034 3040 int numlocs, ret; 3035 3041 #endif … … 3061 3067 #ifdef HAVE_LIBZEPHYR 3062 3068 if (zephyr) { 3063 if (file==NULL) { 3064 tmp=owl_global_get_homedir(&g); 3065 ourfile=owl_sprintf("%s/.anyone", owl_global_get_homedir(&g)); 3069 owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n"); 3070 owl_list_create(&anyone); 3071 ret=owl_zephyr_get_anyone_list(&anyone, filename); 3072 if (ret) { 3073 owl_fmtext_append_normal(&fm, " Error opening file for zephyr buddies.\n"); 3066 3074 } else { 3067 ourfile=owl_strdup(file); 3068 } 3069 3070 owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n"); 3071 f=fopen(ourfile, "r"); 3072 if (!f) { 3073 owl_fmtext_append_normal(&fm, " Error opening file "); 3074 owl_fmtext_append_normal(&fm, ourfile); 3075 owl_fmtext_append_normal(&fm, "\n"); 3076 owl_function_error("Error opening file %s: %s", ourfile, strerror(errno) ? strerror(errno) : ""); 3077 } else { 3078 while (fgets(buff, LINE, f)!=NULL) { 3079 /* ignore comments, blank lines etc. */ 3080 if (buff[0]=='#') continue; 3081 if (buff[0]=='\n') continue; 3082 if (buff[0]=='\0') continue; 3083 3084 /* strip the \n */ 3085 buff[strlen(buff)-1]='\0'; 3086 3087 /* ingore from # on */ 3088 tmp=strchr(buff, '#'); 3089 if (tmp) tmp[0]='\0'; 3090 3091 /* ingore from SPC */ 3092 tmp=strchr(buff, ' '); 3093 if (tmp) tmp[0]='\0'; 3094 3095 /* stick on the local realm. */ 3096 if (!strchr(buff, '@')) { 3097 strcat(buff, "@"); 3098 strcat(buff, ZGetRealm()); 3099 } 3100 3101 ret=ZLocateUser(buff, &numlocs, ZAUTH); 3075 j=owl_list_get_size(&anyone); 3076 for (i=0; i<j; i++) { 3077 user=owl_list_get_element(&anyone, i); 3078 ret=ZLocateUser(user, &numlocs, ZAUTH); 3102 3079 if (ret!=ZERR_NONE) { 3103 owl_function_error("Error getting location for %s", buff);3080 owl_function_error("Error getting location for %s", user); 3104 3081 continue; 3105 3082 } … … 3108 3085 ret=ZGetLocations(location, &numlocs); 3109 3086 if (ret==0) { 3110 for ( i=0; i<numlocs; i++) {3111 line=malloc(strlen(location[ i].host)+strlen(location[i].time)+strlen(location[i].tty)+100);3112 tmp=short_zuser( buff);3087 for (x=0; x<numlocs; x++) { 3088 line=malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100); 3089 tmp=short_zuser(user); 3113 3090 sprintf(line, " %-10.10s %-24.24s %-12.12s %20.20s\n", 3114 3091 tmp, 3115 location[ i].host,3116 location[ i].tty,3117 location[ i].time);3092 location[x].host, 3093 location[x].tty, 3094 location[x].time); 3118 3095 owl_fmtext_append_normal(&fm, line); 3119 3096 owl_free(tmp); … … 3124 3101 } 3125 3102 } 3126 fclose(f); 3127 } 3128 owl_free(ourfile); 3103 } 3129 3104 } 3130 3105 #endif … … 3132 3107 owl_function_popless_fmtext(&fm); 3133 3108 owl_fmtext_free(&fm); 3109 owl_list_free_all(&anyone, owl_free); 3134 3110 } 3135 3111 … … 3141 3117 owl_view *v; 3142 3118 FILE *file; 3143 3144 /* struct stat sbuf; */3145 3119 3146 3120 v=owl_global_get_current_view(&g); … … 3388 3362 va_end(ap); 3389 3363 } 3364 3365 /* get locations for everyone in .anyone. If 'notify' is '1' then 3366 * send a pseudo login or logout message for everyone not in sync with 3367 * the global zephyr buddy list. The list is updated regardless of 3368 * the status of 'notify'. 3369 */ 3370 void owl_function_zephyr_buddy_check(int notify) 3371 { 3372 #ifdef HAVE_LIBZEPHYR 3373 int i, j; 3374 owl_list anyone; 3375 owl_message *m; 3376 owl_zbuddylist *zbl; 3377 char *user; 3378 ZLocations_t location[200]; 3379 int numlocs, ret; 3380 3381 zbl=owl_global_get_zephyr_buddylist(&g); 3382 3383 owl_list_create(&anyone); 3384 ret=owl_zephyr_get_anyone_list(&anyone, NULL); 3385 3386 j=owl_list_get_size(&anyone); 3387 for (i=0; i<j; i++) { 3388 user=owl_list_get_element(&anyone, i); 3389 ret=ZLocateUser(user, &numlocs, ZAUTH); 3390 if (ret!=ZERR_NONE) { 3391 owl_function_error("Error getting location for %s", user); 3392 continue; 3393 } 3394 numlocs=200; 3395 ret=ZGetLocations(location, &numlocs); 3396 if (ret==0) { 3397 if ((numlocs>0) && !owl_zbuddylist_contains_user(zbl, user)) { 3398 /* Send a PSEUDO LOGIN! */ 3399 if (notify) { 3400 m=owl_malloc(sizeof(owl_message)); 3401 owl_message_create_pseudo_zlogin(m, 0, user, location[0].host, location[0].time, location[0].tty); 3402 owl_global_messagequeue_addmsg(&g, m); 3403 } 3404 owl_zbuddylist_adduser(zbl, user); 3405 owl_function_debugmsg("owl_function_zephyr_buddy_check: login for %s ", user); 3406 } else if ((numlocs==0) && owl_zbuddylist_contains_user(zbl, user)) { 3407 /* I don't think this ever happens (if there are 0 locations we should get an error from 3408 * ZGetLocations) 3409 */ 3410 owl_function_error("owl_function_zephyr_buddy_check: exceptional case logout for %s ",user); 3411 } 3412 } else if ((ret==ZERR_NOLOCATIONS) && owl_zbuddylist_contains_user(zbl, user)) { 3413 /* Send a PSEUDO LOGOUT! */ 3414 if (notify) { 3415 m=owl_malloc(sizeof(owl_message)); 3416 owl_message_create_pseudo_zlogin(m, 1, user, location[0].host, location[0].time, location[0].tty); 3417 owl_global_messagequeue_addmsg(&g, m); 3418 } 3419 owl_zbuddylist_deluser(zbl, user); 3420 owl_function_debugmsg("owl_function_zephyr_buddy_check: logout for %s ",user); 3421 } 3422 } 3423 3424 owl_list_free_all(&anyone, owl_free); 3425 #endif 3426 }
Note: See TracChangeset
for help on using the changeset viewer.