Changeset c518676


Ignore:
Timestamp:
Mar 6, 2011, 2:14:48 PM (10 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Branches:
master, release-1.8, release-1.9
Children:
7d969f3
Parents:
00842c3
git-author:
Karl Ramm <kcr@1ts.org> (02/12/11 00:01:14)
git-committer:
Karl Ramm <kcr@1ts.org> (03/06/11 14:14:48)
Message:
refactor owl_zephyr_get_message

Refactor and make the control flow simpler.  Really this code
should get moved to perl.

Reviewed-By: Nelson Elhage <nelhage@nelhage.com>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zephyr.c

    r00842c3 rc518676  
    591591char *owl_zephyr_get_message(const ZNotice_t *n, const owl_message *m)
    592592{
     593#define OWL_NFIELDS     5
     594  int i;
     595  char *fields[OWL_NFIELDS + 1];
     596  char *msg = NULL;
     597
    593598  /* don't let ping messages have a body */
    594599  if (!strcasecmp(n->z_opcode, "ping")) {
     
    596601  }
    597602
     603  for(i = 0; i < OWL_NFIELDS; i++)
     604    fields[i + 1] = owl_zephyr_get_field(n, i + 1);
     605
    598606  /* deal with MIT NOC messages */
    599607  if (!strcasecmp(n->z_default_format, "@center(@bold(NOC Message))\n\n@bold(Sender:) $1 <$sender>\n@bold(Time:  ) $time\n\n@italic($opcode service on $instance $3.) $4\n")) {
    600     char *msg, *field3, *field4;
    601 
    602     field3 = owl_zephyr_get_field(n, 3);
    603     field4 = owl_zephyr_get_field(n, 4);
    604 
    605     msg = g_strdup_printf("%s service on %s %s\n%s", n->z_opcode, n->z_class_inst, field3, field4);
    606     g_free(field3);
    607     g_free(field4);
    608     if (msg) {
    609       return msg;
    610     }
     608
     609    msg = g_strdup_printf("%s service on %s %s\n%s", n->z_opcode, n->z_class_inst, fields[3], fields[4]);
    611610  }
    612611  /* deal with MIT Discuss messages */
    613612  else if (!strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4") ||
    614613           !strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3\nSubject: $4")) {
    615     char *msg, *field1, *field2, *field3, *field4, *field5;
    616614   
    617     field1 = owl_zephyr_get_field(n, 1);
    618     field2 = owl_zephyr_get_field(n, 2);
    619     field3 = owl_zephyr_get_field(n, 3);
    620     field4 = owl_zephyr_get_field(n, 4);
    621     field5 = owl_zephyr_get_field(n, 5);
    622    
    623     msg = g_strdup_printf("New transaction [%s] entered in %s\nFrom: %s (%s)\nSubject: %s", field1, field2, field3, field5, field4);
    624     g_free(field1);
    625     g_free(field2);
    626     g_free(field3);
    627     g_free(field4);
    628     g_free(field5);
    629     if (msg) {
    630       return msg;
    631     }
     615    msg = g_strdup_printf("New transaction [%s] entered in %s\nFrom: %s (%s)\nSubject: %s",
     616                          fields[1], fields[2], fields[3], fields[5], fields[4]);
    632617  }
    633618  /* deal with MIT Moira messages */
    634619  else if (!strcasecmp(n->z_default_format, "MOIRA $instance on $fromhost:\n $message\n")) {
    635     char *msg, *field1;
    636    
    637     field1 = owl_zephyr_get_field(n, 1);
    638    
    639     msg = g_strdup_printf("MOIRA %s on %s: %s", n->z_class_inst, owl_message_get_hostname(m), field1);
    640     g_free(field1);
    641     if (msg) {
    642       return msg;
    643     }
    644   }
    645 
    646   if (owl_zephyr_get_num_fields(n) == 1) {
    647     return(owl_zephyr_get_field(n, 1));
    648   }
    649   else {
    650     return(owl_zephyr_get_field(n, 2));
    651   }
     620    msg = g_strdup_printf("MOIRA %s on %s: %s",
     621                          n->z_class_inst,
     622                          owl_message_get_hostname(m),
     623                          fields[1]);
     624  } else {
     625    if (owl_zephyr_get_num_fields(n) == 1)
     626      msg = g_strdup(fields[1]);
     627    else
     628      msg = g_strdup(fields[2]);
     629  }
     630
     631  for (i = 0; i < OWL_NFIELDS; i++)
     632    g_free(fields[i + 1]);
     633
     634  return msg;
    652635}
    653636#endif
Note: See TracChangeset for help on using the changeset viewer.