The SmsAddToken function adds a token at the specified index in the specified filter or inventory rules folder.
SMS_STATUS SmsAddToken(
HANDLE hFilter, // Handle to filter or inventory rules folder.
ANDOR opAndOr, // Control token for connecting the expression to
// adjacent expression.
TOKEN *pTokenInfo,
// Pointer to token structure containing the
// expression token.
INT iIndex // Location to insert the control token and
// expression token.
);
Important For attribute filters, group filters, site filters, and architecture filters, tokens can only be connected using an OP_OR control token—this means that your application must pass OP_OR for the opAndOr parameter when calling the SmsAddToken function to add a token to one of these filter types. If your application passes OP_AND for the opAndOr parameter, a status of SMS_PARAMETER_ERROR is returned.
The index is an integer that represents a token's position within a filter or inventory rules folder. The index for the first token is always zero. If the filter or inventory rules folder is empty (that is, it contains no tokens), the expression token is added as the first token and no control token is added. If the index does not exist within the filter or inventory rules folder (that is, if the index is greater than the current number of tokens in the filter or inventory rules filter), the new tokens are added at the end of the filter or inventory rules filter.
Note Because the indexes of tokens following added tokens are modified to account for the new tokens, your application should not rely on the index to identify a token. Your application should use the SmsGetToken to verify the contents of the token. In addition, when your application is building a filter or inventory rules folder, it is recommended that your application use the AT_START or AT_END index values to add tokens to the filter or inventory rules folder sequentially.
When tokens are added or removed from a filter or inventory rules folder, the indexes of the tokens that follow the added or removed tokens are adjusted. For example, if a filter has five tokens (indexes 0, 1, 2, 3,and 4) and SmsAddToken is used to add a token at index 2, the new control token would be index 3 and the new expression would be index 4. The tokens that were previously at index 3 and 4 now have index 5 and 6.
The SmsAddToken function returns a status code SMS_STATUS. If successful, the function returns a status of SMS_OK. Otherwise, it returns the following manifest constants:
If your application attempted to add a token to an inventory rules folder and the szTokenString member of the TOKEN structure also uses the retrieve keyword, the szTokenString member may contain a file name that specifies an incorrect location for the file. SmsAddToken will not add the token to the inventory rules folder and will return a status of SMS_PARAMETER_ERROR.
If your application passes OP_AND for the opAndOr parameter for an attribute filter, group filter, site filter, or architecture filter, a status of SMS_PARAMETER_ERROR is returned.
For filters of type GROUP_FILTER, the SMS API engine does not validate the existence of the group specified by a group token. Your application is responsible for creating a token for a valid group class.
// Add a token to the end of an architecture filter.
TOKEN Token;
memset( &Token, 0, sizeof (TOKEN) ); // Clear the Token structure.
//**************************************************************
//******* Set the expression token to "Architecture is equal to
//******* Personal Computer".
// Set the name of the value to be evaluated.
strcpy( Token.szName, "Architecture");
// Set the operator used to evaluate the expression.
Token.dwOp = QOP_STR_EQ; // Use the equals operator.
// Set the value to evaulate.
strcpy( Token.szValue, "Personal Computer");
// Add the token to the filter.
stat = SmsAddToken( hFilter, // Specifies the handle to filter.
OP_AND, // Use the AND control token to connect
// the expression.
&Token, // Specifies the structure containing
// the expression token.
AT_END // Add the token to the end of
// the filter.
);