Changeset b0430a6 for zephyr.c


Ignore:
Timestamp:
Dec 21, 2003, 8:19:14 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:
2de4f20
Parents:
72836b5
Message:
New zephyr_get_field function
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    r5a95b69 rb0430a6  
    257257}
    258258
    259 #ifdef HAVE_LIBZEPHYR
    260 char *owl_zephyr_get_field(ZNotice_t *n, int j, int *k)
    261 {
    262   /* return a pointer to the Jth field, place the length in k.  If the
    263      field doesn't exist return an emtpy string */
     259/* return a pointer to the data in the Jth field, (NULL terminated by
     260 * definition).  Caller must free the return.
     261 */
     262#ifdef HAVE_LIBZEPHYR
     263char *owl_zephyr_get_field(ZNotice_t *n, int j)
     264{
    264265  int i, count, save;
     266  char *out;
    265267
    266268  count=save=0;
     
    270272      if (count==j) {
    271273        /* just found the end of the field we're looking for */
    272         *k=i-save;
    273         return(n->z_message+save);
     274        return(owl_strdup(n->z_message+save));
    274275      } else {
    275276        save=i+1;
     
    277278    }
    278279  }
    279   /* catch the last field */
     280  /* catch the last field, which might not be null terminated */
    280281  if (count==j-1) {
    281     *k=n->z_message_len-save;
    282     return(n->z_message+save);
    283   }
    284  
    285   *k=0;
    286   return("");
     282    out=owl_malloc(n->z_message_len-save+5);
     283    memcpy(out, n->z_message+save, n->z_message_len-save);
     284    out[n->z_message_len-save]='\0';
     285    return(out);
     286  }
     287
     288  return(owl_strdup(""));
    287289}
    288290#else
    289291char *owl_zephyr_get_field(void *n, int j, int *k)
    290292{
    291   return("");
    292 }
    293 #endif
     293  return(owl_strdup(""));
     294}
     295#endif
     296
    294297
    295298#ifdef HAVE_LIBZEPHYR
     
    313316
    314317#ifdef HAVE_LIBZEPHYR
    315 char *owl_zephyr_get_message(ZNotice_t *n, int *k)
    316 {
    317   /* return a pointer to the message, place the message length in k */
     318/* return a pointer to the message, place the message length in k */
     319char *owl_zephyr_get_message(ZNotice_t *n)
     320{
    318321  if (!strcasecmp(n->z_opcode, "ping")) {
    319     *k=0;
    320322    return("");
    321323  }
    322324
    323   return(owl_zephyr_get_field(n, 2, k));
     325  return(owl_zephyr_get_field(n, 2));
    324326}
    325327#endif
     
    793795}
    794796 
    795 
    796797/* Strip a local realm fron the zephyr user name.
    797798 * The caller must free the return
Note: See TracChangeset for help on using the changeset viewer.