#include stdio #include string #include descrip #include stdlib #include ssdef #include #include /* * Description: Sample program to demonstrate how to add a value to an * attribute of a DECdns object. * * Parameters: * This program takes 4 arguments. They are: * argv[0] = name of this program * argv[1] = name of object in string (printable) format * argv[2] = attribute of object given in argv[1] * argv[3] = value for the attribute given in argv[2] * * Returns: * Returns status from sys$dnsw, dns$_modify_attribute function. * */ main(int argc,char *argv[]) { struct $dnsitmdef parseitem[7]; /* Item list for parsing */ unsigned char class[dns$k_simplenamemax]; /* Opaque class name */ unsigned char fullname_buf[dns$k_fullnamemax]; /* Opaque object name */ int status; /* General routine status */ struct $dnsb dnsb; /* Used for nameserver status information */ unsigned short fname_len; /* Length of object name */ unsigned short class_len; /* Length of class name */ /* * Make certain that you have the number of arguments you expect. */ if (argc != 4) { printf("USAGE: "); printf("add_attribute \n"); exit(0); } /* * Convert the object string name into opaque format. */ /* First item contains the address of the object string name */ parseitem[0].dns$w_itm_code = dns$_fromstringname; parseitem[0].dns$w_itm_size = strlen(argv[1]); parseitem[0].dns$a_itm_address = argv[1]; /* Second item contains the address of the buffer to receive the * opaque fullname of the object. */ parseitem[1].dns$w_itm_code = dns$_tofullname; parseitem[1].dns$w_itm_size = dns$k_fullnamemax; parseitem[1].dns$a_itm_address = fullname_buf; parseitem[1].dns$a_itm_ret_length = &fname_len; /* Zero terminates the itemlist to indicate no more item blocks. */ *((int *)&parseitem[2]) = 0; /* Use system service to convert object name to opaque format */ status = sys$dnsw(0, dns$_parse_fullname_string, &parseitem, &dnsb, 0, 0); /* * Must check both the return status from the service, plus the * status from the nameserver in all cases. */ if (status == SS$_NORMAL) { status = dnsb.dns$l_dnsb_status; } /* If error, print message and terminate. */ if (status != SS$_NORMAL) { printf("Error converting name %s\n", argv[1]); exit(status); } /* * Convert the class string name into opaque format. */ /* First item is the address of the class name in string format. */ parseitem[0].dns$w_itm_code = dns$_fromstringname; parseitem[0].dns$w_itm_size = strlen(argv[2]); parseitem[0].dns$a_itm_address = argv[2]; /* Second item is the address of the buffer which will contain the * opaque version of the class name. Size of the actual class name * will be found in class_len. */ parseitem[1].dns$w_itm_code = dns$_tosimplename; parseitem[1].dns$w_itm_size = dns$k_simplenamemax; parseitem[1].dns$a_itm_address = class; parseitem[1].dns$a_itm_ret_length = &class_len; /* Zero terminates the itemlist to indicate no more item blocks. */ *((int *)&parseitem[2]) = 0; /* Use system service to convert class name to opaque format */ status = sys$dnsw(0, dns$_parse_simplename_string, &parseitem, &dnsb, 0, 0); /* * Must check both the return status from the service, plus the * status from the nameserver in all cases. */ if (status == SS$_NORMAL) { status = dnsb.dns$l_dnsb_status; } /* If an error occurred, print out the message and terminate */ if (status != SS$_NORMAL) { printf("Error converting name %s\n", argv[2]); exit(status); } printf("Adding attribute \"%s\", value \"%s\"\n", argv[2], argv[3]); /* Add an attribute to the object using module defined below */ status = add_attribute(fullname_buf, fname_len, class, class_len, argv[3], strlen(argv[3])); /* If an error occurred, print it out and terminate */ if (status != SS$_NORMAL) { printf("Status from add_attribute = %d\n", status); } exit(status); } /* * Description: Function to add a value to an attribute of a DECdns object. * * Parameters: * obj_name = address of opaque full name of the object to create * in the namespace. * obj_len = length (in bytes) of the opaque full name of the * object to create * att_name = address of the opaque simple name of the attribute * to create * att_len = length in bytes of the attribute opaque simple name * * att_value = value to associate withe the attribute * * val_len = length in bytes of the added value * * Returns: * Returns status from sys$dnsw, dns$_modify_attribute function. */ int add_attribute( unsigned char *obj_name, unsigned short obj_len, unsigned char *att_name, unsigned short att_len, unsigned char *att_value, unsigned short val_len) { struct $dnsitmdef moditem[7]; /* system service item list */ unsigned char objtype = dns$k_object; /* using objects */ unsigned char opertype = dns$k_present; /* adding an objects */ unsigned char atttype = dns$k_set; /* attribute will be of type set */ struct $dnsb dnsb; /* DECdns server status */ int status; /* return status */ /* * Construct the item list that modifies the attribute */ /* Item identifies name to which you are adding the attribute */ moditem[0].dns$w_itm_size = obj_len; moditem[0].dns$w_itm_code = dns$_entry; moditem[0].dns$a_itm_address = obj_name; /* Item identifies name from previous item as an object */ moditem[1].dns$w_itm_size = sizeof(char); moditem[1].dns$w_itm_code = dns$_lookingfor; moditem[1].dns$a_itm_address = &objtype; /* Item indicates you are adding data */ moditem[2].dns$w_itm_size = sizeof(char); moditem[2].dns$w_itm_code = dns$_modoperation; moditem[2].dns$a_itm_address = &opertype; /* Item indicates the attribute you are adding to is a set */ moditem[3].dns$w_itm_size = sizeof(char); moditem[3].dns$w_itm_code = dns$_attributetype; moditem[3].dns$a_itm_address = &atttype; /* Item indicates what attribute you want to add to */ moditem[4].dns$w_itm_size = att_len; moditem[4].dns$w_itm_code = dns$_attributename; moditem[4].dns$a_itm_address = att_name; /* Item contains value you are adding to the attribute */ moditem[5].dns$w_itm_size = val_len; moditem[5].dns$w_itm_code = dns$_modvalue; moditem[5].dns$a_itm_address = att_value; /* Zero terminates the itemlist to indicate no more item codes. */ *((int *)&moditem[6]) = 0; status = sys$dnsw(0, dns$_modify_attribute, &moditem, &dnsb, 0, 0); /* * Must check both the return status from the service, plus the * status from the nameserver in all cases. */ if (status == SS$_NORMAL) { status = dnsb.dns$l_dnsb_status; } return(status); }