--- packet-sip.c.old	2003-09-01 19:25:03.000000000 +0200
+++ packet-sip.c	2003-09-01 19:03:05.000000000 +0200
@@ -49,6 +49,8 @@
 #include <string.h>
 #include <ctype.h>
 
+#include "prefs.h"
+
 #include <glib.h>
 #include <epan/packet.h>
 
@@ -57,6 +59,7 @@
 
 /* Initialize the protocol and registered fields */
 static gint proto_sip = -1;
+static gint proto_raw_sip = -1;
 static gint hf_msg_hdr = -1;
 static gint hf_Method = -1;
 static gint hf_Status_Code = -1;
@@ -65,6 +68,7 @@
 static gint ett_sip = -1;
 static gint ett_sip_reqresp = -1;
 static gint ett_sip_hdr = -1;
+static gint ett_raw_text = -1;
 
 static const char *sip_methods[] = {
         "<Invalid method>",      /* Pad so that the real methods start at index 1 */
@@ -253,6 +257,12 @@
 	OTHER_LINE
 } line_type_t;
 
+/* global_sip_raw_text determines whether we are going to display		*/
+/* the raw text of the SIP message, much like the MEGACO dissector does.	*/
+
+static gboolean global_sip_raw_text = FALSE;
+
+
 static gboolean dissect_sip_common(tvbuff_t *tvb, packet_info *pinfo,
     proto_tree *tree, gboolean is_heur);
 static line_type_t sip_parse_line(tvbuff_t *tvb, gint eol, guint *token_1_len);
@@ -267,9 +277,39 @@
 static dissector_handle_t sdp_handle;
 static dissector_handle_t data_handle;
 
+static void 
+tvb_raw_text_add(tvbuff_t *tvb, proto_tree *tree);
+
+
 #define SIP2_HDR "SIP/2.0"
 #define SIP2_HDR_LEN (strlen (SIP2_HDR))
 
+
+
+/* Copied from MGCP dissector, prints whole message in raw text */
+
+static void tvb_raw_text_add(tvbuff_t *tvb, proto_tree *tree){
+
+  proto_tree *raw_tree;
+  proto_item *ti;
+  gint tvb_linebegin,tvb_lineend,tvb_len,linelen;
+
+  ti = proto_tree_add_item(tree, proto_raw_sip, tvb, 0, -1, FALSE);
+  raw_tree = proto_item_add_subtree(ti, ett_raw_text);
+
+  tvb_linebegin = 0;
+  tvb_len = tvb_length(tvb);
+
+  do {
+    tvb_find_line_end(tvb,tvb_linebegin,-1,&tvb_lineend,FALSE);
+    linelen = tvb_lineend - tvb_linebegin;
+    proto_tree_add_text(raw_tree, tvb, tvb_linebegin, linelen,
+			"%s", tvb_format_text(tvb,tvb_linebegin,
+					      linelen));
+    tvb_linebegin = tvb_lineend;
+  } while ( tvb_lineend < tvb_len );
+}
+
 /* Code to actually dissect the packets */
 static void
 dissect_sip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
@@ -288,7 +328,7 @@
     gboolean is_heur)
 {
         int offset;
-        gint eol, next_offset, msg_offset;
+        gint eol, next_offset, msg_offset, tvb_len;
 	line_type_t line_type;
         tvbuff_t *next_tvb;
         gboolean is_known_request;
@@ -468,7 +508,11 @@
                 next_tvb = tvb_new_subset(tvb, msg_offset, -1, -1);
                 call_dissector(sdp_handle, next_tvb, pinfo, tree);
         }
+	if(global_sip_raw_text){
+	  tvb_len = tvb_length(tvb);
 
+	tvb_raw_text_add(tvb_new_subset(tvb,0,tvb_len,-1), tree);
+	}
         return TRUE;
 
   bad:
@@ -660,6 +704,7 @@
 static gint sip_is_known_sip_header(tvbuff_t *tvb, int offset, guint header_len)
 {
         guint i;
+	  
 
         for (i = 1; i < array_length(sip_headers); i++) {
                 if (header_len == strlen(sip_headers[i]) &&
@@ -670,6 +715,8 @@
         return -1;
 }
 
+
+
 /* Register the protocol with Ethereal */
 void proto_register_sip(void)
 {
@@ -940,6 +987,8 @@
 		
         };
 
+
+
         /* Setup protocol subtree array */
         static gint *ett[] = {
                 &ett_sip,
@@ -947,13 +996,33 @@
                 &ett_sip_hdr,
         };
 
+        static gint *ett_raw[] = {
+                &ett_raw_text,
+        };
+
+	  module_t *sip_module;
+
         /* Register the protocol name and description */
         proto_sip = proto_register_protocol("Session Initiation Protocol",
             "SIP", "sip");
+        proto_raw_sip = proto_register_protocol("Session Initiation Protocol (SIP as raw text)",
+            "Raw_SIP", "raw_sip");
 
         /* Required function calls to register the header fields and subtrees used */
         proto_register_field_array(proto_sip, hf, array_length(hf));
         proto_register_subtree_array(ett, array_length(ett));
+        proto_register_subtree_array(ett_raw, array_length(ett_raw));
+
+      sip_module = prefs_register_protocol(proto_sip, NULL);
+
+	prefs_register_bool_preference(sip_module, "display_raw_text",
+		"Display raw text for SIP message",
+		"Specifies that the raw text of the "
+		"SIP message should be displayed "
+		"in addition to the dissection tree",
+		&global_sip_raw_text);
+	
+
 }
 
 void
