Browse code

dset: exposed branch structure

- added helper functions to allow branch attributes updates via PVs
- related to FS#8

Daniel-Constantin Mierla authored on 21/04/2010 10:53:03
Showing 2 changed files
... ...
@@ -55,27 +55,6 @@
55 55
 #define Q_PARAM ">;q="
56 56
 #define Q_PARAM_LEN (sizeof(Q_PARAM) - 1)
57 57
 
58
-struct branch
59
-{
60
-	char uri[MAX_URI_SIZE];
61
-	unsigned int len;
62
-
63
-	     /* Real destination of the request */
64
-	char dst_uri[MAX_URI_SIZE];
65
-	unsigned int dst_uri_len;
66
-
67
-	/* Path set */
68
-	char path[MAX_PATH_SIZE];
69
-	unsigned int path_len;
70
-
71
-	int q; /* Preference of the contact among
72
-		* contact within the array */
73
-	struct socket_info* force_send_socket;
74
-
75
-	/* Branch flags */
76
-	flag_t flags;
77
-};
78
-
79 58
 
80 59
 /* 
81 60
  * Where we store URIs of additional transaction branches
... ...
@@ -96,6 +75,54 @@ static qvalue_t ruri_q = Q_UNSPECIFIED;
96 96
 static flag_t ruri_bflags;
97 97
 
98 98
 
99
+/*! \brief
100
+ * Return pointer to branch[idx] structure
101
+ * @param idx - branch index
102
+ *
103
+ * @return  pointer to branch or NULL if invalid branch
104
+ */
105
+branch_t *get_sip_branch(int idx)
106
+{
107
+	if(nr_branches==0)
108
+		return NULL;
109
+	if(idx<0)
110
+	{
111
+		if(nr_branches + idx >= 0)
112
+			return &branches[nr_branches+idx];
113
+		return NULL;
114
+	}
115
+	if(idx < nr_branches)
116
+		return &branches[idx];
117
+	return 0;
118
+}
119
+
120
+/*! \brief
121
+ * Drop branch[idx]
122
+ * @param idx - branch index
123
+ *
124
+ * @return  0 on success, -1 on error
125
+ */
126
+int drop_sip_branch(int idx)
127
+{
128
+	if(nr_branches==0 || idx>=nr_branches)
129
+		return 0;
130
+	if(idx<0 && nr_branches+idx<0)
131
+		return 0;
132
+	/* last branch */
133
+	if(idx==nr_branches-1)
134
+	{
135
+		nr_branches--;
136
+		return 0;
137
+	}
138
+	if(idx<0)
139
+		idx = nr_branches+idx;
140
+	/* shift back one position */
141
+	for(; idx<nr_branches-1; idx++)
142
+		memcpy(&branches[idx], &branches[idx+1], sizeof(branch_t));
143
+	nr_branches--;
144
+	return 0;
145
+}
146
+
99 147
 static inline flag_t* get_bflags_ptr(unsigned int branch)
100 148
 {
101 149
 	if (branch == 0) return &ruri_bflags;
... ...
@@ -39,6 +39,42 @@
39 39
 extern unsigned int nr_branches;
40 40
 
41 41
 /*! \brief
42
+ * Structure for storing branch attributes
43
+ */
44
+struct branch
45
+{
46
+    char uri[MAX_URI_SIZE];
47
+    unsigned int len;
48
+
49
+         /* Real destination of the request */
50
+    char dst_uri[MAX_URI_SIZE];
51
+    unsigned int dst_uri_len;
52
+
53
+    /* Path set */
54
+    char path[MAX_PATH_SIZE];
55
+    unsigned int path_len;
56
+
57
+    int q; /* Preference of the contact among
58
+        * contact within the array */
59
+    struct socket_info* force_send_socket;
60
+
61
+    /* Branch flags */
62
+    flag_t flags;
63
+};
64
+
65
+typedef struct branch branch_t;
66
+
67
+/*! \brief
68
+ * Return pointer to branch[idx] structure
69
+ */
70
+branch_t *get_sip_branch(int idx);
71
+
72
+/*! \brief
73
+ * Drop branch[idx]
74
+ */
75
+int drop_sip_branch(int idx);
76
+
77
+/*! \brief
42 78
  * Add a new branch to current transaction 
43 79
  */
44 80
 int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,