Browse code

Add support for loading non-string (int only at this time) fields via load_credentials feature. For now, they are converted into the string AVP and as such should be either processed as strings or converted into integers using avpops module functions. Non-ideal solution, but it's better than crashing when trying to access invalid pointer.

Maxim Sobolev authored on 04/05/2007 21:35:52
Showing 1 changed files
... ...
@@ -35,6 +35,8 @@
35 35
  */
36 36
 
37 37
 
38
+#include <stdio.h>
39
+#include <stdlib.h>
38 40
 #include <string.h>
39 41
 #include "../../ut.h"
40 42
 #include "../../str.h"
... ...
@@ -176,14 +178,32 @@ static int generate_avps(db_res_t* result, db_rec_t *row)
176 178
     int i;
177 179
     int_str iname, ivalue;
178 180
     str value;
181
+    char buf[32];
179 182
     
180 183
 	for (i = 2; i < credentials_n + 2; i++) {
181 184
 		value = row->fld[i].v.lstr;
182 185
 
183
-		if (IS_NULL(row->fld[i]) || value.s == NULL) {
186
+		if (IS_NULL(row->fld[i]))
184 187
 			continue;
188
+
189
+		switch (row->fld[i].type) {
190
+		case DB_STR:
191
+		    value = row->fld[i].v.lstr;
192
+		    break;
193
+
194
+		case DB_INT:
195
+		    value.len = sprintf(buf, "%d", row->fld[i].v.int4);
196
+		    value.s = buf;
197
+		    break;
198
+
199
+		default:
200
+		    abort();
201
+		    break;
185 202
 		}
186 203
 
204
+		if (value.s == NULL)
205
+		    continue;
206
+
187 207
 		iname.s = credentials[i - 2];
188 208
 		ivalue.s = value;
189 209