Changeset 3f52e14 for zwrite.c


Ignore:
Timestamp:
Mar 24, 2011, 4:44:06 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
5d56a27
Parents:
a5b5d00
git-author:
David Benjamin <davidben@mit.edu> (03/11/11 17:21:12)
git-committer:
David Benjamin <davidben@mit.edu> (03/24/11 16:44:06)
Message:
Add owl_zwrite_get_recip_n_with_realm

Refactor owl_zwrite code abit to handle -r in a consistent place.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zwrite.c

    ra5b5d00 r3f52e14  
    175175  j=owl_list_get_size(&(z->recips));
    176176  for (i=0; i<j; i++) {
    177     if (strcmp(z->realm, "")) {
    178       to = g_strdup_printf("%s@%s", (const char *) owl_list_get_element(&(z->recips), i), z->realm);
    179     } else {
    180       to = g_strdup(owl_list_get_element(&(z->recips), i));
    181     }
     177    to = owl_zwrite_get_recip_n_with_realm(z, i);
    182178    send_ping(to, z->class, z->inst);
    183179    g_free(to);
     
    196192{
    197193  int i, j;
    198   char *toline = NULL;
     194  GString *message;
    199195  char *tmp = NULL, *tmp2;
    200196
     
    203199  j=owl_list_get_size(&(z->recips));
    204200  if (j>0 && z->cc) {
    205     toline = g_strdup( "CC: ");
     201    message = g_string_new("CC: ");
    206202    for (i=0; i<j; i++) {
    207       tmp = toline;
    208       if (strcmp(z->realm, "")) {
    209         toline = g_strdup_printf( "%s%s@%s ", toline, (const char *) owl_list_get_element(&(z->recips), i), z->realm);
    210       } else {
    211         toline = g_strdup_printf( "%s%s ", toline, (const char *) owl_list_get_element(&(z->recips), i));
    212       }
     203      tmp = owl_zwrite_get_recip_n_with_realm(z, i);
     204      g_string_append_printf(message, "%s ", tmp);
    213205      g_free(tmp);
    214206      tmp = NULL;
     
    216208    tmp = owl_validate_utf8(msg);
    217209    tmp2 = owl_text_expand_tabs(tmp);
    218     z->message=g_strdup_printf("%s\n%s", toline, tmp2);
    219     g_free(toline);
     210    g_string_append_printf(message, "\n%s", tmp2);
     211    z->message = g_string_free(message, false);
    220212    g_free(tmp);
    221213    g_free(tmp2);
     
    249241  if (j>0) {
    250242    for (i=0; i<j; i++) {
    251       if (strcmp(z->realm, "")) {
    252         to = g_strdup_printf("%s@%s", (const char *) owl_list_get_element(&(z->recips), i), z->realm);
    253       } else {
    254         to = g_strdup( owl_list_get_element(&(z->recips), i));
    255       }
     243      to = owl_zwrite_get_recip_n_with_realm(z, i);
    256244      ret = send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message);
    257245      /* Abort on the first error, to match the zwrite binary. */
     
    322310}
    323311
    324 void owl_zwrite_get_recipstr(const owl_zwrite *z, char *buff)
    325 {
    326   int i, j;
    327 
    328   strcpy(buff, "");
    329   j=owl_list_get_size(&(z->recips));
    330   for (i=0; i<j; i++) {
    331     strcat(buff, owl_list_get_element(&(z->recips), i));
    332     strcat(buff, " ");
    333   }
    334   buff[strlen(buff)-1]='\0';
    335 }
    336 
    337312int owl_zwrite_get_numrecips(const owl_zwrite *z)
    338313{
     
    343318{
    344319  return(owl_list_get_element(&(z->recips), n));
     320}
     321
     322/* Caller must free the result. */
     323char *owl_zwrite_get_recip_n_with_realm(const owl_zwrite *z, int n)
     324{
     325  if (z->realm[0]) {
     326    return g_strdup_printf("%s@%s", owl_zwrite_get_recip_n(z, n), z->realm);
     327  } else {
     328    return g_strdup(owl_zwrite_get_recip_n(z, n));
     329  }
    345330}
    346331
Note: See TracChangeset for help on using the changeset viewer.