Changeset 5a95b69 for message.c


Ignore:
Timestamp:
Dec 20, 2003, 1:35:36 PM (20 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
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
Message:
New code for getting users from .anyfile
Added the 'pseudologins' variable, and code to do it
new attributes 'pseudo' 'logintty' and 'loginhost'
File:
1 edited

Legend:

Unmodified
Added
Removed
  • message.c

    r25dd31a r5a95b69  
    3434}
    3535
     36/* add the named attribute to the message.  If an attribute with the
     37 * name already exists, replace the old value with the new value
     38 */
    3639void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue)
    3740{
    38   /* add the named attribute to the message.  If an attribute with the
    39      name already exists, replace the old value with the new value */
    40 
    4141  int i, j;
    4242  owl_pair *p;
     
    6161}
    6262
     63/* return the value associated with the named attribute, or NULL if
     64 * the attribute does not exist
     65 */
    6366char *owl_message_get_attribute_value(owl_message *m, char *attrname)
    6467{
    65   /* return the value associated with the named attribute, or NULL if
    66      the attribute does not exist */
    6768  int i, j;
    6869  owl_pair *p;
     
    362363{
    363364  if (m->type==OWL_MESSAGE_TYPE_AIM) return(1);
     365  return(0);
     366}
     367
     368int owl_message_is_pseudo(owl_message *m)
     369{
     370  if (owl_message_get_attribute_value(m, "pseudo")) return(1);
    364371  return(0);
    365372}
     
    707714{
    708715  struct hostent *hent;
    709   int k;
     716  int k, len;
    710717  char *ptr, *tmp, *tmp2;
    711718
     
    721728  owl_zephyr_hackaway_cr(&(m->notice));
    722729 
    723   m->delete=0;
    724 
    725730  /* save the time, we need to nuke the string saved by message_init */
    726   if (m->timestr) {
    727     owl_free(m->timestr);
    728   }
     731  if (m->timestr) owl_free(m->timestr);
    729732  m->time=n->z_time.tv_sec;
    730733  m->timestr=owl_strdup(ctime(&(m->time)));
     
    751754  /* Set the "isloginout" attribute if it's a login message */
    752755  if (!strcasecmp(n->z_class, "login") || !strcasecmp(n->z_class, OWL_WEBZEPHYR_CLASS)) {
     756    if (!strcasecmp(n->z_opcode, "user_login") || !strcasecmp(n->z_opcode, "user_logout")) {
     757      ptr=owl_zephyr_get_field(n, 1, &len);
     758      tmp=owl_malloc(len+10);
     759      strncpy(tmp, ptr, len);
     760      tmp[len]='\0';
     761      owl_message_set_attribute(m, "loginhost", tmp);
     762      owl_free(tmp);
     763
     764      ptr=owl_zephyr_get_field(n, 3, &len);
     765      tmp=owl_malloc(len+10);
     766      strncpy(tmp, ptr, len);
     767      tmp[len]='\0';
     768      owl_message_set_attribute(m, "logintty", tmp);
     769      owl_free(tmp);
     770    }
     771
    753772    if (!strcasecmp(n->z_opcode, "user_login")) {
    754773      owl_message_set_islogin(m);
     
    758777  }
    759778
     779 
    760780  /* is the "isprivate" attribute if it's a private zephyr */
    761781  if (!strcasecmp(n->z_recipient, owl_zephyr_get_sender())) {
     
    810830#endif
    811831
     832/* If 'direction' is '0' it is a login message, '1' is a logout message. */
     833void owl_message_create_pseudo_zlogin(owl_message *m, int direction, char *user, char *host, char *time, char *tty)
     834{
     835  char *longuser, *ptr;
     836
     837  memset(&(m->notice), 0, sizeof(ZNotice_t));
     838
     839  longuser=long_zuser(user);
     840 
     841  owl_message_init(m);
     842 
     843  owl_message_set_type_zephyr(m);
     844  owl_message_set_direction_in(m);
     845
     846  owl_message_set_attribute(m, "pseudo", "");
     847  owl_message_set_attribute(m, "loginhost", host ? host : "");
     848  owl_message_set_attribute(m, "logintty", tty ? tty : "");
     849
     850  owl_message_set_sender(m, longuser);
     851  owl_message_set_class(m, "LOGIN");
     852  owl_message_set_instance(m, longuser);
     853  owl_message_set_recipient(m, "");
     854  if (direction==0) {
     855    owl_message_set_opcode(m, "USER_LOGIN");
     856    owl_message_set_islogin(m);
     857  } else if (direction==1) {
     858    owl_message_set_opcode(m, "USER_LOGOUT");
     859    owl_message_set_islogout(m);
     860  }
     861
     862  if ((ptr=strchr(longuser, '@'))!=NULL) {
     863    owl_message_set_realm(m, ptr+1);
     864  } else {
     865    owl_message_set_realm(m, owl_zephyr_get_realm());
     866  }
     867
     868  m->zwriteline=strdup("");
     869
     870  owl_message_set_body(m, "<uninitialized>");
     871
     872  /* save the hostname */
     873  owl_function_debugmsg("create_pseudo_login: host is %s", host);
     874  strcpy(m->hostname, host ? host : "");
     875  owl_free(longuser);
     876}
     877
    812878void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig)
    813879{
Note: See TracChangeset for help on using the changeset viewer.