Changeset 4e29ecb


Ignore:
Timestamp:
Mar 24, 2011, 4:56:24 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
3a3863e
Parents:
5d56a27
Message:
Add zuser_realm and use it

We do not consistently (or correctly) extract the realm from a zuser.
Add a function and use it instead of ad-hoc strchr munging.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • message.c

    ra5b5d00 r4e29ecb  
    775775  struct hostent *hent;
    776776#endif /* ZNOTICE_SOCKADDR */
    777   const char *ptr;
    778777  char *tmp, *tmp2;
    779778  int len;
     
    808807  owl_message_set_zsig(m, owl_zephyr_get_zsig(n, &len));
    809808
    810   if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
    811     owl_message_set_realm(m, ptr+1);
    812   } else {
    813     owl_message_set_realm(m, owl_zephyr_get_realm());
    814   }
     809  owl_message_set_realm(m, zuser_realm(n->z_recipient));
    815810
    816811  /* Set the "isloginout" attribute if it's a login message */
     
    915910{
    916911  char *longuser;
    917   const char *ptr;
    918912
    919913#ifdef HAVE_LIBZEPHYR
     
    944938  }
    945939
    946   if ((ptr=strchr(longuser, '@'))!=NULL) {
    947     owl_message_set_realm(m, ptr+1);
    948   } else {
    949     owl_message_set_realm(m, owl_zephyr_get_realm());
    950   }
     940  owl_message_set_realm(m, zuser_realm(longuser));
    951941
    952942  owl_message_set_body(m, "<uninitialized>");
  • zephyr.c

    r5d56a27 r4e29ecb  
    771771      char *buff;
    772772      owl_zwrite zw;
    773       char *realm;
    774773
    775774      tmp = short_zuser(retnotice->z_recipient);
     
    804803      zw.class = g_strdup(retnotice->z_class);
    805804      zw.inst  = g_strdup(retnotice->z_class_inst);
    806       realm = strchr(retnotice->z_recipient, '@');
    807       if(realm) {
    808         zw.realm = g_strdup(realm + 1);
    809       } else {
    810         zw.realm = g_strdup(owl_zephyr_get_realm());
    811       }
     805      zw.realm = g_strdup(zuser_realm(retnotice->z_recipient));
    812806      zw.opcode = g_strdup(retnotice->z_opcode);
    813807      zw.zsig   = g_strdup("");
     
    11871181  }
    11881182  return g_strdup_printf("%s@%s", in, owl_zephyr_get_realm());
     1183}
     1184
     1185/* Return the realm of the zephyr user name. Caller does /not/ free the return.
     1186 * The string is valid at least as long as the input is.
     1187 */
     1188const char *zuser_realm(const char *in)
     1189{
     1190  char *ptr = strrchr(in, '@');
     1191  /* If the name has an @ and does not end with @, use that. Otherwise, take
     1192   * the default realm. */
     1193  return (ptr && ptr[1]) ? (ptr+1) : owl_zephyr_get_realm();
    11891194}
    11901195
Note: See TracChangeset for help on using the changeset viewer.