Browse Source

modules_k/domain: did column of domain table is by default NULL

- In order to make migration from 3.2 easier, allow did column of domain
  table to be NULL.  If NULL, value of did is assumed to be same as
  value of domain.
Juha Heinanen 13 years ago
parent
commit
a12f916596

+ 3 - 3
lib/srdb1/schema/domain.xml

@@ -39,9 +39,9 @@
         <name>did</name>
         <type>string</type>
         <size>&domain_len;</size>
-        <description>Domain id</description>
-        <default/>
-        <natural/>
+        <description>Domain id.  Value of did column may be NULL, which
+	means that it has the same value as domain column.</description>
+        <null/>
     </column>
 
     <column>

+ 2 - 1
modules_k/domain/README

@@ -174,7 +174,8 @@ modparam("domain", "domain_attrs_table", "local_domain_attributes")
 3.4. did_col (string)
 
    Name of column containing domain id (did) of domain in domain and
-   domain_attrs tables.
+   domain_attrs tables. In domain table, a did column value may be NULL,
+   which means that it has same value as domain column.
 
    Default value is “did”.
 

+ 3 - 1
modules_k/domain/doc/domain_admin.xml

@@ -102,7 +102,9 @@ modparam("domain", "domain_attrs_table", "local_domain_attributes")
 		<title><varname>did_col</varname> (string)</title>
 		<para>
 		Name of column containing domain id (did) of domain in domain
-		and domain_attrs tables.
+		and domain_attrs tables.  In domain table, a did column value
+		may be NULL, which means that it has same value as
+		domain column.
 		</para>
 		<para>
 		Default value is <quote>did</quote>.

+ 19 - 14
modules_k/domain/domain.c

@@ -414,8 +414,8 @@ int reload_tables ( void )
     domain_dbf.free_result(db_handle, res);
     res = NULL;
 
-    cols[0] = &did_col;
-    cols[1] = &domain_col;
+    cols[0] = &domain_col;
+    cols[1] = &did_col;
     
     if (domain_dbf.use_table(db_handle, &domain_table) < 0) {
 	LM_ERR("error while trying to use domain table\n");
@@ -437,26 +437,31 @@ int reload_tables ( void )
 
 	if ((VAL_NULL(ROW_VALUES(row)) == 1) ||
 	    (VAL_TYPE(ROW_VALUES(row)) != DB1_STRING)) {
-	    LM_ERR("did at row <%u> is null or not string\n", i);
+	    LM_ERR("domain at row <%u> is null or not string\n", i);
 	    goto err;
 	}
-	did.s = (char *)VAL_STRING(ROW_VALUES(row));
-	did.len = strlen(did.s);
-	if (did.len == 0) {
-	    LM_ERR("did at row <%u> is empty string\n", i);
+	domain.s = (char *)VAL_STRING(ROW_VALUES(row));
+	domain.len = strlen(domain.s);
+	if (domain.len == 0) {
+	    LM_ERR("domain at row <%u> is empty string\n", i);
 	    goto err;
 	}
 
-	if ((VAL_NULL(ROW_VALUES(row) + 1) == 1) ||
+	if ((VAL_NULL(ROW_VALUES(row) + 1) != 1) &&
 	    (VAL_TYPE(ROW_VALUES(row) + 1) != DB1_STRING)) {
-	    LM_ERR("domain at row <%u> is null or not string\n", i);
+	    LM_ERR("did at row <%u> is not null or string\n", i);
 	    goto err;
 	}
-	domain.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
-	domain.len = strlen(domain.s);
-	if (domain.len == 0) {
-	    LM_ERR("domain at row <%u> is empty string\n", i);
-	    goto err;
+	if (VAL_NULL(ROW_VALUES(row) + 1) == 1) {
+	    did.s = domain.s;
+	    did.len = domain.len;
+	} else {
+	    did.s = (char *)VAL_STRING(ROW_VALUES(row) + 1);
+	    did.len = strlen(did.s);
+	    if (did.len == 0) {
+		LM_ERR("did at row <%u> is empty string\n", i);
+		goto err;
+	    }
 	}
 
 	LM_INFO("inserting <did/domain> = <%s/%s> into hash table\n",