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 499
 }
499 500
 
500 501
 #endif
502
+
503
+
504
+/*
505
+ * Common fixup functions shared across modules
506
+ */
507
+
508
+int fixup_str_12(void** param, int param_no)
509
+{
510
+	str* s;
511
+	
512
+	s = (str*)pkg_malloc(sizeof(str));
513
+	if (!s) {
514
+		LOG(L_ERR, "fixup_str_12: No memory left\n");
515
+		return E_UNSPEC;
516
+	}
517
+	
518
+	s->s = (char*)*param;
519
+	s->len = strlen(s->s);
520
+	*param = (void*)s;
521
+	return 0;
522
+}
523
+
524
+
525
+int fixup_str_1(void** param, int param_no)
526
+{
527
+	if (param_no == 1) {
528
+		return fixup_str_12(param, param_no);
529
+	}
530
+
531
+	return 0;
532
+}
533
+
534
+
535
+int fixup_str_2(void** param, int param_no)
536
+{
537
+	if (param_no == 2) {
538
+		return fixup_str_12(param, param_no);
539
+	}
540
+
541
+	return 0;
542
+}
543
+
544
+
545
+int fixup_int_12(void** param, int param_no)
546
+{
547
+	unsigned long num;
548
+	int err;
549
+
550
+	num = str2s(*param, strlen(*param), &err);
551
+	
552
+	if (err == 0) {
553
+		pkg_free(*param);
554
+		*param=(void*)num;
555
+	} else {
556
+		LOG(L_ERR, "fixup_int_12: Bad number <%s>\n",
557
+		    (char*)(*param));
558
+		return E_UNSPEC;
559
+	}
560
+
561
+	return 0;
562
+}
563
+
564
+
565
+int fixup_int_1(void** param, int param_no)
566
+{
567
+	if (param_no == 1) {
568
+		return fixup_int_12(param, param_no);
569
+	}
570
+
571
+	return 0;
572
+}
573
+
574
+
575
+int fixup_int_2(void** param, int param_no)
576
+{
577
+	if (param_no == 2) {
578
+		return fixup_int_12(param, param_no);
579
+	}
580
+	
581
+	return 0;
582
+}
... ...
@@ -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 */