Browse code

- uid/did manipulation

Jan Janak authored on 19/11/2005 17:05:03
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,130 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2005 iptelorg GmbH
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License 
24
+ * along with this program; if not, write to the Free Software 
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ */
27
+
28
+#include "id.h"
29
+
30
+
31
+/*
32
+ * Set From UID
33
+ */
34
+void set_from_uid(str* uid)
35
+{
36
+	struct search_state s;
37
+	int_str name, val;
38
+	avp_t* a;
39
+
40
+	a = search_first_avp(AVP_USER | AVP_NAME_STR, name, 0, &s);
41
+	while(a) {
42
+		destroy_avp(a);
43
+		a = search_next_avp(&s, 0);
44
+	}
45
+
46
+	val.s = uid;
47
+	add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
48
+}
49
+
50
+
51
+
52
+/*
53
+ * Set From UID
54
+ */
55
+int get_from_uid(str* uid)
56
+{
57
+	static str name_s = STR_STATIC_INIT(AVP_UID);
58
+	int_str name, val;
59
+
60
+	name.s = &name_s;
61
+	if (search_first_avp(AVP_USER | AVP_NAME_STR, name, &val, 0)) {
62
+		*uid = *val.s;
63
+		return 1;
64
+	} else {
65
+		uid->s = 0;
66
+		uid->len = 0;
67
+		return 0;
68
+	}
69
+}
70
+
71
+
72
+/*
73
+ * Set To UID
74
+ */
75
+void set_to_uid(str* uid)
76
+{
77
+	struct search_state s;
78
+	int_str name, val;
79
+	avp_t* a;
80
+
81
+	a = search_first_avp(AVP_USER | AVP_NAME_STR, name, 0, &s);
82
+	while(a) {
83
+		destroy_avp(a);
84
+		a = search_next_avp(&s, 0);
85
+	}
86
+
87
+	val.s = uid;
88
+	add_avp(AVP_USER | AVP_NAME_STR | AVP_VAL_STR, name, val);
89
+}
90
+
91
+
92
+
93
+/*
94
+ * Set To UID
95
+ */
96
+int get_to_uid(str* uid)
97
+{
98
+	static str name_s = STR_STATIC_INIT(AVP_UID);
99
+	int_str name, val;
100
+
101
+	name.s = &name_s;
102
+	if (search_first_avp(AVP_USER | AVP_NAME_STR, name, &val, 0)) {
103
+		*uid = *val.s;
104
+		return 1;
105
+	} else {
106
+		uid->s = 0;
107
+		uid->len = 0;
108
+		return 0;
109
+	}
110
+}
111
+
112
+
113
+/*
114
+ * Return the current domain id
115
+ */
116
+int get_did(str* did)
117
+{
118
+	static str name_s = STR_STATIC_INIT(AVP_DID);
119
+	int_str name, val;
120
+	
121
+	name.s = &name_s;
122
+	if (search_first_avp(AVP_DOMAIN | AVP_NAME_STR, name, &val, 0)) {
123
+		*did = *val.s;
124
+		return 1;
125
+	} else {
126
+		did->s = 0;
127
+		did->len = 0;
128
+		return 0;
129
+	}	
130
+}
0 131
new file mode 100644
... ...
@@ -0,0 +1,65 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2005 iptelorg GmbH
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * For a license to use the ser software under conditions
14
+ * other than those described here, or to purchase support for this
15
+ * software, please contact iptel.org by e-mail at the following addresses:
16
+ *    info@iptel.org
17
+ *
18
+ * ser is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License 
24
+ * along with this program; if not, write to the Free Software 
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ *
27
+ */
28
+
29
+#ifndef _ID_H
30
+#define _ID_H
31
+
32
+#include "str.h"
33
+#include "usr_avp.h"
34
+
35
+
36
+/*
37
+ * Set From UID
38
+ */
39
+void set_from_uid(str* uid);
40
+
41
+
42
+/*
43
+ * Set From UID
44
+ */
45
+int get_from_uid(str* uid);
46
+
47
+/*
48
+ * Set To UID
49
+ */
50
+void set_to_uid(str* uid);
51
+
52
+
53
+/*
54
+ * Set To UID
55
+ */
56
+int set_to_uid(str* uid);
57
+
58
+
59
+/*
60
+ * Return the current domain id
61
+ */
62
+int get_did(str* did);
63
+
64
+
65
+#endif /* _ID_H */