Browse code

sca: clang format code

Victor Seva authored on 16/06/2020 07:31:55
Showing 1 changed files
... ...
@@ -38,102 +38,103 @@ const str SCA_DB_NOTIFY_CSEQ_COL_NAME = STR_STATIC_INIT("notify_cseq");
38 38
 const str SCA_DB_SUBSCRIBE_CSEQ_COL_NAME = STR_STATIC_INIT("subscribe_cseq");
39 39
 const str SCA_DB_SERVER_ID_COL_NAME = STR_STATIC_INIT("server_id");
40 40
 
41
-void sca_db_subscriptions_get_value_for_column(int column, db_val_t *row_values,
42
-		void *column_value)
41
+void sca_db_subscriptions_get_value_for_column(
42
+		int column, db_val_t *row_values, void *column_value)
43 43
 {
44 44
 	assert(column_value != NULL);
45 45
 	assert(row_values != NULL);
46 46
 	assert(column >= 0 && column < SCA_DB_SUBS_BOUNDARY);
47 47
 
48
-	switch (column) {
49
-	case SCA_DB_SUBS_SUBSCRIBER_COL:
50
-	case SCA_DB_SUBS_AOR_COL:
51
-	case SCA_DB_SUBS_CALL_ID_COL:
52
-	case SCA_DB_SUBS_FROM_TAG_COL:
53
-	case SCA_DB_SUBS_TO_TAG_COL:
54
-	case SCA_DB_SUBS_RECORD_ROUTE_COL:
55
-		((str *) column_value)->s = (char *) row_values[column].val.string_val;
56
-		((str *) column_value)->len = strlen(((str *) column_value)->s);
57
-		break;
58
-
59
-	case SCA_DB_SUBS_EXPIRES_COL:
60
-		*((time_t *) column_value) = row_values[column].val.time_val;
61
-		break;
62
-
63
-	case SCA_DB_SUBS_EVENT_COL:
64
-	case SCA_DB_SUBS_STATE_COL:
65
-	case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
66
-	case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
67
-	case SCA_DB_SUBS_SERVER_ID_COL:
68
-		*((int *) column_value) = row_values[column].val.int_val;
69
-		break;
70
-
71
-	default:
72
-		column_value = NULL;
48
+	switch(column) {
49
+		case SCA_DB_SUBS_SUBSCRIBER_COL:
50
+		case SCA_DB_SUBS_AOR_COL:
51
+		case SCA_DB_SUBS_CALL_ID_COL:
52
+		case SCA_DB_SUBS_FROM_TAG_COL:
53
+		case SCA_DB_SUBS_TO_TAG_COL:
54
+		case SCA_DB_SUBS_RECORD_ROUTE_COL:
55
+			((str *)column_value)->s =
56
+					(char *)row_values[column].val.string_val;
57
+			((str *)column_value)->len = strlen(((str *)column_value)->s);
58
+			break;
59
+
60
+		case SCA_DB_SUBS_EXPIRES_COL:
61
+			*((time_t *)column_value) = row_values[column].val.time_val;
62
+			break;
63
+
64
+		case SCA_DB_SUBS_EVENT_COL:
65
+		case SCA_DB_SUBS_STATE_COL:
66
+		case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
67
+		case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
68
+		case SCA_DB_SUBS_SERVER_ID_COL:
69
+			*((int *)column_value) = row_values[column].val.int_val;
70
+			break;
71
+
72
+		default:
73
+			column_value = NULL;
73 74
 	}
74 75
 }
75 76
 
76
-void sca_db_subscriptions_set_value_for_column(int column, db_val_t *row_values,
77
-		void *column_value)
77
+void sca_db_subscriptions_set_value_for_column(
78
+		int column, db_val_t *row_values, void *column_value)
78 79
 {
79 80
 	assert(column >= 0 && column < SCA_DB_SUBS_BOUNDARY);
80 81
 	assert(column_value != NULL);
81 82
 	assert(row_values != NULL);
82 83
 
83
-	switch (column) {
84
-	case SCA_DB_SUBS_SUBSCRIBER_COL:
85
-	case SCA_DB_SUBS_AOR_COL:
86
-	case SCA_DB_SUBS_CALL_ID_COL:
87
-	case SCA_DB_SUBS_FROM_TAG_COL:
88
-	case SCA_DB_SUBS_TO_TAG_COL:
89
-	case SCA_DB_SUBS_RECORD_ROUTE_COL:
90
-		row_values[column].val.str_val = *((str *) column_value);
91
-		row_values[column].type = DB1_STR;
92
-		row_values[column].nul = 0;
93
-		break;
94
-
95
-	case SCA_DB_SUBS_EXPIRES_COL:
96
-		row_values[column].val.int_val = (int) (*((time_t *) column_value));
97
-		row_values[column].type = DB1_INT;
98
-		row_values[column].nul = 0;
99
-		break;
100
-
101
-	case SCA_DB_SUBS_APP_IDX_COL:
102
-		// for now, don't save appearance index associated with subscriber
103
-		row_values[column].val.int_val = 0;
104
-		row_values[column].type = DB1_INT;
105
-		row_values[column].nul = 0;
106
-		break;
107
-
108
-	default:
109
-		LM_WARN("sca_db_subscriptions_set_value_for_column: unrecognized "
110
-				"column index %d, treating as INT\n", column);
111
-		// fall through
112
-
113
-	case SCA_DB_SUBS_EVENT_COL:
114
-	case SCA_DB_SUBS_STATE_COL:
115
-	case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
116
-	case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
117
-	case SCA_DB_SUBS_SERVER_ID_COL:
118
-		row_values[column].val.int_val = *((int *) column_value);
119
-		row_values[column].type = DB1_INT;
120
-		row_values[column].nul = 0;
121
-		break;
84
+	switch(column) {
85
+		case SCA_DB_SUBS_SUBSCRIBER_COL:
86
+		case SCA_DB_SUBS_AOR_COL:
87
+		case SCA_DB_SUBS_CALL_ID_COL:
88
+		case SCA_DB_SUBS_FROM_TAG_COL:
89
+		case SCA_DB_SUBS_TO_TAG_COL:
90
+		case SCA_DB_SUBS_RECORD_ROUTE_COL:
91
+			row_values[column].val.str_val = *((str *)column_value);
92
+			row_values[column].type = DB1_STR;
93
+			row_values[column].nul = 0;
94
+			break;
95
+
96
+		case SCA_DB_SUBS_EXPIRES_COL:
97
+			row_values[column].val.int_val = (int)(*((time_t *)column_value));
98
+			row_values[column].type = DB1_INT;
99
+			row_values[column].nul = 0;
100
+			break;
101
+
102
+		case SCA_DB_SUBS_APP_IDX_COL:
103
+			// for now, don't save appearance index associated with subscriber
104
+			row_values[column].val.int_val = 0;
105
+			row_values[column].type = DB1_INT;
106
+			row_values[column].nul = 0;
107
+			break;
108
+
109
+		default:
110
+			LM_WARN("sca_db_subscriptions_set_value_for_column: unrecognized "
111
+					"column index %d, treating as INT\n",
112
+					column);
113
+			// fall through
114
+
115
+		case SCA_DB_SUBS_EVENT_COL:
116
+		case SCA_DB_SUBS_STATE_COL:
117
+		case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
118
+		case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
119
+		case SCA_DB_SUBS_SERVER_ID_COL:
120
+			row_values[column].val.int_val = *((int *)column_value);
121
+			row_values[column].type = DB1_INT;
122
+			row_values[column].nul = 0;
123
+			break;
122 124
 	}
123 125
 }
124 126
 
125 127
 str **sca_db_subscriptions_columns(void)
126 128
 {
127
-	static str *subs_columns[] = {(str *) &SCA_DB_SUBSCRIBER_COL_NAME,
128
-			(str *) &SCA_DB_AOR_COL_NAME, (str *) &SCA_DB_EVENT_COL_NAME,
129
-			(str *) &SCA_DB_EXPIRES_COL_NAME, (str *) &SCA_DB_STATE_COL_NAME,
130
-			(str *) &SCA_DB_APP_IDX_COL_NAME, (str *) &SCA_DB_CALL_ID_COL_NAME,
131
-			(str *) &SCA_DB_FROM_TAG_COL_NAME, (str *) &SCA_DB_TO_TAG_COL_NAME,
132
-			(str *) &SCA_DB_RECORD_ROUTE_COL_NAME,
133
-			(str *) &SCA_DB_NOTIFY_CSEQ_COL_NAME,
134
-			(str *) &SCA_DB_SUBSCRIBE_CSEQ_COL_NAME,
135
-			(str *) &SCA_DB_SERVER_ID_COL_NAME,
136
-			NULL};
129
+	static str *subs_columns[] = {(str *)&SCA_DB_SUBSCRIBER_COL_NAME,
130
+			(str *)&SCA_DB_AOR_COL_NAME, (str *)&SCA_DB_EVENT_COL_NAME,
131
+			(str *)&SCA_DB_EXPIRES_COL_NAME, (str *)&SCA_DB_STATE_COL_NAME,
132
+			(str *)&SCA_DB_APP_IDX_COL_NAME, (str *)&SCA_DB_CALL_ID_COL_NAME,
133
+			(str *)&SCA_DB_FROM_TAG_COL_NAME, (str *)&SCA_DB_TO_TAG_COL_NAME,
134
+			(str *)&SCA_DB_RECORD_ROUTE_COL_NAME,
135
+			(str *)&SCA_DB_NOTIFY_CSEQ_COL_NAME,
136
+			(str *)&SCA_DB_SUBSCRIBE_CSEQ_COL_NAME,
137
+			(str *)&SCA_DB_SERVER_ID_COL_NAME, NULL};
137 138
 
138 139
 	return (subs_columns);
139 140
 }
... ...
@@ -143,7 +144,7 @@ db1_con_t *sca_db_get_connection(void)
143 144
 	assert(sca && sca->cfg->db_url);
144 145
 	assert(sca->db_api && sca->db_api->init);
145 146
 
146
-	if (sca_db_con == NULL) {
147
+	if(sca_db_con == NULL) {
147 148
 		sca_db_con = sca->db_api->init(sca->cfg->db_url);
148 149
 		// catch connection error in caller
149 150
 	}
... ...
@@ -151,8 +152,9 @@ db1_con_t *sca_db_get_connection(void)
151 152
 	return (sca_db_con);
152 153
 }
153 154
 
154
-void sca_db_disconnect(void) {
155
-	if (sca_db_con != NULL) {
155
+void sca_db_disconnect(void)
156
+{
157
+	if(sca_db_con != NULL) {
156 158
 		sca->db_api->close(sca_db_con);
157 159
 		sca_db_con = NULL;
158 160
 	}
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,159 @@
1
+/*
2
+ * Copyright (C) 2012 Andrew Mortensen
3
+ *
4
+ * This file is part of the sca module for Kamailio, a free SIP server.
5
+ *
6
+ * The sca module is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * The sca module is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA. 02110-1301 USA
19
+ */
20
+#include "sca_common.h"
21
+
22
+#include "sca_db.h"
23
+#include "sca_subscribe.h"
24
+
25
+db1_con_t *sca_db_con = NULL;
26
+
27
+const str SCA_DB_SUBSCRIBER_COL_NAME = STR_STATIC_INIT("subscriber");
28
+const str SCA_DB_AOR_COL_NAME = STR_STATIC_INIT("aor");
29
+const str SCA_DB_EVENT_COL_NAME = STR_STATIC_INIT("event");
30
+const str SCA_DB_EXPIRES_COL_NAME = STR_STATIC_INIT("expires");
31
+const str SCA_DB_STATE_COL_NAME = STR_STATIC_INIT("state");
32
+const str SCA_DB_APP_IDX_COL_NAME = STR_STATIC_INIT("app_idx");
33
+const str SCA_DB_CALL_ID_COL_NAME = STR_STATIC_INIT("call_id");
34
+const str SCA_DB_FROM_TAG_COL_NAME = STR_STATIC_INIT("from_tag");
35
+const str SCA_DB_TO_TAG_COL_NAME = STR_STATIC_INIT("to_tag");
36
+const str SCA_DB_RECORD_ROUTE_COL_NAME = STR_STATIC_INIT("record_route");
37
+const str SCA_DB_NOTIFY_CSEQ_COL_NAME = STR_STATIC_INIT("notify_cseq");
38
+const str SCA_DB_SUBSCRIBE_CSEQ_COL_NAME = STR_STATIC_INIT("subscribe_cseq");
39
+const str SCA_DB_SERVER_ID_COL_NAME = STR_STATIC_INIT("server_id");
40
+
41
+void sca_db_subscriptions_get_value_for_column(int column, db_val_t *row_values,
42
+		void *column_value)
43
+{
44
+	assert(column_value != NULL);
45
+	assert(row_values != NULL);
46
+	assert(column >= 0 && column < SCA_DB_SUBS_BOUNDARY);
47
+
48
+	switch (column) {
49
+	case SCA_DB_SUBS_SUBSCRIBER_COL:
50
+	case SCA_DB_SUBS_AOR_COL:
51
+	case SCA_DB_SUBS_CALL_ID_COL:
52
+	case SCA_DB_SUBS_FROM_TAG_COL:
53
+	case SCA_DB_SUBS_TO_TAG_COL:
54
+	case SCA_DB_SUBS_RECORD_ROUTE_COL:
55
+		((str *) column_value)->s = (char *) row_values[column].val.string_val;
56
+		((str *) column_value)->len = strlen(((str *) column_value)->s);
57
+		break;
58
+
59
+	case SCA_DB_SUBS_EXPIRES_COL:
60
+		*((time_t *) column_value) = row_values[column].val.time_val;
61
+		break;
62
+
63
+	case SCA_DB_SUBS_EVENT_COL:
64
+	case SCA_DB_SUBS_STATE_COL:
65
+	case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
66
+	case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
67
+	case SCA_DB_SUBS_SERVER_ID_COL:
68
+		*((int *) column_value) = row_values[column].val.int_val;
69
+		break;
70
+
71
+	default:
72
+		column_value = NULL;
73
+	}
74
+}
75
+
76
+void sca_db_subscriptions_set_value_for_column(int column, db_val_t *row_values,
77
+		void *column_value)
78
+{
79
+	assert(column >= 0 && column < SCA_DB_SUBS_BOUNDARY);
80
+	assert(column_value != NULL);
81
+	assert(row_values != NULL);
82
+
83
+	switch (column) {
84
+	case SCA_DB_SUBS_SUBSCRIBER_COL:
85
+	case SCA_DB_SUBS_AOR_COL:
86
+	case SCA_DB_SUBS_CALL_ID_COL:
87
+	case SCA_DB_SUBS_FROM_TAG_COL:
88
+	case SCA_DB_SUBS_TO_TAG_COL:
89
+	case SCA_DB_SUBS_RECORD_ROUTE_COL:
90
+		row_values[column].val.str_val = *((str *) column_value);
91
+		row_values[column].type = DB1_STR;
92
+		row_values[column].nul = 0;
93
+		break;
94
+
95
+	case SCA_DB_SUBS_EXPIRES_COL:
96
+		row_values[column].val.int_val = (int) (*((time_t *) column_value));
97
+		row_values[column].type = DB1_INT;
98
+		row_values[column].nul = 0;
99
+		break;
100
+
101
+	case SCA_DB_SUBS_APP_IDX_COL:
102
+		// for now, don't save appearance index associated with subscriber
103
+		row_values[column].val.int_val = 0;
104
+		row_values[column].type = DB1_INT;
105
+		row_values[column].nul = 0;
106
+		break;
107
+
108
+	default:
109
+		LM_WARN("sca_db_subscriptions_set_value_for_column: unrecognized "
110
+				"column index %d, treating as INT\n", column);
111
+		// fall through
112
+
113
+	case SCA_DB_SUBS_EVENT_COL:
114
+	case SCA_DB_SUBS_STATE_COL:
115
+	case SCA_DB_SUBS_NOTIFY_CSEQ_COL:
116
+	case SCA_DB_SUBS_SUBSCRIBE_CSEQ_COL:
117
+	case SCA_DB_SUBS_SERVER_ID_COL:
118
+		row_values[column].val.int_val = *((int *) column_value);
119
+		row_values[column].type = DB1_INT;
120
+		row_values[column].nul = 0;
121
+		break;
122
+	}
123
+}
124
+
125
+str **sca_db_subscriptions_columns(void)
126
+{
127
+	static str *subs_columns[] = {(str *) &SCA_DB_SUBSCRIBER_COL_NAME,
128
+			(str *) &SCA_DB_AOR_COL_NAME, (str *) &SCA_DB_EVENT_COL_NAME,
129
+			(str *) &SCA_DB_EXPIRES_COL_NAME, (str *) &SCA_DB_STATE_COL_NAME,
130
+			(str *) &SCA_DB_APP_IDX_COL_NAME, (str *) &SCA_DB_CALL_ID_COL_NAME,
131
+			(str *) &SCA_DB_FROM_TAG_COL_NAME, (str *) &SCA_DB_TO_TAG_COL_NAME,
132
+			(str *) &SCA_DB_RECORD_ROUTE_COL_NAME,
133
+			(str *) &SCA_DB_NOTIFY_CSEQ_COL_NAME,
134
+			(str *) &SCA_DB_SUBSCRIBE_CSEQ_COL_NAME,
135
+			(str *) &SCA_DB_SERVER_ID_COL_NAME,
136
+			NULL};
137
+
138
+	return (subs_columns);
139
+}
140
+
141
+db1_con_t *sca_db_get_connection(void)
142
+{
143
+	assert(sca && sca->cfg->db_url);
144
+	assert(sca->db_api && sca->db_api->init);
145
+
146
+	if (sca_db_con == NULL) {
147
+		sca_db_con = sca->db_api->init(sca->cfg->db_url);
148
+		// catch connection error in caller
149
+	}
150
+
151
+	return (sca_db_con);
152
+}
153
+
154
+void sca_db_disconnect(void) {
155
+	if (sca_db_con != NULL) {
156
+		sca->db_api->close(sca_db_con);
157
+		sca_db_con = NULL;
158
+	}
159
+}