annotate extensions/rt_ignore_dh/rt_ignore_dh.c @ 1041:a740267f1be6

Add extension that removes Destination-Host from Requests and restores it for Answers.
author Thomas Klausner <tk@giga.or.at>
date Thu, 18 Apr 2013 15:49:45 +0200
parents
children 3fa4dc91adee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1041
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
1 #include <freeDiameter/extension.h>
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
2
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
3 /*
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
4 * Remove Destination-Hosts, putting it into Proxy-Info, and restore it to
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
5 * Origin-Host for answers.
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
6 */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
7
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
8 struct dict_object * dh_avp_do; /* cache the Destination-Host dictionary object */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
9 struct dict_object * oh_avp_do; /* cache the Origin-Host dictionary object */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
10 struct dict_object * ph_avp_do; /* cache the Proxy-Host dictionary object */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
11 struct dict_object * pi_avp_do; /* cache the Proxy-Info dictionary object */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
12 struct dict_object * ps_avp_do; /* cache the Proxy-State dictionary object */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
13
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
14 static void *memdup(void *data, size_t len)
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
15 {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
16 void *mem;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
17 if ((mem=malloc(len)) == NULL)
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
18 return NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
19 memcpy(mem, data, len);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
20 return mem;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
21 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
22
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
23 static int restore_origin_host(struct msg **msg) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
24 struct avp *avp, *child;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
25 struct avp *oh_avp = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
26 struct avp *pi_avp = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
27 int match;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
28 void *ps, *new_oh;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
29 size_t ps_len, new_oh_len = 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
30 union avp_value val;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
31
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
32 ps = new_oh = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
33
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
34 CHECK_FCT(fd_msg_browse(*msg, MSG_BRW_FIRST_CHILD, &avp, NULL));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
35 /* look for Origin-Host and Proxy-Info matching this host */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
36 while (avp && (!oh_avp || !pi_avp)) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
37 struct avp_hdr * ahdr;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
38
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
39 CHECK_FCT(fd_msg_avp_hdr(avp, &ahdr));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
40 if (!(ahdr->avp_flags & AVP_FLAG_VENDOR)) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
41 switch (ahdr->avp_code) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
42 case AC_ORIGIN_HOST:
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
43 oh_avp = avp;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
44 CHECK_FCT(fd_msg_parse_dict(oh_avp, fd_g_config->cnf_dict, NULL));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
45 break;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
46 case AC_PROXY_INFO:
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
47 ps = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
48 match = ps_len = 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
49 CHECK_FCT(fd_msg_parse_dict(avp, fd_g_config->cnf_dict, NULL));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
50 CHECK_FCT(fd_msg_browse(avp, MSG_BRW_FIRST_CHILD, &child, NULL));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
51 int match = 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
52 while (child && (!match || !ps)) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
53 struct avp_hdr *chdr;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
54 CHECK_FCT(fd_msg_avp_hdr(child, &chdr));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
55 if (!(chdr->avp_flags & AVP_FLAG_VENDOR)) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
56 switch (chdr->avp_code) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
57 case AC_PROXY_HOST:
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
58 if (fd_os_cmp(chdr->avp_value->os.data, chdr->avp_value->os.len,
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
59 fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len) == 0) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
60 match = 1;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
61 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
62 break;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
63 case AC_PROXY_STATE:
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
64 ps_len = chdr->avp_value->os.len;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
65 ps = memdup(chdr->avp_value->os.data, ps_len);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
66 if (!ps) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
67 TRACE_ERROR("malloc failure");
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
68 return 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
69 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
70 break;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
71 default:
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
72 break;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
73 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
74 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
75 CHECK_FCT(fd_msg_browse(child, MSG_BRW_NEXT, &child, NULL));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
76 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
77 if (match && ps) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
78 new_oh = ps;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
79 new_oh_len = ps_len;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
80 pi_avp = avp;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
81 } else
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
82 free(ps);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
83 break;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
84 default:
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
85 break;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
86 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
87 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
88 CHECK_FCT(fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
89 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
90 if (!pi_avp)
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
91 return 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
92
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
93 memset(&val, 0, sizeof(val));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
94 val.os.data = new_oh;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
95 val.os.len = new_oh_len;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
96 if (!oh_avp) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
97 TRACE_ERROR("Message contained no Origin-Host");
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
98 } else {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
99 CHECK_FCT(fd_msg_avp_setvalue(oh_avp, &val));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
100 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
101 fd_msg_free((msg_or_avp*)pi_avp);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
102
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
103 fd_log_debug("Restored Origin-Host '%.*s' from Proxy-Info", (int)new_oh_len, (char *)new_oh);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
104 return 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
105 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
106
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
107 static int stow_destination_host(struct msg **msg) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
108 struct avp * avp = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
109 struct avp * ph_avp = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
110 struct avp * pi_avp = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
111 struct avp * ps_avp = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
112
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
113 /* Look for the Destination-Host AVP in the message */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
114 CHECK_FCT(fd_msg_search_avp(*msg, dh_avp_do, &avp));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
115 if (avp != NULL) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
116 struct avp_hdr * ahdr = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
117 union avp_value val;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
118
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
119 CHECK_FCT(fd_msg_avp_hdr(avp, &ahdr));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
120 if (ahdr->avp_value != NULL) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
121 /* add Proxy-Info->{Proxy-Host, Proxy-State} using Destination-Host information */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
122 CHECK_FCT(fd_msg_avp_new(ph_avp_do, 0, &ph_avp));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
123 memset(&val, 0, sizeof(val));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
124 val.os.data = memdup(fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
125 val.os.len = fd_g_config->cnf_diamid_len;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
126 CHECK_FCT(fd_msg_avp_setvalue(ph_avp, &val));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
127
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
128 CHECK_FCT(fd_msg_avp_new(ps_avp_do, 0, &ps_avp));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
129 memset(&val, 0, sizeof(val));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
130 val.os.data = memdup(ahdr->avp_value->os.data, ahdr->avp_value->os.len);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
131 val.os.len = ahdr->avp_value->os.len;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
132 CHECK_FCT(fd_msg_avp_setvalue(ps_avp, &val));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
133
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
134 CHECK_FCT(fd_msg_avp_new(pi_avp_do, 0, &pi_avp));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
135 CHECK_FCT(fd_msg_avp_add(pi_avp, MSG_BRW_LAST_CHILD, ph_avp));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
136 CHECK_FCT(fd_msg_avp_add(pi_avp, MSG_BRW_LAST_CHILD, ps_avp));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
137
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
138 /* remove Destination-Host from message */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
139 fd_msg_free((msg_or_avp*)avp);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
140 /* add Proxy-Info */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
141 CHECK_FCT(fd_msg_avp_add(*msg, MSG_BRW_LAST_CHILD, pi_avp));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
142 fd_log_debug("Stowed Destination-Host '%.*s' into Proxy-Info", (int)val.os.len, (const char *)val.os.data);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
143 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
144 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
145
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
146 return 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
147 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
148
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
149 /* The callback for putting Destination-Host into Proxy-Info and restoring it on the way back */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
150 static int rt_ignore_destination_host(void * cbdata, struct msg **msg) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
151 struct msg_hdr * hdr;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
152 int ret;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
153
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
154 TRACE_ENTRY("%p %p", cbdata, msg);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
155
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
156 CHECK_PARAMS(msg && *msg);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
157
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
158 /* Read the message header */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
159 CHECK_FCT(fd_msg_hdr(*msg, &hdr));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
160 if (hdr->msg_flags & CMD_FLAG_REQUEST) {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
161 ret = stow_destination_host(msg);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
162 } else {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
163 ret = restore_origin_host(msg);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
164 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
165
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
166 return ret;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
167 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
168
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
169 /* handler */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
170 static struct fd_rt_fwd_hdl * rt_ignore_destination_host_hdl = NULL;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
171
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
172 /* entry point */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
173 static int rt_ignore_destination_host_entry(char * conffile)
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
174 {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
175 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Destination-Host", &dh_avp_do, ENOENT),
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
176 { TRACE_ERROR("Unable to find 'Destination-Host' AVP in the loaded dictionaries."); });
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
177 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Origin-Host", &oh_avp_do, ENOENT),
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
178 { TRACE_ERROR("Unable to find 'Origin-Host' AVP in the loaded dictionaries."); });
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
179 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Proxy-Host", &ph_avp_do, ENOENT),
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
180 { TRACE_ERROR("Unable to find 'Proxy-Host' AVP in the loaded dictionaries."); });
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
181 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Proxy-Info", &pi_avp_do, ENOENT),
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
182 { TRACE_ERROR("Unable to find 'Proxy-Info' AVP in the loaded dictionaries."); });
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
183 CHECK_FCT_DO(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Proxy-State", &ps_avp_do, ENOENT),
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
184 { TRACE_ERROR("Unable to find 'Proxy-State' AVP in the loaded dictionaries."); });
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
185
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
186 /* Register the callback */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
187 CHECK_FCT(fd_rt_fwd_register(rt_ignore_destination_host, NULL, RT_FWD_ALL, &rt_ignore_destination_host_hdl));
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
188
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
189 TRACE_DEBUG(INFO, "Extension 'Ignore Destination Host' initialized");
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
190 return 0;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
191 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
192
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
193 /* Unload */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
194 void fd_ext_fini(void)
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
195 {
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
196 /* Unregister the callbacks */
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
197 CHECK_FCT_DO(fd_rt_fwd_unregister(rt_ignore_destination_host_hdl, NULL), /* continue */);
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
198 return ;
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
199 }
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
200
a740267f1be6 Add extension that removes Destination-Host from Requests and restores it for Answers.
Thomas Klausner <tk@giga.or.at>
parents:
diff changeset
201 EXTENSION_ENTRY("rt_ignore_destination_host", rt_ignore_destination_host_entry);
"Welcome to our mercurial repository"