summaryrefslogtreecommitdiff
path: root/test/navigation/patches/bustle_filter.patch
blob: 9208abef54ed882f593c78481287303bb1923293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
diff -cr bustle-0.4.0/c-sources/pcap-monitor.c bustle-0.4.0.work/c-sources/pcap-monitor.c
*** bustle-0.4.0/c-sources/pcap-monitor.c	Wed Jan 18 11:32:49 2012
--- bustle-0.4.0.work/c-sources/pcap-monitor.c	Thu Apr 19 13:59:23 2012
***************
*** 20,27 ****
--- 20,31 ----
  #include "pcap-monitor.h"
  
  #include <string.h>
+ #include <stdlib.h>
  #include <pcap/pcap.h>
  
+ const char *filter_str;
+ GHashTable *filter_hash;
+ 
  typedef struct {
      struct timeval ts;
      GByteArray *blob;
***************
*** 230,235 ****
--- 234,240 ----
  
        /* The cast is necessary because libpcap is weird. */
        pcap_dump ((u_char *) td->dumper, &hdr, message->blob->data);
+       pcap_dump_flush(td->dumper);
        g_byte_array_unref (message->blob);
        g_slice_free (Message, message);
      }
***************
*** 260,266 ****
  }
  
  GDBusMessage *
! filter (
      GDBusConnection *connection,
      GDBusMessage *message,
      gboolean is_incoming,
--- 265,271 ----
  }
  
  GDBusMessage *
! filter_ok (
      GDBusConnection *connection,
      GDBusMessage *message,
      gboolean is_incoming,
***************
*** 318,323 ****
--- 323,399 ----
      }
  }
  
+ gboolean
+ filter_match(GDBusMessage *message)
+ {
+ 	const char *method=g_strdup_printf("%s.%s",g_dbus_message_get_interface(message),g_dbus_message_get_member(message));
+ 	const char *filter=filter_str;
+ 	gboolean match=FALSE;
+ 	while (*filter) {
+ 		int flen;
+ 		gboolean part_match=TRUE;
+ 		if (*filter=='-') {
+ 			filter++;
+ 			part_match=FALSE;
+ 		}
+ 		flen=strcspn(filter,",");
+ 		if (!strncmp(method, filter, flen))
+ 			match=part_match;
+ 		filter+=flen;
+ 		if (*filter==',')
+ 			filter++;
+ 	}
+ 	g_free((gpointer)method);
+ 	return match;
+ }
+ 
+ GDBusMessage *
+ filter(
+     GDBusConnection *connection,
+     GDBusMessage *message,
+     gboolean is_incoming,
+     gpointer user_data)
+ {
+ 	char *id, *reply_id, *found;
+   	const gchar *dest;
+ 	if (!filter_str)
+ 		return filter_ok(connection, message, is_incoming, user_data);
+   	dest = g_dbus_message_get_destination (message);
+ 	if (!is_incoming || g_strcmp0 (dest, g_dbus_connection_get_unique_name (connection)) == 0)
+       		return message;
+ 	switch(g_dbus_message_get_message_type(message)) {
+ 	case G_DBUS_MESSAGE_TYPE_METHOD_CALL:
+ 		if (!filter_match(message)) {
+       			g_clear_object (&message);
+ 			return NULL;
+ 		}
+ 		id=g_strdup_printf("%s:%u",g_dbus_message_get_sender(message), g_dbus_message_get_serial(message));
+ 		g_hash_table_insert(filter_hash, id, id);
+ 		return filter_ok(connection, message, is_incoming, user_data);
+ 	case G_DBUS_MESSAGE_TYPE_SIGNAL:
+ 		if (!filter_match(message)) {
+       			g_clear_object (&message);
+ 			return NULL;
+ 		}
+ 	case G_DBUS_MESSAGE_TYPE_INVALID:
+ 		return filter_ok(connection, message, is_incoming, user_data);
+ 	case G_DBUS_MESSAGE_TYPE_METHOD_RETURN:
+ 	case G_DBUS_MESSAGE_TYPE_ERROR:
+ 		reply_id=g_strdup_printf("%s:%u",g_dbus_message_get_destination(message), g_dbus_message_get_reply_serial(message));
+ 		found=g_hash_table_lookup(filter_hash, reply_id);
+ 		g_free(reply_id);
+ 		if (found) {
+ 			g_hash_table_remove(filter_hash, found);
+ 			g_free(found);
+ 			return filter_ok(connection, message, is_incoming, user_data);
+ 		}
+       		g_clear_object (&message);
+ 		return NULL;
+ 	}
+      	g_clear_object (&message);
+ 	return NULL;
+ }
+ 
  static gboolean
  match_everything (
      GDBusProxy *bus,
***************
*** 565,570 ****
--- 641,649 ----
      const gchar *filename,
      GError **error)
  {
+   filter_str=getenv("BUSTLE_FILTER");
+   if (!filter_hash)
+ 	filter_hash=g_hash_table_new(g_str_hash, g_str_equal);
    return g_initable_new (
        BUSTLE_TYPE_PCAP_MONITOR, NULL, error,
        "bus-type", bus_type,
Only in bustle-0.4.0.work: dist