HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-pgsql.c
blobcfe3ad16bfa777579b2b45417ed0410ee4ca78fa
1 /* packet-pgsql.c
2 * Routines for PostgreSQL v3 protocol dissection.
3 * <http://www.postgresql.org/docs/current/static/protocol.html>
4 * Copyright 2004 Abhijit Menon-Sen <ams@oryx.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "config.h"
29 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/conversation.h>
32 #include <epan/prefs.h>
34 #include "packet-tcp.h"
37 static int proto_pgsql = -1;
38 static int hf_frontend = -1;
39 static int hf_type = -1;
40 static int hf_length = -1;
41 static int hf_parameter_name = -1;
42 static int hf_parameter_value = -1;
43 static int hf_query = -1;
44 static int hf_authtype = -1;
45 static int hf_passwd = -1;
46 static int hf_salt = -1;
47 static int hf_statement = -1;
48 static int hf_portal = -1;
49 static int hf_tag = -1;
50 static int hf_status = -1;
51 static int hf_copydata = -1;
52 static int hf_error = -1;
53 static int hf_pid = -1;
54 static int hf_key = -1;
55 static int hf_condition = -1;
56 static int hf_text = -1;
57 static int hf_tableoid = -1;
58 static int hf_typeoid = -1;
59 static int hf_oid = -1;
60 static int hf_format = -1;
61 static int hf_field_count = -1;
62 static int hf_val_name = -1;
63 static int hf_val_idx = -1;
64 static int hf_val_length = -1;
65 static int hf_val_data = -1;
66 static int hf_val_mod = -1;
67 static int hf_severity = -1;
68 static int hf_code = -1;
69 static int hf_message = -1;
70 static int hf_detail = -1;
71 static int hf_hint = -1;
72 static int hf_position = -1;
73 static int hf_where = -1;
74 static int hf_file = -1;
75 static int hf_line = -1;
76 static int hf_routine = -1;
78 static gint ett_pgsql = -1;
79 static gint ett_values = -1;
81 static guint pgsql_port = 5432;
82 static gboolean pgsql_desegment = TRUE;
83 static gboolean first_message = TRUE;
85 static const value_string fe_messages[] = {
86 { 'p', "Password message" },
87 { 'Q', "Simple query" },
88 { 'P', "Parse" },
89 { 'B', "Bind" },
90 { 'E', "Execute" },
91 { 'D', "Describe" },
92 { 'C', "Close" },
93 { 'H', "Flush" },
94 { 'S', "Sync" },
95 { 'F', "Function call" },
96 { 'd', "Copy data" },
97 { 'c', "Copy completion" },
98 { 'f', "Copy failure" },
99 { 'X', "Termination" },
100 { 0, NULL }
103 static const value_string be_messages[] = {
104 { 'R', "Authentication request" },
105 { 'K', "Backend key data" },
106 { 'S', "Parameter status" },
107 { '1', "Parse completion" },
108 { '2', "Bind completion" },
109 { '3', "Close completion" },
110 { 'C', "Command completion" },
111 { 't', "Parameter description" },
112 { 'T', "Row description" },
113 { 'D', "Data row" },
114 { 'I', "Empty query" },
115 { 'n', "No data" },
116 { 'E', "Error" },
117 { 'N', "Notice" },
118 { 's', "Portal suspended" },
119 { 'Z', "Ready for query" },
120 { 'A', "Notification" },
121 { 'V', "Function call response" },
122 { 'G', "CopyIn response" },
123 { 'H', "CopyOut response" },
124 { 'd', "Copy data" },
125 { 'c', "Copy completion" },
126 { 0, NULL }
130 static const value_string auth_types[] = {
131 { 0, "Success" },
132 { 1, "Kerberos V4" },
133 { 2, "Kerberos V5" },
134 { 3, "Plaintext password" },
135 { 4, "crypt()ed password" },
136 { 5, "MD5 password" },
137 { 6, "SCM credentials" },
138 { 0, NULL }
141 static const value_string status_vals[] = {
142 { 'I', "Idle" },
143 { 'T', "In a transaction" },
144 { 'E', "In a failed transaction" },
145 { 0, NULL }
148 static const value_string format_vals[] = {
149 { 0, "Text" },
150 { 1, "Binary" },
151 { 0, NULL }
154 static void dissect_pgsql_fe_msg(guchar type, guint length, tvbuff_t *tvb,
155 gint n, proto_tree *tree)
157 guchar c;
158 gint i, siz;
159 char *s;
160 proto_item *ti, *hidden_item;
161 proto_tree *shrub;
163 switch (type) {
164 /* Password */
165 case 'p':
166 siz = tvb_strsize(tvb, n);
167 proto_tree_add_item(tree, hf_passwd, tvb, n, siz, ENC_ASCII|ENC_NA);
168 break;
170 /* Simple query */
171 case 'Q':
172 siz = tvb_strsize(tvb, n);
173 proto_tree_add_item(tree, hf_query, tvb, n, siz, ENC_ASCII|ENC_NA);
174 break;
176 /* Parse */
177 case 'P':
178 siz = tvb_strsize(tvb, n);
179 proto_tree_add_item(tree, hf_statement, tvb, n, siz, ENC_ASCII|ENC_NA);
180 n += siz;
182 siz = tvb_strsize(tvb, n);
183 proto_tree_add_item(tree, hf_query, tvb, n, siz, ENC_ASCII|ENC_NA);
184 n += siz;
186 i = tvb_get_ntohs(tvb, n);
187 ti = proto_tree_add_text(tree, tvb, n, 2, "Parameters: %d", i);
188 shrub = proto_item_add_subtree(ti, ett_values);
189 n += 2;
190 while (i-- > 0) {
191 proto_tree_add_item(shrub, hf_typeoid, tvb, n, 4, ENC_BIG_ENDIAN);
192 n += 4;
194 break;
196 /* Bind */
197 case 'B':
198 siz = tvb_strsize(tvb, n);
199 proto_tree_add_item(tree, hf_portal, tvb, n, siz, ENC_ASCII|ENC_NA);
200 n += siz;
202 siz = tvb_strsize(tvb, n);
203 proto_tree_add_item(tree, hf_statement, tvb, n, siz, ENC_ASCII|ENC_NA);
204 n += siz;
206 i = tvb_get_ntohs(tvb, n);
207 ti = proto_tree_add_text(tree, tvb, n, 2, "Parameter formats: %d", i);
208 shrub = proto_item_add_subtree(ti, ett_values);
209 n += 2;
210 while (i-- > 0) {
211 proto_tree_add_item(shrub, hf_format, tvb, n, 2, ENC_BIG_ENDIAN);
212 n += 2;
215 i = tvb_get_ntohs(tvb, n);
216 ti = proto_tree_add_text(tree, tvb, n, 2, "Parameter values: %d", i);
217 shrub = proto_item_add_subtree(ti, ett_values);
218 n += 2;
219 while (i-- > 0) {
220 siz = tvb_get_ntohl(tvb, n);
221 proto_tree_add_int(shrub, hf_val_length, tvb, n, 4, siz);
222 n += 4;
223 if (siz > 0) {
224 proto_tree_add_item(shrub, hf_val_data, tvb, n, siz, ENC_NA);
225 n += siz;
229 i = tvb_get_ntohs(tvb, n);
230 ti = proto_tree_add_text(tree, tvb, n, 2, "Result formats: %d", i);
231 shrub = proto_item_add_subtree(ti, ett_values);
232 n += 2;
233 while (i-- > 0) {
234 proto_tree_add_item(shrub, hf_format, tvb, n, 2, ENC_BIG_ENDIAN);
235 n += 2;
237 break;
239 /* Execute */
240 case 'E':
241 siz = tvb_strsize(tvb, n);
242 proto_tree_add_item(tree, hf_portal, tvb, n, siz, ENC_ASCII|ENC_NA);
243 n += siz;
245 ti = proto_tree_add_text(tree, tvb, n, 4, "Returns: ");
246 i = tvb_get_ntohl(tvb, n);
247 if (i == 0)
248 proto_item_append_text(ti, "all");
249 else
250 proto_item_append_text(ti, "%d", i);
251 proto_item_append_text(ti, " rows");
252 break;
254 /* Describe, Close */
255 case 'D':
256 case 'C':
257 c = tvb_get_guint8(tvb, n);
258 if (c == 'P')
259 i = hf_portal;
260 else
261 i = hf_statement;
263 if (i != 0) {
264 n += 1;
265 s = tvb_get_stringz(wmem_packet_scope(), tvb, n, &siz);
266 hidden_item = proto_tree_add_string(tree, i, tvb, n, siz, s);
267 PROTO_ITEM_SET_HIDDEN(hidden_item);
268 proto_tree_add_text(
269 tree, tvb, n-1, siz, "%s: %s",
270 (c == 'P' ? "Portal" : "Statement"), s
273 break;
275 /* Messages without a type identifier */
276 case '\0':
277 i = tvb_get_ntohl(tvb, n);
278 n += 4;
279 length -= n;
280 switch (i) {
281 /* Startup message */
282 case 196608:
283 while ((signed)length > 0) {
284 siz = tvb_strsize(tvb, n);
285 length -= siz;
286 if ((signed)length <= 0) {
287 break;
289 proto_tree_add_item(tree, hf_parameter_name, tvb, n, siz, ENC_ASCII|ENC_NA);
290 i = tvb_strsize(tvb, n+siz);
291 proto_tree_add_item(tree, hf_parameter_value, tvb, n + siz, i, ENC_ASCII|ENC_NA);
292 length -= i;
294 n += siz+i;
295 if (length == 1 && tvb_get_guint8(tvb, n) == 0)
296 break;
298 break;
300 /* SSL request */
301 case 80877103:
302 /* There's nothing to parse here, but what do we do if the
303 SSL negotiation succeeds? */
304 break;
306 /* Cancellation request */
307 case 80877102:
308 proto_tree_add_item(tree, hf_pid, tvb, n, 4, ENC_BIG_ENDIAN);
309 proto_tree_add_item(tree, hf_key, tvb, n+4, 4, ENC_BIG_ENDIAN);
310 break;
312 break;
314 /* Copy data */
315 case 'd':
316 proto_tree_add_item(tree, hf_copydata, tvb, n, length-n+1, ENC_NA);
317 break;
319 /* Copy failure */
320 case 'f':
321 siz = tvb_strsize(tvb, n);
322 proto_tree_add_item(tree, hf_error, tvb, n, siz, ENC_ASCII|ENC_NA);
323 break;
325 /* Function call */
326 case 'F':
327 proto_tree_add_item(tree, hf_oid, tvb, n, 4, ENC_BIG_ENDIAN);
328 n += 4;
330 i = tvb_get_ntohs(tvb, n);
331 ti = proto_tree_add_text(tree, tvb, n, 2, "Parameter formats: %d", i);
332 shrub = proto_item_add_subtree(ti, ett_values);
333 n += 2;
334 while (i-- > 0) {
335 proto_tree_add_item(shrub, hf_format, tvb, n, 2, ENC_BIG_ENDIAN);
336 n += 2;
339 i = tvb_get_ntohs(tvb, n);
340 ti = proto_tree_add_text(tree, tvb, n, 2, "Parameter values: %d", i);
341 shrub = proto_item_add_subtree(ti, ett_values);
342 n += 2;
343 while (i-- > 0) {
344 siz = tvb_get_ntohl(tvb, n);
345 proto_tree_add_item(shrub, hf_val_length, tvb, n, 4, ENC_BIG_ENDIAN);
346 n += 4;
347 if (siz > 0) {
348 proto_tree_add_item(shrub, hf_val_data, tvb, n, siz, ENC_NA);
349 n += siz;
353 proto_tree_add_item(tree, hf_format, tvb, n, 2, ENC_BIG_ENDIAN);
354 break;
359 static void dissect_pgsql_be_msg(guchar type, guint length, tvbuff_t *tvb,
360 gint n, proto_tree *tree)
362 guchar c;
363 gint i, siz;
364 char *s, *t;
365 proto_item *ti, *hidden_item;
366 proto_tree *shrub;
368 switch (type) {
369 /* Authentication request */
370 case 'R':
371 proto_tree_add_item(tree, hf_authtype, tvb, n, 4, ENC_BIG_ENDIAN);
372 i = tvb_get_ntohl(tvb, n);
373 if (i == 4 || i == 5) {
374 /* i -= (6-i); :-) */
375 n += 4;
376 siz = (i == 4 ? 2 : 4);
377 proto_tree_add_item(tree, hf_salt, tvb, n, siz, ENC_NA);
379 break;
381 /* Key data */
382 case 'K':
383 proto_tree_add_item(tree, hf_pid, tvb, n, 4, ENC_BIG_ENDIAN);
384 proto_tree_add_item(tree, hf_key, tvb, n+4, 4, ENC_BIG_ENDIAN);
385 break;
387 /* Parameter status */
388 case 'S':
389 s = tvb_get_stringz(wmem_packet_scope(), tvb, n, &siz);
390 hidden_item = proto_tree_add_string(tree, hf_parameter_name, tvb, n, siz, s);
391 PROTO_ITEM_SET_HIDDEN(hidden_item);
392 n += siz;
393 t = tvb_get_stringz(wmem_packet_scope(), tvb, n, &i);
394 hidden_item = proto_tree_add_string(tree, hf_parameter_value, tvb, n, i, t);
395 PROTO_ITEM_SET_HIDDEN(hidden_item);
396 proto_tree_add_text(tree, tvb, n-siz, siz+i, "%s: %s", s, t);
397 break;
399 /* Parameter description */
400 case 't':
401 i = tvb_get_ntohs(tvb, n);
402 proto_tree_add_text(tree, tvb, n, 2, "Parameters: %d", i);
403 n += 2;
404 while (i-- > 0) {
405 proto_tree_add_item(tree, hf_typeoid, tvb, n, 4, ENC_BIG_ENDIAN);
406 n += 4;
408 break;
410 /* Row description */
411 case 'T':
412 i = tvb_get_ntohs(tvb, n);
413 ti = proto_tree_add_item(tree, hf_field_count, tvb, n, 2, ENC_BIG_ENDIAN);
414 shrub = proto_item_add_subtree(ti, ett_values);
415 n += 2;
416 while (i-- > 0) {
417 proto_tree *twig;
418 siz = tvb_strsize(tvb, n);
419 ti = proto_tree_add_item(shrub, hf_val_name, tvb, n, siz, ENC_ASCII|ENC_NA);
420 twig = proto_item_add_subtree(ti, ett_values);
421 n += siz;
422 proto_tree_add_item(twig, hf_tableoid, tvb, n, 4, ENC_BIG_ENDIAN);
423 n += 4;
424 proto_tree_add_item(twig, hf_val_idx, tvb, n, 2, ENC_BIG_ENDIAN);
425 n += 2;
426 proto_tree_add_item(twig, hf_typeoid, tvb, n, 4, ENC_BIG_ENDIAN);
427 n += 4;
428 proto_tree_add_item(twig, hf_val_length, tvb, n, 2, ENC_BIG_ENDIAN);
429 n += 2;
430 proto_tree_add_item(twig, hf_val_mod, tvb, n, 4, ENC_BIG_ENDIAN);
431 n += 4;
432 proto_tree_add_item(twig, hf_format, tvb, n, 2, ENC_BIG_ENDIAN);
433 n += 2;
435 break;
437 /* Data row */
438 case 'D':
439 i = tvb_get_ntohs(tvb, n);
440 ti = proto_tree_add_item(tree, hf_field_count, tvb, n, 2, ENC_BIG_ENDIAN);
441 shrub = proto_item_add_subtree(ti, ett_values);
442 n += 2;
443 while (i-- > 0) {
444 siz = tvb_get_ntohl(tvb, n);
445 proto_tree_add_int(shrub, hf_val_length, tvb, n, 4, siz);
446 n += 4;
447 if (siz > 0) {
448 proto_tree_add_item(shrub, hf_val_data, tvb, n, siz, ENC_NA);
449 n += siz;
452 break;
454 /* Command completion */
455 case 'C':
456 siz = tvb_strsize(tvb, n);
457 proto_tree_add_item(tree, hf_tag, tvb, n, siz, ENC_ASCII|ENC_NA);
458 break;
460 /* Ready */
461 case 'Z':
462 proto_tree_add_item(tree, hf_status, tvb, n, 1, ENC_NA);
463 break;
465 /* Error, Notice */
466 case 'E':
467 case 'N':
468 length -= 4;
469 while ((signed)length > 0) {
470 c = tvb_get_guint8(tvb, n);
471 if (c == '\0')
472 break;
473 s = tvb_get_stringz(wmem_packet_scope(), tvb, n+1, &siz);
474 i = hf_text;
475 switch (c) {
476 case 'S': i = hf_severity; break;
477 case 'C': i = hf_code; break;
478 case 'M': i = hf_message; break;
479 case 'D': i = hf_detail; break;
480 case 'H': i = hf_hint; break;
481 case 'P': i = hf_position; break;
482 case 'W': i = hf_where; break;
483 case 'F': i = hf_file; break;
484 case 'L': i = hf_line; break;
485 case 'R': i = hf_routine; break;
487 proto_tree_add_string(tree, i, tvb, n, siz+1, s);
488 length -= siz+1;
489 n += siz+1;
491 break;
493 /* NOTICE response */
494 case 'A':
495 proto_tree_add_item(tree, hf_pid, tvb, n, 4, ENC_BIG_ENDIAN);
496 n += 4;
497 siz = tvb_strsize(tvb, n);
498 proto_tree_add_item(tree, hf_condition, tvb, n, siz, ENC_ASCII|ENC_NA);
499 n += siz;
500 siz = tvb_strsize(tvb, n);
501 if (siz > 1)
502 proto_tree_add_item(tree, hf_text, tvb, n, siz, ENC_ASCII|ENC_NA);
503 break;
505 /* Copy in/out */
506 case 'G':
507 case 'H':
508 proto_tree_add_item(tree, hf_format, tvb, n, 1, ENC_BIG_ENDIAN);
509 n += 1;
510 i = tvb_get_ntohs(tvb, n);
511 ti = proto_tree_add_text(tree, tvb, n, 2, "Columns: %d", i);
512 shrub = proto_item_add_subtree(ti, ett_values);
513 n += 2;
514 while (i-- > 2) {
515 proto_tree_add_item(shrub, hf_format, tvb, n, 2, ENC_BIG_ENDIAN);
516 n += 2;
518 break;
520 /* Copy data */
521 case 'd':
522 proto_tree_add_item(tree, hf_copydata, tvb, n, length-n+1, ENC_NA);
523 break;
525 /* Function call response */
526 case 'V':
527 siz = tvb_get_ntohl(tvb, n);
528 proto_tree_add_int(tree, hf_val_length, tvb, n, 4, siz);
529 if (siz > 0)
530 proto_tree_add_item(tree, hf_val_data, tvb, n+4, siz, ENC_NA);
531 break;
535 /* This function is called by tcp_dissect_pdus() to find the size of the
536 message starting at tvb[offset]. */
537 static guint
538 pgsql_length(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
540 gint n = 0;
541 guchar type;
542 guint length;
544 /* The length is either the four bytes after the type, or, if the
545 type is 0, the first four bytes. */
546 type = tvb_get_guint8(tvb, offset);
547 if (type != '\0')
548 n = 1;
549 length = tvb_get_ntohl(tvb, offset+n);
550 return length+n;
554 /* This function is responsible for dissecting a single message. */
556 static int
557 dissect_pgsql_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
559 proto_item *ti, *hidden_item;
560 proto_tree *ptree;
562 gint n;
563 guchar type;
564 const char *typestr;
565 guint length;
566 gboolean fe = (pinfo->match_uint == pinfo->destport);
568 n = 0;
569 type = tvb_get_guint8(tvb, 0);
570 if (type != '\0')
571 n += 1;
572 length = tvb_get_ntohl(tvb, n);
574 /* This is like specifying VALS(messages) for hf_type, which we can't do
575 directly because of messages without type bytes, and because the type
576 interpretation depends on fe. */
577 if (fe) {
578 /* There are a few frontend messages that have no leading type byte.
579 We identify them by the fact that the first byte of their length
580 must be zero, and that the next four bytes are a unique tag. */
581 if (type == '\0') {
582 guint tag = tvb_get_ntohl(tvb, 4);
584 if (length == 16 && tag == 80877102)
585 typestr = "Cancel request";
586 else if (length == 8 && tag == 80877103)
587 typestr = "SSL request";
588 else if (tag == 196608)
589 typestr = "Startup message";
590 else
591 typestr = "Unknown";
592 } else
593 typestr = val_to_str_const(type, fe_messages, "Unknown");
595 else {
596 typestr = val_to_str_const(type, be_messages, "Unknown");
599 /* This is a terrible hack. It makes the "Info" column reflect
600 the contents of every message in a TCP packet. Could it be
601 done any better? */
602 col_append_fstr(pinfo->cinfo, COL_INFO, "%s%c",
603 ( first_message ? "" : "/" ), type);
604 first_message = FALSE;
606 if (tree) {
607 ti = proto_tree_add_item(tree, proto_pgsql, tvb, 0, -1, ENC_NA);
608 ptree = proto_item_add_subtree(ti, ett_pgsql);
610 n = 1;
611 if (type == '\0')
612 n = 0;
613 proto_tree_add_text(ptree, tvb, 0, n, "Type: %s", typestr);
614 hidden_item = proto_tree_add_item(ptree, hf_type, tvb, 0, n, ENC_ASCII|ENC_NA);
615 PROTO_ITEM_SET_HIDDEN(hidden_item);
616 proto_tree_add_item(ptree, hf_length, tvb, n, 4, ENC_BIG_ENDIAN);
617 hidden_item = proto_tree_add_boolean(ptree, hf_frontend, tvb, 0, 0, fe);
618 PROTO_ITEM_SET_HIDDEN(hidden_item);
619 n += 4;
621 if (fe)
622 dissect_pgsql_fe_msg(type, length, tvb, n, ptree);
623 else
624 dissect_pgsql_be_msg(type, length, tvb, n, ptree);
627 return tvb_length(tvb);
630 /* This function is called once per TCP packet. It sets COL_PROTOCOL and
631 * identifies FE/BE messages by adding a ">" or "<" to COL_INFO. Then it
632 * arranges for each message to be dissected individually. */
634 static int
635 dissect_pgsql(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
637 /* conversation_t *cv; */
639 first_message = TRUE;
641 /* We don't use conversation data yet, but... */
642 /* cv = find_or_create_conversation(pinfo); */
644 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PGSQL");
645 col_set_str(pinfo->cinfo, COL_INFO,
646 (pinfo->match_uint == pinfo->destport) ?
647 ">" : "<");
649 tcp_dissect_pdus(tvb, pinfo, tree, pgsql_desegment, 5,
650 pgsql_length, dissect_pgsql_msg, data);
651 return tvb_length(tvb);
654 void
655 proto_reg_handoff_pgsql(void);
657 void
658 proto_register_pgsql(void)
660 static hf_register_info hf[] = {
661 { &hf_frontend,
662 { "Frontend", "pgsql.frontend", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
663 "True for messages from the frontend, false otherwise.",
664 HFILL }
666 { &hf_type,
667 { "Type", "pgsql.type", FT_STRING, BASE_NONE, NULL, 0,
668 "A one-byte message type identifier.", HFILL }
670 { &hf_length,
671 { "Length", "pgsql.length", FT_UINT32, BASE_DEC, NULL, 0,
672 "The length of the message (not including the type).",
673 HFILL }
675 { &hf_parameter_name,
676 { "Parameter name", "pgsql.parameter_name", FT_STRINGZ,
677 BASE_NONE, NULL, 0, "The name of a database parameter.",
678 HFILL }
680 { &hf_parameter_value,
681 { "Parameter value", "pgsql.parameter_value", FT_STRINGZ,
682 BASE_NONE, NULL, 0, "The value of a database parameter.",
683 HFILL }
685 { &hf_query,
686 { "Query", "pgsql.query", FT_STRINGZ, BASE_NONE, NULL, 0,
687 "A query string.", HFILL }
689 { &hf_passwd,
690 { "Password", "pgsql.password", FT_STRINGZ, BASE_NONE, NULL, 0,
691 "A password.", HFILL }
693 { &hf_authtype,
694 { "Authentication type", "pgsql.authtype", FT_INT32, BASE_DEC,
695 VALS(auth_types), 0,
696 "The type of authentication requested by the backend.", HFILL }
698 { &hf_salt,
699 { "Salt value", "pgsql.salt", FT_BYTES, BASE_NONE, NULL, 0,
700 "The salt to use while encrypting a password.", HFILL }
702 { &hf_statement,
703 { "Statement", "pgsql.statement", FT_STRINGZ, BASE_NONE, NULL, 0,
704 "The name of a prepared statement.", HFILL }
706 { &hf_portal,
707 { "Portal", "pgsql.portal", FT_STRINGZ, BASE_NONE, NULL, 0,
708 "The name of a portal.", HFILL }
710 { &hf_tag,
711 { "Tag", "pgsql.tag", FT_STRINGZ, BASE_NONE, NULL, 0,
712 "A completion tag.", HFILL }
714 { &hf_status,
715 { "Status", "pgsql.status", FT_UINT8, BASE_DEC, VALS(status_vals),
716 0, "The transaction status of the backend.", HFILL }
718 { &hf_copydata,
719 { "Copy data", "pgsql.copydata", FT_BYTES, BASE_NONE, NULL, 0,
720 "Data sent following a Copy-in or Copy-out response.", HFILL }
722 { &hf_error,
723 { "Error", "pgsql.error", FT_STRINGZ, BASE_NONE, NULL, 0,
724 "An error message.", HFILL }
726 { &hf_pid,
727 { "PID", "pgsql.pid", FT_UINT32, BASE_DEC, NULL, 0,
728 "The process ID of a backend.", HFILL }
730 { &hf_key,
731 { "Key", "pgsql.key", FT_UINT32, BASE_DEC, NULL, 0,
732 "The secret key used by a particular backend.", HFILL }
734 { &hf_condition,
735 { "Condition", "pgsql.condition", FT_STRINGZ, BASE_NONE, NULL, 0,
736 "The name of a NOTIFY condition.", HFILL }
738 { &hf_text,
739 { "Text", "pgsql.text", FT_STRINGZ, BASE_NONE, NULL, 0,
740 "Text from the backend.", HFILL }
742 { &hf_tableoid,
743 { "Table OID", "pgsql.oid.table", FT_UINT32, BASE_DEC, NULL, 0,
744 "The object identifier of a table.", HFILL }
746 { &hf_typeoid,
747 { "Type OID", "pgsql.oid.type", FT_UINT32, BASE_DEC, NULL, 0,
748 "The object identifier of a type.", HFILL }
750 { &hf_oid,
751 { "OID", "pgsql.oid", FT_UINT32, BASE_DEC, NULL, 0,
752 "An object identifier.", HFILL }
754 { &hf_format,
755 { "Format", "pgsql.format", FT_UINT16, BASE_DEC, VALS(format_vals),
756 0, "A format specifier.", HFILL }
758 { &hf_field_count,
759 { "Field count", "pgsql.field.count", FT_UINT16, BASE_DEC, NULL, 0,
760 "The number of fields within a row.", HFILL }
762 { &hf_val_name,
763 { "Column name", "pgsql.col.name", FT_STRINGZ, BASE_NONE, NULL, 0,
764 "The name of a column.", HFILL }
766 { &hf_val_idx,
767 { "Column index", "pgsql.col.index", FT_UINT32, BASE_DEC, NULL, 0,
768 "The position of a column within a row.", HFILL }
770 { &hf_val_length,
771 { "Column length", "pgsql.val.length", FT_INT32, BASE_DEC, NULL, 0,
772 "The length of a parameter value, in bytes. -1 means NULL.",
773 HFILL }
775 { &hf_val_data,
776 { "Data", "pgsql.val.data", FT_BYTES, BASE_NONE, NULL, 0,
777 "Parameter data.", HFILL }
779 { &hf_val_mod,
780 { "Type modifier", "pgsql.col.typemod", FT_INT32, BASE_DEC, NULL, 0,
781 "The type modifier for a column.", HFILL }
783 { &hf_severity,
784 { "Severity", "pgsql.severity", FT_STRINGZ, BASE_NONE, NULL, 0,
785 "Message severity.", HFILL }
787 { &hf_code,
788 { "Code", "pgsql.code", FT_STRINGZ, BASE_NONE, NULL, 0,
789 "SQLState code.", HFILL }
791 { &hf_message,
792 { "Message", "pgsql.message", FT_STRINGZ, BASE_NONE, NULL, 0,
793 "Error message.", HFILL }
795 { &hf_detail,
796 { "Detail", "pgsql.detail", FT_STRINGZ, BASE_NONE, NULL, 0,
797 "Detailed error message.", HFILL }
799 { &hf_hint,
800 { "Hint", "pgsql.hint", FT_STRINGZ, BASE_NONE, NULL, 0,
801 "A suggestion to resolve an error.", HFILL }
803 { &hf_position,
804 { "Position", "pgsql.position", FT_STRINGZ, BASE_NONE, NULL, 0,
805 "The index of the error within the query string.", HFILL }
807 { &hf_where,
808 { "Context", "pgsql.where", FT_STRINGZ, BASE_NONE, NULL, 0,
809 "The context in which an error occurred.", HFILL }
811 { &hf_file,
812 { "File", "pgsql.file", FT_STRINGZ, BASE_NONE, NULL, 0,
813 "The source-code file where an error was reported.", HFILL }
815 { &hf_line,
816 { "Line", "pgsql.line", FT_STRINGZ, BASE_NONE, NULL, 0,
817 "The line number on which an error was reported.", HFILL }
819 { &hf_routine,
820 { "Routine", "pgsql.routine", FT_STRINGZ, BASE_NONE, NULL, 0,
821 "The routine that reported an error.", HFILL }
825 static gint *ett[] = {
826 &ett_pgsql,
827 &ett_values
830 module_t *mod_pgsql;
832 proto_pgsql = proto_register_protocol("PostgreSQL", "PGSQL", "pgsql");
833 proto_register_field_array(proto_pgsql, hf, array_length(hf));
834 proto_register_subtree_array(ett, array_length(ett));
836 mod_pgsql = prefs_register_protocol(proto_pgsql, proto_reg_handoff_pgsql);
837 prefs_register_uint_preference(
838 mod_pgsql, "tcp.port", "PGSQL TCP port", "Set the port for PGSQL "
839 "messages (if different from the default of 5432)", 10, &pgsql_port
843 void
844 proto_reg_handoff_pgsql(void)
846 static gboolean initialized = FALSE;
847 static dissector_handle_t pgsql_handle;
848 static guint saved_pgsql_port;
850 if (!initialized) {
851 pgsql_handle = new_create_dissector_handle(dissect_pgsql, proto_pgsql);
852 initialized = TRUE;
853 } else {
854 dissector_delete_uint("tcp.port", saved_pgsql_port, pgsql_handle);
857 dissector_add_uint("tcp.port", pgsql_port, pgsql_handle);
858 saved_pgsql_port = pgsql_port;