Browse code

- common fixup functions shared across modules

Jan Janak authored on 11/10/2005 14:54:21
Showing 2 changed files
... ...
@@ -40,6 +40,7 @@
40 40
 #include "dprint.h"
41 41
 #include "error.h"
42 42
 #include "mem/mem.h"
43
+#include "ut.h"
43 44
 
44 45
 #include <dlfcn.h>
45 46
 #include <strings.h>
... ...
@@ -498,3 +499,84 @@ int init_modules(void)
498 498
 }
499 499
 
500 500
 #endif
501
+
502
+
503
+/*
504
+ * Common fixup functions shared across modules
505
+ */
506
+
507
+int fixup_str_12(void** param, int param_no)
508
+{
509
+	str* s;
510
+	
511
+	s = (str*)pkg_malloc(sizeof(str));
512
+	if (!s) {
513
+		LOG(L_ERR, "fixup_str_12: No memory left\n");
514
+		return E_UNSPEC;
515
+	}
516
+	
517
+	s->s = (char*)*param;
518
+	s->len = strlen(s->s);
519
+	*param = (void*)s;
520
+	return 0;
521
+}
522
+
523
+
524
+int fixup_str_1(void** param, int param_no)
525
+{
526
+	if (param_no == 1) {
527
+		return fixup_str_12(param, param_no);
528
+	}
529
+
530
+	return 0;
531
+}
532
+
533
+
534
+int fixup_str_2(void** param, int param_no)
535
+{
536
+	if (param_no == 2) {
537
+		return fixup_str_12(param, param_no);
538
+	}
539
+
540
+	return 0;
541
+}
542
+
543
+
544
+int fixup_int_12(void** param, int param_no)
545
+{
546
+	unsigned long num;
547
+	int err;
548
+
549
+	num = str2s(*param, strlen(*param), &err);
550
+	
551
+	if (err == 0) {
552
+		pkg_free(*param);
553
+		*param=(void*)num;
554
+	} else {
555
+		LOG(L_ERR, "fixup_int_12: Bad number <%s>\n",
556
+		    (char*)(*param));
557
+		return E_UNSPEC;
558
+	}
559
+
560
+	return 0;
561
+}
562
+
563
+
564
+int fixup_int_1(void** param, int param_no)
565
+{
566
+	if (param_no == 1) {
567
+		return fixup_int_12(param, param_no);
568
+	}
569
+
570
+	return 0;
571
+}
572
+
573
+
574
+int fixup_int_2(void** param, int param_no)
575
+{
576
+	if (param_no == 2) {
577
+		return fixup_int_12(param, param_no);
578
+	}
579
+	
580
+	return 0;
581
+}
... ...
@@ -161,4 +161,26 @@ void* find_param_export(char* mod, char* name, modparam_t type);
161 161
  */
162 162
 
163 163
 
164
-#endif
164
+/*
165
+ * Common fixup functions shared across modules
166
+ */
167
+
168
+/* Convert both parameters from char* to str* */
169
+int fixup_str_12(void** param, int param_no);
170
+
171
+/* Convert first parameter from char* to str* */
172
+int fixup_str_1(void** param, int param_no);
173
+
174
+/* Convert second parameter from char* to str* */
175
+int fixup_str_2(void** param, int param_no);
176
+
177
+/* Convert both parameters from char* to long */
178
+int fixup_int_12(void** param, int param_no);
179
+
180
+/* Convert first parameter from char* to long */
181
+int fixup_int_1(void** param, int param_no);
182
+
183
+/* Convert second parameter from char* to long */
184
+int fixup_int_2(void** param, int param_no);
185
+
186
+#endif /* sr_module_h */