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