Changeset 765fa34


Ignore:
Timestamp:
Mar 29, 2009, 5:06:44 PM (15 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
owl
Children:
9b9e2d9c
Parents:
e01449c
Message:
new getsubs()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    re01449c r765fa34  
    717717char *owl_zephyr_makesubline(char *class, char *inst, char *recip)
    718718{
    719   char *out;
    720 
    721   out=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+30);
    722   sprintf(out, "%s,%s,%s\n", class, inst, !strcmp(recip, "") ? "*" : recip);
    723   return(out);
    724 }
    725 
     719  return(owl_sprintf("%s,%s,%s\n", class, inst, !strcmp(recip, "") ? "*" : recip));
     720}
    726721
    727722void owl_zephyr_zlog_in(void)
     
    753748  ret=ZSetLocation(eset);
    754749  if (ret != ZERR_NONE) {
    755     /*
    756       char buff[LINE];
    757       sprintf(buff, "Error setting location: %s", error_message(ret));
    758       owl_function_makemsg(buff);
    759     */
     750    /* owl_function_makemsg("Error setting location: %s", error_message(ret)); */
    760751  }
    761752#endif
     
    770761  ret=ZUnsetLocation();
    771762  if (ret != ZERR_NONE) {
    772     /*
    773       char buff[LINE];
    774       sprintf(buff, "Error unsetting location: %s", error_message(ret));
    775       owl_function_makemsg(buff);
    776     */
     763    /* owl_function_makemsg("Error unsetting location: %s", error_message(ret)); */
    777764  }
    778765#endif
     
    835822#ifdef HAVE_LIBZEPHYR
    836823  int ret, num, i, one;
     824  int buffsize;
    837825  ZSubscription_t sub;
    838   char *out, *tmpbuff;
     826  char *out;
    839827  one=1;
    840828
     
    842830  if (ret==ZERR_TOOMANYSUBS) {
    843831    return(owl_strdup("Zephyr: too many subscriptions\n"));
    844   } else if (ret) {
     832  } else if (ret || (num <= 0)) {
    845833    return(owl_strdup("Zephyr: error retriving subscriptions\n"));
    846834  }
    847835
    848   out=owl_malloc(num*500);
    849   tmpbuff=owl_malloc(num*500);
     836  buffsize = (num + 1) * 50;
     837  out=owl_malloc(buffsize);
    850838  strcpy(out, "");
    851839  for (i=0; i<num; i++) {
    852840    if ((ret = ZGetSubscriptions(&sub, &one)) != ZERR_NONE) {
    853841      owl_free(out);
    854       owl_free(tmpbuff);
    855842      ZFlushSubscriptions();
    856843      out=owl_strdup("Error while getting subscriptions\n");
    857844      return(out);
    858845    } else {
    859       sprintf(tmpbuff, "<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out);
     846      int tmpbufflen;
     847      char *tmpbuff;
     848      tmpbuff = owl_sprintf("<%s,%s,%s>\n%s", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient, out);
     849      tmpbufflen = strlen(tmpbuff) + 1;
     850      if (tmpbufflen > buffsize) {
     851        char *out2;
     852        buffsize = tmpbufflen * 2;
     853        out2 = owl_realloc(out, buffsize);
     854        if (out2 == NULL) {
     855          owl_free(out);
     856          owl_free(tmpbuff);
     857          ZFlushSubscriptions();
     858          out=owl_strdup("Realloc error while getting subscriptions\n");
     859          return(out);   
     860        }
     861        out = out2;
     862      }
    860863      strcpy(out, tmpbuff);
    861     }
    862   }
    863 
    864   owl_free(tmpbuff);
     864      owl_free(tmpbuff);
     865    }
     866  }
     867
    865868  ZFlushSubscriptions();
    866869  return(out);
Note: See TracChangeset for help on using the changeset viewer.