For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-mmse.c
index 895dcec855415e94f998eb466fed5baa5b3b9782..ea65607f12896b02dc1fddf5498dd669731697e5 100644 (file)
@@ -5,8 +5,8 @@
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
@@ -48,7 +48,6 @@
 #include "packet-wap.h"
 #include "packet-wsp.h"
 /* #include "packet-mmse.h" */         /* We autoregister      */
-#include <epan/emem.h>
 
 #define        MM_QUOTE                0x7F    /* Quoted string        */
 
 #define DebugLog(x) ;
 #endif
 
-
 /*
  * Forward declarations
  */
 static void dissect_mmse_standalone(tvbuff_t *, packet_info *, proto_tree *);
-static void dissect_mmse_encapsulated(tvbuff_t *, packet_info *, proto_tree *);
 static void dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
        guint8 pdut, const char *message_type);
 
@@ -81,10 +78,10 @@ static void dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
  * Header field values
  */
 /* MMS 1.0 */
-#define MM_BCC_HDR             0x81    /* Bcc                  */
-#define MM_CC_HDR              0x82    /* Cc                   */
+#define MM_BCC_HDR             0x81    /* Bcc                          */
+#define MM_CC_HDR              0x82    /* Cc                           */
 #define MM_CLOCATION_HDR       0x83    /* X-Mms-Content-Location       */
-#define MM_CTYPE_HDR           0x84    /* Content-Type         */
+#define MM_CTYPE_HDR           0x84    /* Content-Type                 */
 #define MM_DATE_HDR            0x85    /* Date                         */
 #define MM_DREPORT_HDR         0x86    /* X-Mms-Delivery-Report        */
 #define MM_DTIME_HDR           0x87    /* X-Mms-Delivery-Time          */
@@ -178,8 +175,8 @@ static const value_string vals_mm_header_names[] = {
        { MM_PREV_SENT_DATE_HDR,        "X-Mms-Previously-Sent-Date" },
        /* MMS 1.2 */
        { MM_STORE_HDR,                 "X-Mms-Store" },
-       { MM_MM_STATE_HDR,              "X-Mms-MM-State " },
-       { MM_MM_FLAGS_HDR,              "X-Mms-MM-Flags " },
+       { MM_MM_STATE_HDR,              "X-Mms-MM-State" },
+       { MM_MM_FLAGS_HDR,              "X-Mms-MM-Flags" },
        { MM_STORE_STATUS_HDR,          "X-Mms-Store-Status" },
        { MM_STORE_STATUS_TEXT_HDR,     "X-Mms-Store-Status-Text" },
        { MM_STORED_HDR,                "X-Mms-Stored" },
@@ -237,7 +234,8 @@ static int hf_mmse_retrieve_status  = -1;
 static int hf_mmse_retrieve_text       = -1;
 static int hf_mmse_read_status         = -1;
 static int hf_mmse_reply_charging      = -1;
-static int hf_mmse_reply_charging_deadline     = -1;
+static int hf_mmse_reply_charging_deadline_abs = -1;
+static int hf_mmse_reply_charging_deadline_rel = -1;
 static int hf_mmse_reply_charging_id   = -1;
 static int hf_mmse_reply_charging_size = -1;
 static int hf_mmse_prev_sent_by        = -1;
@@ -376,7 +374,7 @@ static const value_string vals_response_status[] = {
     { 0xE9, "Permanent: Reply charging not supported" },
     /* MMS 1.2 */
     { 0xEA, "Permanent: Address hiding not supported" },
-    
+
     { 0x00, NULL },
 };
 
@@ -398,7 +396,7 @@ static const value_string vals_message_status[] = {
     { 0x86, "Forwarded" },
     /* MMS 1.2 */
     { 0x87, "Unreachable" },
-    
+
     { 0x00, NULL },
 };
 
@@ -439,13 +437,6 @@ static const value_string vals_reply_charging[] = {
     { 0x00, NULL },
 };
 
-static const value_string vals_reply_charging_deadline[] = {
-    { 0x80, "Absolute" },
-    { 0x81, "Relative" },
-
-    { 0x00, NULL },
-};
-
 /*!
  * Decodes a Text-string from the protocol data
  *     Text-string = [Quote] *TEXT End-of-string
@@ -463,18 +454,18 @@ static const value_string vals_reply_charging_deadline[] = {
  * \return             The length in bytes of the entire field
  */
 static guint
-get_text_string(tvbuff_t *tvb, guint offset, char **strval)
+get_text_string(tvbuff_t *tvb, guint offset, const char **strval)
 {
     guint       len;
 
-    DebugLog(("get_text_string(tvb = %p, offset = %u, **strval) - start\n", 
+    DebugLog(("get_text_string(tvb = %p, offset = %u, **strval) - start\n",
                tvb, offset));
     len = tvb_strsize(tvb, offset);
     DebugLog((" [1] tvb_strsize(tvb, offset) == %u\n", len));
     if (tvb_get_guint8(tvb, offset) == MM_QUOTE)
-       *strval = (char *)tvb_memcpy(tvb, ep_alloc(len-1), offset+1, len-1);
+       *strval = ep_tvb_memdup(tvb, offset+1, len-1);
     else
-       *strval = (char *)tvb_memcpy(tvb, ep_alloc(len), offset, len);
+       *strval = ep_tvb_memdup(tvb, offset, len);
     DebugLog((" [3] Return(len) == %u\n", len));
     return len;
 }
@@ -523,7 +514,7 @@ get_value_length(tvbuff_t *tvb, guint offset, guint *byte_count)
  * \return             The length in bytes of the entire field
  */
 static guint
-get_encoded_strval(tvbuff_t *tvb, guint offset, char **strval)
+get_encoded_strval(tvbuff_t *tvb, guint offset, const char **strval)
 {
     guint       field;
     guint       length;
@@ -677,8 +668,7 @@ dissect_mmse_standalone(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     message_type = val_to_str(pdut, vals_message_type, "Unknown type %u");
 
     /* Make entries in Protocol column and Info column on summary display */
-    if (check_col(pinfo->cinfo, COL_PROTOCOL))
-       col_set_str(pinfo->cinfo, COL_PROTOCOL, "MMSE");
+    col_set_str(pinfo->cinfo, COL_PROTOCOL, "MMSE");
 
     if (check_col(pinfo->cinfo, COL_INFO)) {
        col_clear(pinfo->cinfo, COL_INFO);
@@ -715,7 +705,7 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
 {
     guint       offset;
     guint8      field = 0;
-    char        *strval;
+    const char  *strval;
     guint       length;
     guint       count;
     guint8      version = 0x80; /* Default to MMSE 1.0 */
@@ -731,14 +721,14 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
      * columns must be set appropriately too.
      * If tree != NULL then we also want to display the protocol tree
      * with its fields.
-     * 
+     *
      * In the interest of speed, skip protocol tree item generation
      * if tree is NULL.
      */
     if (tree) {
        DebugLog(("tree != NULL\n"));
 
-       ti = proto_tree_add_item(tree, proto_mmse, tvb, 0, -1, FALSE);
+       ti = proto_tree_add_item(tree, proto_mmse, tvb, 0, -1, ENC_NA);
        proto_item_append_text(ti, ", Type: %s", message_type);
        /* create display subtree for the protocol */
        mmse_tree = proto_item_add_subtree(ti, ett_mmse);
@@ -777,16 +767,17 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                    version = tvb_get_guint8(tvb, offset++);
                    if (tree) {
                        guint8   major, minor;
+                       char    *vers_string;
 
                        major = (version & 0x70) >> 4;
                        minor = version & 0x0F;
                        if (minor == 0x0F)
-                           strval = g_strdup_printf("%u", major);
+                           vers_string = g_strdup_printf("%u", major);
                        else
-                           strval = g_strdup_printf("%u.%u", major, minor);
+                           vers_string = g_strdup_printf("%u.%u", major, minor);
                        proto_tree_add_string(mmse_tree, hf_mmse_mms_version,
-                               tvb, offset - 2, 2, strval);
-                       g_free(strval);
+                               tvb, offset - 2, 2, vers_string);
+                       g_free(vers_string);
                    }
                    break;
                case MM_BCC_HDR:                /* Encoded-string-value */
@@ -1123,12 +1114,32 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                    }
                    break;
                case MM_REPLY_CHARGING_DEADLINE_HDR:    /* Well-known-value */
-                   field = tvb_get_guint8(tvb, offset++);
+                   /*
+                    * Value-length(Absolute-token Date-value|
+                    *              Relative-token Delta-seconds-value)
+                    */
+                   length = get_value_length(tvb, offset, &count);
+                   field = tvb_get_guint8(tvb, offset + count);
                    if (tree) {
-                       proto_tree_add_uint(mmse_tree,
-                               hf_mmse_reply_charging_deadline,
-                               tvb, offset - 2, 2, field);
+                       guint            tval;
+                       nstime_t         tmptime;
+                       guint            cnt;
+
+                       tval = get_long_integer(tvb, offset + count + 1, &cnt);
+                       tmptime.secs = tval;
+                       tmptime.nsecs = 0;
+
+                       tvb_ensure_bytes_exist(tvb, offset - 1, length + count + 1);
+                       if (field == 0x80)
+                           proto_tree_add_time(mmse_tree, hf_mmse_reply_charging_deadline_abs,
+                                   tvb, offset - 1,
+                                   length + count + 1, &tmptime);
+                       else
+                           proto_tree_add_time(mmse_tree, hf_mmse_reply_charging_deadline_rel,
+                                   tvb, offset - 1,
+                                   length + count + 1, &tmptime);
                    }
+                   offset += length + count;
                    break;
                case MM_REPLY_CHARGING_ID_HDR:  /* Text-string */
                    length = get_text_string(tvb, offset, &strval);
@@ -1152,9 +1163,9 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                    /* Value-length Integer-value Encoded-string-value */
                    length = get_value_length(tvb, offset, &count);
                    if (tree) {
-                       guint32 fwd_count, count1, count2;                      
+                       guint32 fwd_count, count1, count2;
                        proto_tree *subtree = NULL;
-                       proto_item *ti = NULL;
+                       proto_item *tii = NULL;
                        /* 1. Forwarded-count-value := Integer-value */
                        fwd_count = get_integer_value(tvb, offset + count,
                            &count1);
@@ -1162,13 +1173,13 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                        count2 = get_encoded_strval(tvb,
                                offset + count + count1, &strval);
                        /* Now render the fields */
-                       ti = proto_tree_add_string_format(mmse_tree,
+                       tii = proto_tree_add_string_format(mmse_tree,
                                hf_mmse_prev_sent_by,
                                tvb, offset - 1, 1 + count + length,
                                strval, "%s (Forwarded-count=%u)",
                                format_text(strval, strlen(strval)),
                                fwd_count);
-                       subtree = proto_item_add_subtree(ti,
+                       subtree = proto_item_add_subtree(tii,
                                ett_mmse_hdr_details);
                        proto_tree_add_uint(subtree,
                                hf_mmse_prev_sent_by_fwd_count,
@@ -1183,11 +1194,11 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                    /* Value-Length Forwarded-count-value Date-value */
                    length = get_value_length(tvb, offset, &count);
                    if (tree) {
-                       guint32 fwd_count, count1, count2;                      
+                       guint32 fwd_count, count1, count2;
                        guint            tval;
                        nstime_t         tmptime;
                        proto_tree *subtree = NULL;
-                       proto_item *ti = NULL;
+                       proto_item *tii = NULL;
                        /* 1. Forwarded-count-value := Integer-value */
                        fwd_count = get_integer_value(tvb, offset + count,
                            &count1);
@@ -1196,16 +1207,17 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                                &count2);
                        tmptime.secs = tval;
                        tmptime.nsecs = 0;
-                       strval = abs_time_to_str(&tmptime);
+                       strval = abs_time_to_str(&tmptime, ABSOLUTE_TIME_LOCAL,
+                           TRUE);
                        /* Now render the fields */
                        tvb_ensure_bytes_exist(tvb, offset - 1, length + count + 1);
-                       ti = proto_tree_add_string_format(mmse_tree,
+                       tii = proto_tree_add_string_format(mmse_tree,
                                hf_mmse_prev_sent_date,
                                tvb, offset - 1, 1 + count + length,
                                strval, "%s (Forwarded-count=%u)",
                                format_text(strval, strlen(strval)),
                                fwd_count);
-                       subtree = proto_item_add_subtree(ti,
+                       subtree = proto_item_add_subtree(tii,
                                ett_mmse_hdr_details);
                        proto_tree_add_uint(subtree,
                                hf_mmse_prev_sent_date_fwd_count,
@@ -1262,8 +1274,8 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                        }
                        offset += length;
                    } else { /* Literal WSP header encoding */
-                       guint    length2;
-                       char     *strval2;
+                       guint            length2;
+                       const char       *strval2;
 
                        --offset;
                        length = get_text_string(tvb, offset, &strval);
@@ -1275,8 +1287,8 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
                            proto_tree_add_string_format(mmse_tree,
                                    hf_mmse_ffheader, tvb, offset,
                                    length + length2,
-                                   (const char *) tvb_get_ptr(
-                                           tvb, offset, length + length2),
+                                   tvb_get_ephemeral_string(tvb, offset,
+                                           length + length2),
                                    "%s: %s",
                                    format_text(strval, strlen(strval)),
                                    format_text(strval2, strlen(strval2)));
@@ -1301,7 +1313,7 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
            DebugLog(("Calling add_content_type() in WSP dissector\n"));
            offset = add_content_type(mmse_tree, tvb, offset, &type, &type_str);
            DebugLog(("Generating new TVB subset (offset = %u)\n", offset));
-           tmp_tvb = tvb_new_subset(tvb, offset, -1, -1);
+           tmp_tvb = tvb_new_subset_remaining(tvb, offset);
            DebugLog(("Add POST data\n"));
            add_post_data(mmse_tree, tmp_tvb, type, type_str, pinfo);
            DebugLog(("Done!\n"));
@@ -1315,7 +1327,7 @@ dissect_mmse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 pdut,
 }
 
 
-/* Register the protocol with Ethereal */
+/* Register the protocol with Wireshark */
 
 /* this format is required because a script is used to build the C function
  * that calls all the protocol registration.
@@ -1335,8 +1347,7 @@ proto_register_mmse(void)
        {   &hf_mmse_transaction_id,
            {   "X-Mms-Transaction-ID", "mmse.transaction_id",
                FT_STRING, BASE_NONE, NULL, 0x00,
-               "A unique identifier for this transaction. "
-               "Identifies request and corresponding response only.",
+               "A unique identifier for this transaction. Identifies request and corresponding response only.",
                HFILL
            }
        },
@@ -1370,7 +1381,7 @@ proto_register_mmse(void)
        },
        {   &hf_mmse_date,
            {   "Date", "mmse.date",
-               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
+               FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
                "Arrival timestamp of the message or sending timestamp.",
                HFILL
            }
@@ -1384,7 +1395,7 @@ proto_register_mmse(void)
        },
        {   &hf_mmse_delivery_time_abs,
            {   "X-Mms-Delivery-Time", "mmse.delivery_time.abs",
-               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
+               FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
                "The time at which message delivery is desired.",
                HFILL
            }
@@ -1398,7 +1409,7 @@ proto_register_mmse(void)
        },
        {   &hf_mmse_expiry_abs,
            {   "X-Mms-Expiry", "mmse.expiry.abs",
-               FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x00,
+               FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
                "Time when message expires and need not be delivered anymore.",
                HFILL
            }
@@ -1558,10 +1569,17 @@ proto_register_mmse(void)
                HFILL
            }
        },
-       {   &hf_mmse_reply_charging_deadline,
-           {   "X-Mms-Reply-Charging-Deadline", "mmse.reply_charging_deadline",
-               FT_UINT8, BASE_HEX, VALS(vals_reply_charging_deadline), 0x00,
-               "MMS-specific message reply charging deadline type.",
+       {   &hf_mmse_reply_charging_deadline_abs,
+           {   "X-Mms-Reply-Charging-Deadline", "mmse.reply_charging_deadline.abs",
+               FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x00,
+               "The latest time of the recipient(s) to submit the Reply MM.",
+               HFILL
+           }
+       },
+       {   &hf_mmse_reply_charging_deadline_rel,
+           {   "X-Mms-Reply-Charging-Deadline", "mmse.reply_charging_deadline.rel",
+               FT_RELATIVE_TIME, BASE_NONE, NULL, 0x00,
+               "The latest time of the recipient(s) to submit the Reply MM.",
                HFILL
            }
        },