Changeset 1222

Show
Ignore:
Timestamp:
03/10/10 16:02:05 (2 years ago)
Author:
Hugo
Message:

idnsOrg/vdnsOrg: added AAAA and NAPTR code

Location:
trunk/unxsBind/interfaces
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/unxsBind/interfaces/org/resource.c

    r1221 r1222  
    12391239                if(cName[strlen(cName)-1]!='.') strcat(cName,"."); 
    12401240        } 
     1241        else if(!strcmp(cRRType,"AAAA")) 
     1242        { 
     1243                register int i; 
     1244                unsigned h1=0; 
     1245                unsigned h2=0; 
     1246                unsigned h3=0; 
     1247                unsigned h4=0; 
     1248                unsigned h5=0; 
     1249                unsigned h6=0; 
     1250                unsigned h7=0; 
     1251                unsigned h8=0; 
     1252                char *cp; 
     1253                unsigned uColonCount=0; 
     1254                unsigned uRead=0; 
     1255 
     1256                //Insure these are empty 
     1257                cParam2[0]=0; 
     1258 
     1259                if(strlen(cParam1)<4) 
     1260                { 
     1261                        cParam1Style="type_fields_req"; 
     1262                        gcMessage="<blink>Error: </blink>IPv6 number must be at least 4 chars long (e.g. 1::a)"; 
     1263                        return(18); 
     1264                } 
     1265 
     1266                //if cParam1 has no consecutive colons we can simply: 
     1267                if((cp=strstr(cParam1,"::"))) 
     1268                { 
     1269                        if(strstr(cp+2,"::")) 
     1270                        { 
     1271                                cParam1Style="type_fields_req";                          
     1272                                gcMessage="<blink>Error: </blink>IPv6 number can not have more than one double colon!"; 
     1273                                return(18); 
     1274                        } 
     1275                } 
     1276 
     1277                //Now for the hard work 
     1278                for(i=0;cParam1[i];i++) 
     1279                { 
     1280                        if(cParam1[i]==':') 
     1281                                uColonCount++; 
     1282                        if(cParam1[i]!=':' && !isxdigit(cParam1[i])) 
     1283                        { 
     1284                                cParam1Style="type_fields_req"; 
     1285                                gcMessage="<blink>Error: </blink>IPv6 number can only have hexadecimal digits and colons!"; 
     1286                                return(18); 
     1287                        } 
     1288                } 
     1289 
     1290                switch(uColonCount) 
     1291                { 
     1292                        case 0: 
     1293                        case 1: 
     1294                                cParam1Style="type_fields_req"; 
     1295                                gcMessage="<blink>Error: </blink>IPv6 too few colons: Min is 2!"; 
     1296                                return(18); 
     1297                        break; 
     1298 
     1299                        case 2: 
     1300                                uRead=sscanf(cParam1,"%x::%x",&h1,&h8); 
     1301                                if(uRead!=2) 
     1302                                { 
     1303                                        cParam1Style="type_fields_req"; 
     1304                                        gcMessage="<blink>Error: </blink>IPv6 format-2 error!"; 
     1305                                        return(18); 
     1306                                } 
     1307                        break; 
     1308 
     1309                        case 3: 
     1310                                uRead=sscanf(cParam1,"%x::%x:%x",&h1,&h7,&h8); 
     1311                                if(uRead!=3) 
     1312                                { 
     1313                                        uRead=sscanf(cParam1,"%x:%x::%x",&h1,&h2,&h8); 
     1314                                        if(uRead!=3) 
     1315                                        { 
     1316                                                cParam1Style="type_fields_req"; 
     1317                                                gcMessage="<blink>Error: </blink>IPv6 format-3 error!"; 
     1318                                                return(18); 
     1319                                        } 
     1320                                } 
     1321                        break; 
     1322 
     1323                        case 4: 
     1324                                uRead=sscanf(cParam1,"%x::%x:%x:%x",&h1,&h6,&h7,&h8); 
     1325                                if(uRead!=4) 
     1326                                { 
     1327                                        uRead=sscanf(cParam1,"%x:%x::%x:%x",&h1,&h2,&h7,&h8); 
     1328                                        if(uRead!=4) 
     1329                                        { 
     1330                                                uRead=sscanf(cParam1,"%x:%x:%x::%x",&h1,&h2,&h3,&h8); 
     1331                                                if(uRead!=4) 
     1332                                                { 
     1333                                                        cParam1Style="type_fields_req"; 
     1334                                                        gcMessage="<blink>Error: </blink>IPv6 format-4 error!"; 
     1335                                                        return(18); 
     1336                                                } 
     1337                                        } 
     1338                                } 
     1339                        break; 
     1340 
     1341                        case 5: 
     1342                                uRead=sscanf(cParam1,"%x::%x:%x:%x:%x",&h1,&h5,&h6,&h7,&h8); 
     1343                                if(uRead!=5) 
     1344                                { 
     1345                                        uRead=sscanf(cParam1,"%x:%x::%x:%x:%x",&h1,&h2,&h6,&h7,&h8); 
     1346                                        if(uRead!=5) 
     1347                                        { 
     1348                                                uRead=sscanf(cParam1,"%x:%x:%x::%x:%x",&h1,&h2,&h3,&h7,&h8); 
     1349                                                if(uRead!=5) 
     1350                                                { 
     1351                                                        uRead=sscanf(cParam1,"%x:%x:%x:%x::%x",&h1,&h2,&h3,&h4,&h8); 
     1352                                                        if(uRead!=5) 
     1353                                                        { 
     1354                                                                cParam1Style="type_fields_req"; 
     1355                                                                gcMessage="<blink>Error: </blink>IPv6 format-5 error!"; 
     1356                                                                return(18); 
     1357                                                        } 
     1358                                                } 
     1359                                        } 
     1360                                } 
     1361                        break; 
     1362 
     1363                        case 6: 
     1364                                uRead=sscanf(cParam1,"%x::%x:%x:%x:%x:%x",&h1,&h4,&h5,&h6,&h7,&h8); 
     1365                                if(uRead!=6) 
     1366                                { 
     1367                                        uRead=sscanf(cParam1,"%x:%x::%x:%x:%x:%x",&h1,&h2,&h5,&h6,&h7,&h8); 
     1368                                        if(uRead!=6) 
     1369                                        { 
     1370                                                uRead=sscanf(cParam1,"%x:%x:%x::%x:%x:%x",&h1,&h2,&h3,&h6,&h7,&h8); 
     1371                                                if(uRead!=6) 
     1372                                                { 
     1373                                                        uRead=sscanf(cParam1,"%x:%x:%x:%x::%x:%x",&h1,&h2,&h3,&h4,&h7,&h8); 
     1374                                                        if(uRead!=6) 
     1375                                                        { 
     1376                                                                uRead=sscanf(cParam1,"%x:%x:%x:%x:%x::%x", 
     1377                                                                                        &h1,&h2,&h3,&h4,&h5,&h8); 
     1378                                                                if(uRead!=6) 
     1379                                                                { 
     1380                                                                        cParam1Style="type_fields_req"; 
     1381                                                                        gcMessage="<blink>Error: </blink>IPv6 format-6 error!"; 
     1382                                                                        return(18); 
     1383                                                                } 
     1384                                                        } 
     1385                                                } 
     1386                                        } 
     1387                                } 
     1388                        break; 
     1389 
     1390                        case 7: 
     1391                                uRead=sscanf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",&h1,&h2,&h3,&h4,&h5,&h6,&h7,&h8); 
     1392                                if(uRead!=8) 
     1393                                { 
     1394                                        cParam1Style="type_fields_req"; 
     1395                                        gcMessage="<blink>Error: </blink>IPv6 format-7 error!"; 
     1396                                        return(18); 
     1397                                } 
     1398                        break; 
     1399 
     1400                        default: 
     1401                                cParam1Style="type_fields_req"; 
     1402                                gcMessage="<blink>Error: </blink>IPv6 too many colons: Max is 7!"; 
     1403                                return(18); 
     1404                         
     1405                } 
     1406 
     1407                //First basic checks for AAAA hosts 
     1408                if(!h1) 
     1409                { 
     1410                        cParam1Style="type_fields_req"; 
     1411                        gcMessage="<blink>Error: </blink>IPv6 number can not have a 0 in first 16 bit hex word."; 
     1412                        return(18); 
     1413                } 
     1414 
     1415                if(!h8) 
     1416                { 
     1417                        cParam1Style="type_fields_req"; 
     1418                        gcMessage=malloc(256); 
     1419                        sprintf(gcMessage,"<blink>Error: </blink>IPv6 number can not have a 0 in last 16 bit hex word:" 
     1420                                        " %x:%x:%x:%x:%x:%x:%x:%x",h1,h2,h3,h4,h5,h6,h7,h8); 
     1421                        return(18); 
     1422                } 
     1423 
     1424                //Mandatory rewrite in shortest possible IPv6 format. 
     1425                //This is needed to speed up DNSSEC and reduce BIND zone file size. 
     1426                //This may not be a good idea. Need to research further: If someone wants to 
     1427                //write a bunch of 0's why not? 
     1428                //Compress empty words: Double colon. Can only be used once. 
     1429                //Trying KISS method here. sprintf does the leading 0 removal for us. 
     1430                //6 consecutive 0 case 
     1431                if(!h2 && !h3 && !h4 && !h5 && !h6 && !h7) 
     1432                        sprintf(cParam1,"%x::%x",h1,h8); 
     1433                //5 consecutive 0 cases 
     1434                else if(!h3 && !h4 && !h5 && !h6 && !h7) 
     1435                        sprintf(cParam1,"%x:%x::%x",h1,h2,h8); 
     1436                else if(!h2 && !h3 && !h4 && !h5 && !h6) 
     1437                        sprintf(cParam1,"%x::%x:%x",h1,h7,h8); 
     1438                //4 consecutive 0 cases 
     1439                else if(!h4 && !h5 && !h6 && !h7) 
     1440                        sprintf(cParam1,"%x:%x:%x::%x",h1,h2,h3, h8); 
     1441                else if(!h3 && !h4 && !h5 && !h6) 
     1442                        sprintf(cParam1,"%x:%x::%x:%x",h1,h2, h7,h8); 
     1443                else if(!h2 && !h3 && !h4 && !h5) 
     1444                        sprintf(cParam1,"%x::%x:%x:%x",h1, h6,h7,h8); 
     1445                //3 consecutive 0 cases 
     1446                else if(!h5 && !h6 && !h7) 
     1447                        sprintf(cParam1,"%x:%x:%x:%x::%x",h1,h2,h3,h4, h8); 
     1448                else if(!h4 && !h5 && !h6) 
     1449                        sprintf(cParam1,"%x:%x:%x::%x:%x",h1,h2,h3, h7,h8); 
     1450                else if(!h3 && !h4 && !h5) 
     1451                        sprintf(cParam1,"%x:%x::%x:%x:%x",h1,h2, h6,h7,h8); 
     1452                else if(!h2 && !h3 && !h4) 
     1453                        sprintf(cParam1,"%x::%x:%x:%x:%x",h1, h5,h6,h7,h8); 
     1454                //2 consecutive 0 cases 
     1455                else if(!h6 && !h7) 
     1456                        sprintf(cParam1,"%x:%x:%x:%x:%x::%x",h1,h2,h3,h4,h5, h8); 
     1457                else if(!h5 && !h6) 
     1458                        sprintf(cParam1,"%x:%x:%x:%x::%x:%x",h1,h2,h3,h4, h7,h8); 
     1459                else if(!h4 && !h5) 
     1460                        sprintf(cParam1,"%x:%x:%x::%x:%x:%x",h1,h2,h3, h6,h7,h8); 
     1461                else if(!h3 && !h4) 
     1462                        sprintf(cParam1,"%x:%x::%x:%x:%x:%x",h1,h2, h5,h6,h7,h8); 
     1463                else if(!h2 && !h3) 
     1464                        sprintf(cParam1,"%x::%x:%x:%x:%x:%x",h1, h4,h5,h6,h7,h8); 
     1465                //0 consecutive 0 case, i.e. no double colon case 
     1466                else if(1) 
     1467                        sprintf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",h1,h2,h3,h4,h5,h6,h7,h8); 
     1468 
     1469        } 
     1470        else if(!strcmp(cRRType,"NAPTR")) 
     1471        { 
     1472        } 
     1473         
    12411474        else if(1) 
    12421475        { 
  • trunk/unxsBind/interfaces/vorg/resource.c

    r1221 r1222  
    12511251                if(cName[strlen(cName)-1]!='.') strcat(cName,"."); 
    12521252        } 
     1253        else if(!strcmp(cRRType,"AAAA")) 
     1254        { 
     1255                register int i; 
     1256                unsigned h1=0; 
     1257                unsigned h2=0; 
     1258                unsigned h3=0; 
     1259                unsigned h4=0; 
     1260                unsigned h5=0; 
     1261                unsigned h6=0; 
     1262                unsigned h7=0; 
     1263                unsigned h8=0; 
     1264                char *cp; 
     1265                unsigned uColonCount=0; 
     1266                unsigned uRead=0; 
     1267 
     1268                //Insure these are empty 
     1269                cParam2[0]=0; 
     1270 
     1271                if(strlen(cParam1)<4) 
     1272                { 
     1273                        cParam1Style="type_fields_req"; 
     1274                        gcMessage="<blink>Error: </blink>IPv6 number must be at least 4 chars long (e.g. 1::a)"; 
     1275                        return(18); 
     1276                } 
     1277 
     1278                //if cParam1 has no consecutive colons we can simply: 
     1279                if((cp=strstr(cParam1,"::"))) 
     1280                { 
     1281                        if(strstr(cp+2,"::")) 
     1282                        { 
     1283                                cParam1Style="type_fields_req";                          
     1284                                gcMessage="<blink>Error: </blink>IPv6 number can not have more than one double colon!"; 
     1285                                return(18); 
     1286                        } 
     1287                } 
     1288 
     1289                //Now for the hard work 
     1290                for(i=0;cParam1[i];i++) 
     1291                { 
     1292                        if(cParam1[i]==':') 
     1293                                uColonCount++; 
     1294                        if(cParam1[i]!=':' && !isxdigit(cParam1[i])) 
     1295                        { 
     1296                                cParam1Style="type_fields_req"; 
     1297                                gcMessage="<blink>Error: </blink>IPv6 number can only have hexadecimal digits and colons!"; 
     1298                                return(18); 
     1299                        } 
     1300                } 
     1301 
     1302                switch(uColonCount) 
     1303                { 
     1304                        case 0: 
     1305                        case 1: 
     1306                                cParam1Style="type_fields_req"; 
     1307                                gcMessage="<blink>Error: </blink>IPv6 too few colons: Min is 2!"; 
     1308                                return(18); 
     1309                        break; 
     1310 
     1311                        case 2: 
     1312                                uRead=sscanf(cParam1,"%x::%x",&h1,&h8); 
     1313                                if(uRead!=2) 
     1314                                { 
     1315                                        cParam1Style="type_fields_req"; 
     1316                                        gcMessage="<blink>Error: </blink>IPv6 format-2 error!"; 
     1317                                        return(18); 
     1318                                } 
     1319                        break; 
     1320 
     1321                        case 3: 
     1322                                uRead=sscanf(cParam1,"%x::%x:%x",&h1,&h7,&h8); 
     1323                                if(uRead!=3) 
     1324                                { 
     1325                                        uRead=sscanf(cParam1,"%x:%x::%x",&h1,&h2,&h8); 
     1326                                        if(uRead!=3) 
     1327                                        { 
     1328                                                cParam1Style="type_fields_req"; 
     1329                                                gcMessage="<blink>Error: </blink>IPv6 format-3 error!"; 
     1330                                                return(18); 
     1331                                        } 
     1332                                } 
     1333                        break; 
     1334 
     1335                        case 4: 
     1336                                uRead=sscanf(cParam1,"%x::%x:%x:%x",&h1,&h6,&h7,&h8); 
     1337                                if(uRead!=4) 
     1338                                { 
     1339                                        uRead=sscanf(cParam1,"%x:%x::%x:%x",&h1,&h2,&h7,&h8); 
     1340                                        if(uRead!=4) 
     1341                                        { 
     1342                                                uRead=sscanf(cParam1,"%x:%x:%x::%x",&h1,&h2,&h3,&h8); 
     1343                                                if(uRead!=4) 
     1344                                                { 
     1345                                                        cParam1Style="type_fields_req"; 
     1346                                                        gcMessage="<blink>Error: </blink>IPv6 format-4 error!"; 
     1347                                                        return(18); 
     1348                                                } 
     1349                                        } 
     1350                                } 
     1351                        break; 
     1352 
     1353                        case 5: 
     1354                                uRead=sscanf(cParam1,"%x::%x:%x:%x:%x",&h1,&h5,&h6,&h7,&h8); 
     1355                                if(uRead!=5) 
     1356                                { 
     1357                                        uRead=sscanf(cParam1,"%x:%x::%x:%x:%x",&h1,&h2,&h6,&h7,&h8); 
     1358                                        if(uRead!=5) 
     1359                                        { 
     1360                                                uRead=sscanf(cParam1,"%x:%x:%x::%x:%x",&h1,&h2,&h3,&h7,&h8); 
     1361                                                if(uRead!=5) 
     1362                                                { 
     1363                                                        uRead=sscanf(cParam1,"%x:%x:%x:%x::%x",&h1,&h2,&h3,&h4,&h8); 
     1364                                                        if(uRead!=5) 
     1365                                                        { 
     1366                                                                cParam1Style="type_fields_req"; 
     1367                                                                gcMessage="<blink>Error: </blink>IPv6 format-5 error!"; 
     1368                                                                return(18); 
     1369                                                        } 
     1370                                                } 
     1371                                        } 
     1372                                } 
     1373                        break; 
     1374 
     1375                        case 6: 
     1376                                uRead=sscanf(cParam1,"%x::%x:%x:%x:%x:%x",&h1,&h4,&h5,&h6,&h7,&h8); 
     1377                                if(uRead!=6) 
     1378                                { 
     1379                                        uRead=sscanf(cParam1,"%x:%x::%x:%x:%x:%x",&h1,&h2,&h5,&h6,&h7,&h8); 
     1380                                        if(uRead!=6) 
     1381                                        { 
     1382                                                uRead=sscanf(cParam1,"%x:%x:%x::%x:%x:%x",&h1,&h2,&h3,&h6,&h7,&h8); 
     1383                                                if(uRead!=6) 
     1384                                                { 
     1385                                                        uRead=sscanf(cParam1,"%x:%x:%x:%x::%x:%x",&h1,&h2,&h3,&h4,&h7,&h8); 
     1386                                                        if(uRead!=6) 
     1387                                                        { 
     1388                                                                uRead=sscanf(cParam1,"%x:%x:%x:%x:%x::%x", 
     1389                                                                                        &h1,&h2,&h3,&h4,&h5,&h8); 
     1390                                                                if(uRead!=6) 
     1391                                                                { 
     1392                                                                        cParam1Style="type_fields_req"; 
     1393                                                                        gcMessage="<blink>Error: </blink>IPv6 format-6 error!"; 
     1394                                                                        return(18); 
     1395                                                                } 
     1396                                                        } 
     1397                                                } 
     1398                                        } 
     1399                                } 
     1400                        break; 
     1401 
     1402                        case 7: 
     1403                                uRead=sscanf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",&h1,&h2,&h3,&h4,&h5,&h6,&h7,&h8); 
     1404                                if(uRead!=8) 
     1405                                { 
     1406                                        cParam1Style="type_fields_req"; 
     1407                                        gcMessage="<blink>Error: </blink>IPv6 format-7 error!"; 
     1408                                        return(18); 
     1409                                } 
     1410                        break; 
     1411 
     1412                        default: 
     1413                                cParam1Style="type_fields_req"; 
     1414                                gcMessage="<blink>Error: </blink>IPv6 too many colons: Max is 7!"; 
     1415                                return(18); 
     1416                         
     1417                } 
     1418 
     1419                //First basic checks for AAAA hosts 
     1420                if(!h1) 
     1421                { 
     1422                        cParam1Style="type_fields_req"; 
     1423                        gcMessage="<blink>Error: </blink>IPv6 number can not have a 0 in first 16 bit hex word."; 
     1424                        return(18); 
     1425                } 
     1426 
     1427                if(!h8) 
     1428                { 
     1429                        cParam1Style="type_fields_req"; 
     1430                        gcMessage=malloc(256); 
     1431                        sprintf(gcMessage,"<blink>Error: </blink>IPv6 number can not have a 0 in last 16 bit hex word:" 
     1432                                        " %x:%x:%x:%x:%x:%x:%x:%x",h1,h2,h3,h4,h5,h6,h7,h8); 
     1433                        return(18); 
     1434                } 
     1435 
     1436                //Mandatory rewrite in shortest possible IPv6 format. 
     1437                //This is needed to speed up DNSSEC and reduce BIND zone file size. 
     1438                //This may not be a good idea. Need to research further: If someone wants to 
     1439                //write a bunch of 0's why not? 
     1440                //Compress empty words: Double colon. Can only be used once. 
     1441                //Trying KISS method here. sprintf does the leading 0 removal for us. 
     1442                //6 consecutive 0 case 
     1443                if(!h2 && !h3 && !h4 && !h5 && !h6 && !h7) 
     1444                        sprintf(cParam1,"%x::%x",h1,h8); 
     1445                //5 consecutive 0 cases 
     1446                else if(!h3 && !h4 && !h5 && !h6 && !h7) 
     1447                        sprintf(cParam1,"%x:%x::%x",h1,h2,h8); 
     1448                else if(!h2 && !h3 && !h4 && !h5 && !h6) 
     1449                        sprintf(cParam1,"%x::%x:%x",h1,h7,h8); 
     1450                //4 consecutive 0 cases 
     1451                else if(!h4 && !h5 && !h6 && !h7) 
     1452                        sprintf(cParam1,"%x:%x:%x::%x",h1,h2,h3, h8); 
     1453                else if(!h3 && !h4 && !h5 && !h6) 
     1454                        sprintf(cParam1,"%x:%x::%x:%x",h1,h2, h7,h8); 
     1455                else if(!h2 && !h3 && !h4 && !h5) 
     1456                        sprintf(cParam1,"%x::%x:%x:%x",h1, h6,h7,h8); 
     1457                //3 consecutive 0 cases 
     1458                else if(!h5 && !h6 && !h7) 
     1459                        sprintf(cParam1,"%x:%x:%x:%x::%x",h1,h2,h3,h4, h8); 
     1460                else if(!h4 && !h5 && !h6) 
     1461                        sprintf(cParam1,"%x:%x:%x::%x:%x",h1,h2,h3, h7,h8); 
     1462                else if(!h3 && !h4 && !h5) 
     1463                        sprintf(cParam1,"%x:%x::%x:%x:%x",h1,h2, h6,h7,h8); 
     1464                else if(!h2 && !h3 && !h4) 
     1465                        sprintf(cParam1,"%x::%x:%x:%x:%x",h1, h5,h6,h7,h8); 
     1466                //2 consecutive 0 cases 
     1467                else if(!h6 && !h7) 
     1468                        sprintf(cParam1,"%x:%x:%x:%x:%x::%x",h1,h2,h3,h4,h5, h8); 
     1469                else if(!h5 && !h6) 
     1470                        sprintf(cParam1,"%x:%x:%x:%x::%x:%x",h1,h2,h3,h4, h7,h8); 
     1471                else if(!h4 && !h5) 
     1472                        sprintf(cParam1,"%x:%x:%x::%x:%x:%x",h1,h2,h3, h6,h7,h8); 
     1473                else if(!h3 && !h4) 
     1474                        sprintf(cParam1,"%x:%x::%x:%x:%x:%x",h1,h2, h5,h6,h7,h8); 
     1475                else if(!h2 && !h3) 
     1476                        sprintf(cParam1,"%x::%x:%x:%x:%x:%x",h1, h4,h5,h6,h7,h8); 
     1477                //0 consecutive 0 case, i.e. no double colon case 
     1478                else if(1) 
     1479                        sprintf(cParam1,"%x:%x:%x:%x:%x:%x:%x:%x",h1,h2,h3,h4,h5,h6,h7,h8); 
     1480 
     1481        } 
     1482        else if(!strcmp(cRRType,"NAPTR")) 
     1483        { 
     1484        } 
     1485 
    12531486        else if(1) 
    12541487        {