Changeset 13a3c1db for owl.c


Ignore:
Timestamp:
May 30, 2007, 12:05:27 AM (17 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
4508e21
Parents:
1fd5e4c1
git-author:
Nelson Elhage <nelhage@mit.edu> (05/30/07 00:05:16)
git-committer:
Nelson Elhage <nelhage@mit.edu> (05/30/07 00:05:27)
Message:
Refactoring message processing: All new messages, incoming or
outgoing, get added to the owl_global_messagequeue by protocol code,
and then passed to owl_proces_message, which serves as a single
central code path for adding messages to the message list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    rf178fb5 r13a3c1db  
    7070  owl_popwin *pw;
    7171  int j, ret, initialsubs, debug, argcsave, followlast;
    72   int newmsgs, zpendcount, nexttimediff;
     72  int newmsgs, nexttimediff;
    7373  struct sigaction sigact;
    7474  char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
     
    7979  char *dir;
    8080  struct termios tio;
    81 #ifdef HAVE_LIBZEPHYR
    82   ZNotice_t notice;
    83 #endif
     81  owl_message *m;
    8482#if OWL_STDERR_REDIR
    8583  int newstderr;
     
    453451    }
    454452
     453    owl_zephyr_process_events();
     454   
    455455    /* Grab incoming messages. */
    456456    newmsgs=0;
    457     zpendcount=0;
    458     while(owl_zephyr_zpending() || owl_global_messagequeue_pending(&g)) {
    459 #ifdef HAVE_LIBZEPHYR
    460       struct sockaddr_in from;
    461 #endif
    462       owl_message *m=NULL;
    463       owl_filter *f;
    464 
    465       /* grab the new message, stick it in 'm' */
    466       if (owl_zephyr_zpending()) {
    467 #ifdef HAVE_LIBZEPHYR
    468         /* grab a zephyr notice, but if we've done 20 without stopping,
    469            take a break to process keystrokes etc. */
    470         if (zpendcount>20) break;
    471         ZReceiveNotice(&notice, &from);
    472         zpendcount++;
    473        
    474         /* is this an ack from a zephyr we sent? */
    475         if (owl_zephyr_notice_is_ack(&notice)) {
    476           owl_zephyr_handle_ack(&notice);
    477           continue;
    478         }
    479        
    480         /* if it's a ping and we're not viewing pings then skip it */
    481         if (!owl_global_is_rxping(&g) && !strcasecmp(notice.z_opcode, "ping")) {
    482           continue;
    483         }
    484 
    485         /* create the new message */
    486         m=owl_malloc(sizeof(owl_message));
    487         owl_message_create_from_znotice(m, &notice);
    488 #endif
    489       } else if (owl_global_messagequeue_pending(&g)) {
    490         /* pick up the non-zephyr message in the message queue */
    491         m=owl_global_messageuque_popmsg(&g);
    492       } else {
    493         /* Not supposed to happen, but we seem to get here on resizes */
    494         owl_function_debugmsg("Bottomed out looking for zephyr");
    495       }
    496 
    497       /* If we didn't pick up a message for some reason, don't go on */
    498       if (m==NULL) {
    499         owl_function_debugmsg("m is null in main loop");
    500         continue;
    501       }
    502      
    503       /* if this message it on the puntlist, nuke it and continue */
    504       if (owl_global_message_is_puntable(&g, m)) {
    505         owl_message_free(m);
    506         continue;
    507       }
    508 
    509       /*  login or logout that should be ignored? */
    510       if (owl_global_is_ignorelogins(&g) && owl_message_is_loginout(m)) {
    511         owl_message_free(m);
    512         continue;
    513       }
    514 
    515       /* otherwise add it to the global list */
    516       owl_messagelist_append_element(owl_global_get_msglist(&g), m);
    517       newmsgs=1;
    518 
    519       /* let the config know the new message has been received */
    520       owl_perlconfig_getmsg(m, 0, NULL);
    521 
    522       /* add it to any necessary views; right now there's only the current view */
    523       owl_view_consider_message(owl_global_get_current_view(&g), m);
    524 
    525       /* do we need to autoreply? */
    526       if (owl_global_is_zaway(&g) && !owl_message_get_attribute_value(m, "isauto")) {
    527         if (owl_message_is_type_zephyr(m)) {
    528           owl_zephyr_zaway(m);
    529         } else if (owl_message_is_type_aim(m)) {
    530           if (owl_message_is_private(m)) {
    531             owl_function_send_aimawymsg(owl_message_get_sender(m), owl_global_get_zaway_msg(&g));
    532           }
    533         }
    534       }
    535 
    536       /* ring the bell if it's a personal */
    537       if (!strcmp(owl_global_get_personalbell(&g), "on")) {
    538           if (!owl_message_is_loginout(m) &&
    539               !owl_message_is_mail(m) &&
    540               owl_message_is_personal(m)) {
    541             owl_function_beep();
    542           }
    543       } else if (!strcmp(owl_global_get_personalbell(&g), "off")) {
    544         /* do nothing */
    545       } else {
    546         f=owl_global_get_filter(&g, owl_global_get_personalbell(&g));
    547         if (f && owl_filter_message_match(f, m)) {
    548           owl_function_beep();
    549         }
    550       }
    551 
    552 
    553       /* if it matches the alert filter, do the alert action */
    554       f=owl_global_get_filter(&g, owl_global_get_alert_filter(&g));
    555       if (f && owl_filter_message_match(f, m)) {
    556         owl_function_command(owl_global_get_alert_action(&g));
    557       }
    558 
    559       /* if it's a zephyr login or logout, update the zbuddylist */
    560       if (owl_message_is_type_zephyr(m) && owl_message_is_loginout(m)) {
    561         if (owl_message_is_login(m)) {
    562           owl_zbuddylist_adduser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m));
    563         } else if (owl_message_is_logout(m)) {
    564           owl_zbuddylist_deluser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m));
    565         } else {
    566           owl_function_error("Internal error: received login notice that is neither login nor logout");
    567         }
    568       }
    569 
    570       /* check for burning ears message */
    571       /* this is an unsupported feature */
    572       if (owl_global_is_burningears(&g) && owl_message_is_burningears(m)) {
    573         char *buff;
    574         buff = owl_sprintf("@i(Burning ears message on class %s)", owl_message_get_class(m));
    575         owl_function_adminmsg(buff, "");
    576         owl_free(buff);
    577         owl_function_beep();
    578       }
    579 
    580       /* log the message if we need to */
    581       owl_log_message(m);
     457    while(owl_global_messagequeue_pending(&g)) {
     458
     459      m = owl_global_messagequeue_popmsg(&g);
     460
     461      if(owl_process_message(m))
     462        newmsgs = 1;
    582463    }
    583464
     
    694575}
    695576
     577/*
     578 * Process a new message passed to us on the message queue from some
     579 * protocol. This includes adding it to the message list, updating the
     580 * view and scrolling if appropriate, logging it, and so on.
     581 *
     582 * Either a pointer is kept to the message internally, or it is freed
     583 * if unneeded. The caller no longer ``owns'' the message's memory.
     584 *
     585 * Returns 1 if the message was added to the message list, and 0 if it
     586 * was ignored due to user settings or otherwise.
     587 */
     588int owl_process_message(owl_message *m) {
     589  owl_filter *f;
     590  /* if this message it on the puntlist, nuke it and continue */
     591  if (owl_global_message_is_puntable(&g, m)) {
     592    owl_message_free(m);
     593    return 0;
     594  }
     595
     596  /*  login or logout that should be ignored? */
     597  if (owl_global_is_ignorelogins(&g)
     598      && owl_message_is_loginout(m)) {
     599    owl_message_free(m);
     600    return 0;
     601  }
     602
     603  if (!owl_global_is_displayoutgoing(&g)
     604      && owl_message_is_direction_out(m)) {
     605    owl_message_free(m);
     606    return 0;
     607  }
     608
     609  /* add it to the global list */
     610  owl_messagelist_append_element(owl_global_get_msglist(&g), m);
     611  /* add it to any necessary views; right now there's only the current view */
     612  owl_view_consider_message(owl_global_get_current_view(&g), m);
     613
     614  if(owl_message_is_direction_in(m)) {
     615    /* let perl know about it*/
     616    owl_perlconfig_getmsg(m, 0, NULL);
     617
     618    /* do we need to autoreply? */
     619    if (owl_global_is_zaway(&g) && !owl_message_get_attribute_value(m, "isauto")) {
     620      if (owl_message_is_type_zephyr(m)) {
     621        owl_zephyr_zaway(m);
     622      } else if (owl_message_is_type_aim(m)) {
     623        if (owl_message_is_private(m)) {
     624          owl_function_send_aimawymsg(owl_message_get_sender(m), owl_global_get_zaway_msg(&g));
     625        }
     626      }
     627    }
     628
     629    /* ring the bell if it's a personal */
     630    if (!strcmp(owl_global_get_personalbell(&g), "on")) {
     631      if (!owl_message_is_loginout(m) &&
     632          !owl_message_is_mail(m) &&
     633          owl_message_is_personal(m)) {
     634        owl_function_beep();
     635      }
     636    } else if (!strcmp(owl_global_get_personalbell(&g), "off")) {
     637      /* do nothing */
     638    } else {
     639      f=owl_global_get_filter(&g, owl_global_get_personalbell(&g));
     640      if (f && owl_filter_message_match(f, m)) {
     641        owl_function_beep();
     642      }
     643    }
     644
     645    /* if it matches the alert filter, do the alert action */
     646    f=owl_global_get_filter(&g, owl_global_get_alert_filter(&g));
     647    if (f && owl_filter_message_match(f, m)) {
     648      owl_function_command(owl_global_get_alert_action(&g));
     649    }
     650
     651    /* if it's a zephyr login or logout, update the zbuddylist */
     652    if (owl_message_is_type_zephyr(m) && owl_message_is_loginout(m)) {
     653      if (owl_message_is_login(m)) {
     654        owl_zbuddylist_adduser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m));
     655      } else if (owl_message_is_logout(m)) {
     656        owl_zbuddylist_deluser(owl_global_get_zephyr_buddylist(&g), owl_message_get_sender(m));
     657      } else {
     658        owl_function_error("Internal error: received login notice that is neither login nor logout");
     659      }
     660    }
     661
     662    /* check for burning ears message */
     663    /* this is an unsupported feature */
     664    if (owl_global_is_burningears(&g) && owl_message_is_burningears(m)) {
     665      char *buff;
     666      buff = owl_sprintf("@i(Burning ears message on class %s)", owl_message_get_class(m));
     667      owl_function_adminmsg(buff, "");
     668      owl_free(buff);
     669      owl_function_beep();
     670    }
     671  }
     672
     673  /* log the message if we need to */
     674  owl_log_message(m);
     675
     676  return 1;
     677}
     678
    696679void sig_handler(int sig, siginfo_t *si, void *data)
    697680{
Note: See TracChangeset for help on using the changeset viewer.