Browse Source

- common fixup functions shared across modules

Jan Janak 20 years ago
parent
commit
bb6575cde0
2 changed files with 105 additions and 1 deletions
  1. 82 0
      sr_module.c
  2. 23 1
      sr_module.h

+ 82 - 0
sr_module.c

@@ -40,6 +40,7 @@
 #include "dprint.h"
 #include "error.h"
 #include "mem/mem.h"
+#include "ut.h"
 
 #include <dlfcn.h>
 #include <strings.h>
@@ -498,3 +499,84 @@ int init_modules(void)
 }
 
 #endif
+
+
+/*
+ * Common fixup functions shared across modules
+ */
+
+int fixup_str_12(void** param, int param_no)
+{
+	str* s;
+	
+	s = (str*)pkg_malloc(sizeof(str));
+	if (!s) {
+		LOG(L_ERR, "fixup_str_12: No memory left\n");
+		return E_UNSPEC;
+	}
+	
+	s->s = (char*)*param;
+	s->len = strlen(s->s);
+	*param = (void*)s;
+	return 0;
+}
+
+
+int fixup_str_1(void** param, int param_no)
+{
+	if (param_no == 1) {
+		return fixup_str_12(param, param_no);
+	}
+
+	return 0;
+}
+
+
+int fixup_str_2(void** param, int param_no)
+{
+	if (param_no == 2) {
+		return fixup_str_12(param, param_no);
+	}
+
+	return 0;
+}
+
+
+int fixup_int_12(void** param, int param_no)
+{
+	unsigned long num;
+	int err;
+
+	num = str2s(*param, strlen(*param), &err);
+	
+	if (err == 0) {
+		pkg_free(*param);
+		*param=(void*)num;
+	} else {
+		LOG(L_ERR, "fixup_int_12: Bad number <%s>\n",
+		    (char*)(*param));
+		return E_UNSPEC;
+	}
+
+	return 0;
+}
+
+
+int fixup_int_1(void** param, int param_no)
+{
+	if (param_no == 1) {
+		return fixup_int_12(param, param_no);
+	}
+
+	return 0;
+}
+
+
+int fixup_int_2(void** param, int param_no)
+{
+	if (param_no == 2) {
+		return fixup_int_12(param, param_no);
+	}
+	
+	return 0;
+}

+ 23 - 1
sr_module.h

@@ -161,4 +161,26 @@ void* find_param_export(char* mod, char* name, modparam_t type);
  */
 
 
-#endif
+/*
+ * Common fixup functions shared across modules
+ */
+
+/* Convert both parameters from char* to str* */
+int fixup_str_12(void** param, int param_no);
+
+/* Convert first parameter from char* to str* */
+int fixup_str_1(void** param, int param_no);
+
+/* Convert second parameter from char* to str* */
+int fixup_str_2(void** param, int param_no);
+
+/* Convert both parameters from char* to long */
+int fixup_int_12(void** param, int param_no);
+
+/* Convert first parameter from char* to long */
+int fixup_int_1(void** param, int param_no);
+
+/* Convert second parameter from char* to long */
+int fixup_int_2(void** param, int param_no);
+
+#endif /* sr_module_h */