Changeset 57609b3


Ignore:
Timestamp:
Feb 11, 2009, 12:20:21 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
c1d166b
Parents:
28fa23c
git-author:
Nelson Elhage <nelhage@mit.edu> (02/10/09 18:30:04)
git-committer:
Nelson Elhage <nelhage@mit.edu> (02/11/09 12:20:21)
Message:
owl_function_info: Clean up code using owl_fmtext_appendf_normal

This replaces the awkward and potentially unsafe use of sprintf
previously present here.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r2101a50 r57609b3  
    14331433  owl_message *m;
    14341434  owl_fmtext fm, attrfm;
    1435   char buff[10000];
    14361435  owl_view *v;
    14371436#ifdef HAVE_LIBZEPHYR
     
    14491448
    14501449  owl_fmtext_append_bold(&fm, "General Information:\n");
    1451   owl_fmtext_append_normal(&fm, "  Msg Id    : ");
    1452   sprintf(buff, "%i", owl_message_get_id(m));
    1453   owl_fmtext_append_normal(&fm, buff);
    1454   owl_fmtext_append_normal(&fm, "\n");
     1450  owl_fmtext_appendf_normal(&fm, "  Msg Id    : %i\n", owl_message_get_id(m));
    14551451
    14561452  owl_fmtext_append_normal(&fm, "  Type      : ");
     
    14681464  }
    14691465
    1470   owl_fmtext_append_normal(&fm, "  Time      : ");
    1471   owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
    1472   owl_fmtext_append_normal(&fm, "\n");
     1466  owl_fmtext_appendf_normal(&fm, "  Time      : %s\n", owl_message_get_timestr(m));
    14731467
    14741468  if (!owl_message_is_type_admin(m)) {
    1475     owl_fmtext_append_normal(&fm, "  Sender    : ");
    1476     owl_fmtext_append_normal(&fm, owl_message_get_sender(m));
    1477     owl_fmtext_append_normal(&fm, "\n");
    1478    
    1479     owl_fmtext_append_normal(&fm, "  Recipient : ");
    1480     owl_fmtext_append_normal(&fm, owl_message_get_recipient(m));
    1481     owl_fmtext_append_normal(&fm, "\n");
    1482   }
    1483    
     1469    owl_fmtext_appendf_normal(&fm, "  Sender    : %s\n", owl_message_get_sender(m));
     1470    owl_fmtext_appendf_normal(&fm, "  Recipient : %s\n", owl_message_get_recipient(m));
     1471  }
     1472
    14841473  if (owl_message_is_type_zephyr(m)) {
    14851474    owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n");
    14861475   
    1487     owl_fmtext_append_normal(&fm, "  Class     : ");
    1488     owl_fmtext_append_normal(&fm, owl_message_get_class(m));
    1489     owl_fmtext_append_normal(&fm, "\n");
    1490     owl_fmtext_append_normal(&fm, "  Instance  : ");
    1491     owl_fmtext_append_normal(&fm, owl_message_get_instance(m));
    1492     owl_fmtext_append_normal(&fm, "\n");
    1493     owl_fmtext_append_normal(&fm, "  Opcode    : ");
    1494     owl_fmtext_append_normal(&fm, owl_message_get_opcode(m));
    1495     owl_fmtext_append_normal(&fm, "\n");
    1496    
    1497     owl_fmtext_append_normal(&fm, "  Time      : ");
    1498     owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
    1499     owl_fmtext_append_normal(&fm, "\n");
     1476    owl_fmtext_appendf_normal(&fm, "  Class     : %s\n", owl_message_get_class(m));
     1477    owl_fmtext_appendf_normal(&fm, "  Instance  : %s\n", owl_message_get_instance(m));
     1478    owl_fmtext_appendf_normal(&fm, "  Opcode    : %s\n", owl_message_get_opcode(m));
    15001479#ifdef HAVE_LIBZEPHYR
    15011480    if (owl_message_is_direction_in(m)) {
     
    15291508        }
    15301509      }
    1531       owl_fmtext_append_normal(&fm, "  Host      : ");
    1532       owl_fmtext_append_normal(&fm, owl_message_get_hostname(m));
     1510      owl_fmtext_appendf_normal(&fm, "  Host      : %s\n", owl_message_get_hostname(m));
    15331511
    15341512      if (!owl_message_is_pseudo(m)) {
    15351513        owl_fmtext_append_normal(&fm, "\n");
    1536         sprintf(buff, "  Port      : %i\n", ntohs(n->z_port));
    1537         owl_fmtext_append_normal(&fm, buff);
    1538 
    1539         owl_fmtext_append_normal(&fm,    "  Auth      : ");
    1540         owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n));
    1541         owl_fmtext_append_normal(&fm, "\n");
    1542        
    1543         /* fix this */
    1544         sprintf(buff, "  Checkd Ath: %i\n", n->z_checked_auth);
    1545         sprintf(buff + strlen(buff), "  Multi notc: %s\n", n->z_multinotice);
    1546         sprintf(buff + strlen(buff), "  Num other : %i\n", n->z_num_other_fields);
    1547         sprintf(buff + strlen(buff), "  Msg Len   : %i\n", n->z_message_len);
    1548         owl_fmtext_append_normal(&fm, buff);
    1549        
    1550         sprintf(buff, "  Fields    : %i\n", owl_zephyr_get_num_fields(n));
    1551         owl_fmtext_append_normal(&fm, buff);
    1552        
     1514        owl_fmtext_appendf_normal(&fm, "  Port      : %i\n", ntohs(n->z_port));
     1515        owl_fmtext_appendf_normal(&fm, "  Auth      : %s\n", owl_zephyr_get_authstr(n));
     1516
     1517        /* FIXME make these more descriptive */
     1518        owl_fmtext_appendf_normal(&fm, "  Checkd Ath: %i\n", n->z_checked_auth);
     1519        owl_fmtext_appendf_normal(&fm, "  Multi notc: %s\n", n->z_multinotice);
     1520        owl_fmtext_appendf_normal(&fm, "  Num other : %i\n", n->z_num_other_fields);
     1521        owl_fmtext_appendf_normal(&fm, "  Msg Len   : %i\n", n->z_message_len);
     1522
    15531523        fields=owl_zephyr_get_num_fields(n);
     1524        owl_fmtext_appendf_normal(&fm, "  Fields    : %i\n", fields);
     1525
    15541526        for (i=0; i<fields; i++) {
    1555           sprintf(buff, "  Field %i   : ", i+1);
    1556          
    15571527          ptr=owl_zephyr_get_field_as_utf8(n, i+1);
    15581528          len=strlen(ptr);
     
    15661536          }
    15671537          owl_free(ptr);
    1568          
     1538
    15691539          for (j=0; j<strlen(tmpbuff); j++) {
    15701540            if (tmpbuff[j]=='\n') tmpbuff[j]='~';
    15711541            if (tmpbuff[j]=='\r') tmpbuff[j]='!';
    15721542          }
    1573          
    1574           strcat(buff, tmpbuff);
    1575           strcat(buff, "\n");
    1576           owl_fmtext_append_normal(&fm, buff);
     1543
     1544          owl_fmtext_appendf_normal(&fm, "  Field %i   : %s\n", i+1, tmpbuff);
    15771545        }
    1578         owl_fmtext_append_normal(&fm, "  Default Fm:");
    1579         owl_fmtext_append_normal(&fm, n->z_default_format);
     1546        owl_fmtext_appendf_normal(&fm, "  Default Fm: %s\n", n->z_default_format);
    15801547      }
    1581      
    1582     }
    1583 #endif   
     1548
     1549    }
     1550#endif
    15841551  }
    15851552
Note: See TracChangeset for help on using the changeset viewer.