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 75
 static flag_t ruri_bflags;
97 76
 
98 77
 
78
+/*! \brief
79
+ * Return pointer to branch[idx] structure
80
+ * @param idx - branch index
81
+ *
82
+ * @return  pointer to branch or NULL if invalid branch
83
+ */
84
+branch_t *get_sip_branch(int idx)
85
+{
86
+	if(nr_branches==0)
87
+		return NULL;
88
+	if(idx<0)
89
+	{
90
+		if(nr_branches + idx >= 0)
91
+			return &branches[nr_branches+idx];
92
+		return NULL;
93
+	}
94
+	if(idx < nr_branches)
95
+		return &branches[idx];
96
+	return 0;
97
+}
98
+
99
+/*! \brief
100
+ * Drop branch[idx]
101
+ * @param idx - branch index
102
+ *
103
+ * @return  0 on success, -1 on error
104
+ */
105
+int drop_sip_branch(int idx)
106
+{
107
+	if(nr_branches==0 || idx>=nr_branches)
108
+		return 0;
109
+	if(idx<0 && nr_branches+idx<0)
110
+		return 0;
111
+	/* last branch */
112
+	if(idx==nr_branches-1)
113
+	{
114
+		nr_branches--;
115
+		return 0;
116
+	}
117
+	if(idx<0)
118
+		idx = nr_branches+idx;
119
+	/* shift back one position */
120
+	for(; idx<nr_branches-1; idx++)
121
+		memcpy(&branches[idx], &branches[idx+1], sizeof(branch_t));
122
+	nr_branches--;
123
+	return 0;
124
+}
125
+
99 126
 static inline flag_t* get_bflags_ptr(unsigned int branch)
100 127
 {
101 128
 	if (branch == 0) return &ruri_bflags;
... ...
@@ -38,6 +38,42 @@
38 38
 
39 39
 extern unsigned int nr_branches;
40 40
 
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
+
41 77
 /*! \brief
42 78
  * Add a new branch to current transaction 
43 79
  */