00001 /** 00002 * @file propertiesMS.c 00003 * 00004 */ 00005 00006 /*** Copyright (c), The Regents of the University of California *** 00007 *** For more information please refer to files in the COPYRIGHT directory ***/ 00008 00009 /** 00010 * @file propertiesMS.c 00011 * 00012 * @brief Manage a list of keyword-value pair properties. 00013 * 00014 * Properties can be used to store metadata extracted from a file or 00015 * database, or to build up a list of options to control how a 00016 * microservice processes data. 00017 * 00018 * @author David R. Nadeau / University of California, San Diego 00019 */ 00020 00021 #include "rsApiHandler.h" 00022 #include "propertiesMS.h" 00023 00024 00025 00026 /** 00027 * \fn msiPropertiesNew( msParam_t *listParam, ruleExecInfo_t *rei ) 00028 * 00029 * \brief Create a new empty property list 00030 * 00031 * \module properties 00032 * 00033 * \since pre-2.1 00034 * 00035 * \author David R. Nadeau / University of California, San Diego 00036 * \date 2007 00037 * 00038 * \usage See clients/icommands/test/rules3.0/ 00039 * 00040 * \param[out] listParam - a KeyValPair_MS_T, the newly created property list 00041 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00042 * handled by the rule engine. The user does not include rei as a 00043 * parameter in the rule invocation. 00044 * 00045 * \DolVarDependence none 00046 * \DolVarModified none 00047 * \iCatAttrDependence none 00048 * \iCatAttrModified none 00049 * \sideeffect none 00050 * 00051 * \return integer 00052 * \retval 0 on success 00053 * \pre none 00054 * \post none 00055 * \sa none 00056 **/ 00057 int 00058 msiPropertiesNew( msParam_t *listParam, ruleExecInfo_t *rei ) 00059 { 00060 RE_TEST_MACRO( " Calling msiPropertiesNew" ); 00061 00062 /* Create empty list */ 00063 fillMsParam( listParam, NULL, 00064 KeyValPair_MS_T, mallocAndZero( sizeof(keyValPair_t) ), NULL ); 00065 return 0; 00066 } 00067 00068 /** 00069 * \fn msiPropertiesClear( msParam_t *listParam, ruleExecInfo_t *rei ) 00070 * 00071 * \brief Clear a property list 00072 * 00073 * \module properties 00074 * 00075 * \since pre-2.1 00076 * 00077 * \author David R. Nadeau / University of California, San Diego 00078 * \date 2007 00079 * 00080 * \usage See clients/icommands/test/rules3.0/ 00081 * 00082 * \param[in,out] listParam - a KeyValPair_MS_T, the property list to clear 00083 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00084 * handled by the rule engine. The user does not include rei as a 00085 * parameter in the rule invocation. 00086 * 00087 * \DolVarDependence none 00088 * \DolVarModified none 00089 * \iCatAttrDependence none 00090 * \iCatAttrModified none 00091 * \sideeffect property list is cleared 00092 * 00093 * \return integer 00094 * \retval 0 on success 00095 * \pre none 00096 * \post none 00097 * \sa none 00098 **/ 00099 int 00100 msiPropertiesClear( msParam_t *listParam, ruleExecInfo_t *rei ) 00101 { 00102 RE_TEST_MACRO( " Calling msiPropertiesClear" ); 00103 00104 /* Check parameters */ 00105 if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 ) 00106 return USER_PARAM_TYPE_ERR; 00107 00108 /* Clear list */ 00109 clearKeyVal( (keyValPair_t*)listParam->inOutStruct ); 00110 return 0; 00111 } 00112 00113 /** 00114 * \fn msiPropertiesClone( msParam_t *listParam, msParam_t *cloneParam, ruleExecInfo_t *rei ) 00115 * 00116 * \brief Clone a property list, returning a new property list 00117 * 00118 * \module properties 00119 * 00120 * \since pre-2.1 00121 * 00122 * \author David R. Nadeau / University of California, San Diego 00123 * \date 2007 00124 * 00125 * \usage See clients/icommands/test/rules3.0/ 00126 * 00127 * \param[in] listParam - a KeyValPair_MS_T, the property list to clone 00128 * \param[out] cloneParam - a KeyValPair_MS_T, the returned clone (new property list) 00129 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00130 * handled by the rule engine. The user does not include rei as a 00131 * parameter in the rule invocation. 00132 * 00133 * \DolVarDependence none 00134 * \DolVarModified none 00135 * \iCatAttrDependence none 00136 * \iCatAttrModified none 00137 * \sideeffect a new peoperty list is created 00138 * 00139 * \return integer 00140 * \retval 0 on success 00141 * \pre none 00142 * \post none 00143 * \sa none 00144 **/ 00145 int 00146 msiPropertiesClone( msParam_t *listParam, msParam_t *cloneParam, ruleExecInfo_t *rei ) 00147 { 00148 RE_TEST_MACRO( " Calling msiPropertiesClone" ); 00149 00150 /* Check parameters */ 00151 if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 ) 00152 return USER_PARAM_TYPE_ERR; 00153 00154 fillMsParam( cloneParam, NULL, 00155 KeyValPair_MS_T, mallocAndZero( sizeof(keyValPair_t) ), NULL ); 00156 replKeyVal( (keyValPair_t*)listParam->inOutStruct, (keyValPair_t*)cloneParam->inOutStruct ); 00157 return 0; 00158 } 00159 00160 00161 00162 /** 00163 * \fn msiPropertiesAdd( msParam_t *listParam, msParam_t* keywordParam, msParam_t* valueParam, ruleExecInfo_t *rei ) 00164 * 00165 * \brief Add a property and value to a property list. 00166 * 00167 * \module properties 00168 * 00169 * \since pre-2.1 00170 * 00171 * \author David R. Nadeau / University of California, San Diego 00172 * \date 2007 00173 * 00174 * \remark Terrell Russell - msi documentation, 2009-06-22 00175 * 00176 * \note If the property is already in the list, its value is changed. 00177 * Otherwise the property is added. 00178 * 00179 * \usage See clients/icommands/test/rules3.0/ 00180 * 00181 * \param[in,out] listParam - a KeyValPair_MS_T, the property list to be added to 00182 * \param[in] keywordParam - a STR_MS_T, a keyword to add 00183 * \param[in] valueParam - a STR_MS_T, a value to add 00184 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00185 * handled by the rule engine. The user does not include rei as a 00186 * parameter in the rule invocation. 00187 * 00188 * \DolVarDependence none 00189 * \DolVarModified none 00190 * \iCatAttrDependence none 00191 * \iCatAttrModified none 00192 * \sideeffect property list changed 00193 * 00194 * \return integer 00195 * \retval 0 on success 00196 * \pre none 00197 * \post none 00198 * \sa msiPropertiesSet 00199 **/ 00200 int 00201 msiPropertiesAdd( msParam_t *listParam, msParam_t* keywordParam, msParam_t* valueParam, ruleExecInfo_t *rei ) 00202 { 00203 RE_TEST_MACRO( " Calling msiPropertiesAdd" ); 00204 00205 /* Check parameters */ 00206 if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 ) 00207 return USER_PARAM_TYPE_ERR; 00208 if ( strcmp( keywordParam->type, STR_MS_T ) != 0 ) 00209 return USER_PARAM_TYPE_ERR; 00210 if ( strcmp( valueParam->type, STR_MS_T ) != 0 ) 00211 return USER_PARAM_TYPE_ERR; 00212 00213 /* Add entry */ 00214 addKeyVal( (keyValPair_t*)listParam->inOutStruct, 00215 (char*)keywordParam->inOutStruct, 00216 (char*)valueParam->inOutStruct ); 00217 return 0; 00218 } 00219 00220 /** 00221 * \fn msiPropertiesRemove( msParam_t *listParam, msParam_t* keywordParam, ruleExecInfo_t *rei ) 00222 * 00223 * \brief Remove a property from the list. 00224 * 00225 * \module properties 00226 * 00227 * \since pre-2.1 00228 * 00229 * \author David R. Nadeau / University of California, San Diego 00230 * \date 2007 00231 * 00232 * \usage See clients/icommands/test/rules3.0/ 00233 * 00234 * \param[in,out] listParam - a KeyValPair_MS_T, the property list to be removed from 00235 * \param[in] keywordParam - a STR_MS_T, a keyword to remove 00236 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00237 * handled by the rule engine. The user does not include rei as a 00238 * parameter in the rule invocation. 00239 * 00240 * \DolVarDependence none 00241 * \DolVarModified none 00242 * \iCatAttrDependence none 00243 * \iCatAttrModified none 00244 * \sideeffect property list changed 00245 * 00246 * \return integer 00247 * \retval 0 on success 00248 * \pre none 00249 * \post none 00250 * \sa none 00251 **/ 00252 int 00253 msiPropertiesRemove( msParam_t *listParam, msParam_t* keywordParam, ruleExecInfo_t *rei ) 00254 { 00255 RE_TEST_MACRO( " Calling msiPropertiesRemove" ); 00256 00257 /* Check parameters */ 00258 if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 ) 00259 return USER_PARAM_TYPE_ERR; 00260 if ( strcmp( keywordParam->type, STR_MS_T ) != 0 ) 00261 return USER_PARAM_TYPE_ERR; 00262 00263 /* Remove entry */ 00264 rmKeyVal( (keyValPair_t*)listParam->inOutStruct, 00265 (char*)keywordParam->inOutStruct ); 00266 return 0; 00267 } 00268 00269 /** 00270 * \fn msiPropertiesGet( msParam_t *listParam, msParam_t* keywordParam, msParam_t* valueParam, ruleExecInfo_t *rei ) 00271 * 00272 * \brief Get the value of a property in a property list. 00273 * 00274 * \module properties 00275 * 00276 * \since pre-2.1 00277 * 00278 * \author David R. Nadeau / University of California, San Diego 00279 * \date 2007 00280 * 00281 * \note The property list is left unmodified. 00282 * 00283 * \usage See clients/icommands/test/rules3.0/ 00284 * 00285 * \param[in,out] listParam - a KeyValPair_MS_T, the property list to be queried 00286 * \param[in] keywordParam - a STR_MS_T, a keyword to get 00287 * \param[out] valueParam - a STR_MS_T, the returned value 00288 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00289 * handled by the rule engine. The user does not include rei as a 00290 * parameter in the rule invocation. 00291 * 00292 * \DolVarDependence none 00293 * \DolVarModified none 00294 * \iCatAttrDependence none 00295 * \iCatAttrModified none 00296 * \sideeffect none 00297 * 00298 * \return integer 00299 * \retval 0 on success 00300 * \pre none 00301 * \post none 00302 * \sa none 00303 **/ 00304 int 00305 msiPropertiesGet( msParam_t *listParam, msParam_t* keywordParam, msParam_t* valueParam, ruleExecInfo_t *rei ) 00306 { 00307 char* value = NULL; 00308 00309 RE_TEST_MACRO( " Calling msiPropertiesGet" ); 00310 00311 /* Check parameters */ 00312 if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 ) 00313 return USER_PARAM_TYPE_ERR; 00314 if ( strcmp( keywordParam->type, STR_MS_T ) != 0 ) 00315 return USER_PARAM_TYPE_ERR; 00316 00317 /* Get value and return it */ 00318 value = getValByKey( (keyValPair_t*)listParam->inOutStruct, 00319 (char*)keywordParam->inOutStruct ); 00320 fillMsParam( valueParam, NULL, STR_MS_T, value, NULL ); 00321 return 0; 00322 } 00323 00324 /** 00325 * \fn msiPropertiesSet( msParam_t *listParam, msParam_t* keywordParam, msParam_t* valueParam, ruleExecInfo_t *rei ) 00326 * 00327 * \brief Set the value of a property in a property list. 00328 * 00329 * \module properties 00330 * 00331 * \since pre-2.1 00332 * 00333 * \author David R. Nadeau / University of California, San Diego 00334 * \date 2007 00335 * 00336 * \note If the property is already 00337 * in the list, its value is changed. Otherwise the property is added. Same as {@link #msiPropertiesAdd}. 00338 * 00339 * \usage See clients/icommands/test/rules3.0/ 00340 * 00341 * \param[in,out] listParam - a KeyValPair_MS_T, the property list to set within 00342 * \param[in] keywordParam - a STR_MS_T, a keyword to set 00343 * \param[out] valueParam - a STR_MS_T, a value 00344 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00345 * handled by the rule engine. The user does not include rei as a 00346 * parameter in the rule invocation. 00347 * 00348 * \DolVarDependence none 00349 * \DolVarModified none 00350 * \iCatAttrDependence none 00351 * \iCatAttrModified none 00352 * \sideeffect propert value changed 00353 * 00354 * \return integer 00355 * \retval 0 on success 00356 * \pre none 00357 * \post none 00358 * \sa msiPropertiesAdd 00359 **/ 00360 int 00361 msiPropertiesSet( msParam_t *listParam, msParam_t* keywordParam, msParam_t* valueParam, ruleExecInfo_t *rei ) 00362 { 00363 return msiPropertiesAdd( listParam, keywordParam, valueParam, rei ); 00364 } 00365 00366 /** 00367 * \fn msiPropertiesExists( msParam_t *listParam, msParam_t* keywordParam, msParam_t* trueFalseParam, ruleExecInfo_t *rei ) 00368 * 00369 * \brief check for a property in a list 00370 * 00371 * \module properties 00372 * 00373 * \since pre-2.1 00374 * 00375 * \author David R. Nadeau / University of California, San Diego 00376 * \date 2007 00377 * 00378 * \remark Terrell Russell - msi documentation, 2009-06-22 00379 * 00380 * \note Return true (integer 1) if the keyword has a property value in the property list, 00381 * and false (integer 0) otherwise. The property list is unmodified. 00382 * 00383 * \usage See clients/icommands/test/rules3.0/ 00384 * 00385 * \param[in,out] listParam - a KeyValPair_MS_T, the property list to look in 00386 * \param[in] keywordParam - a STR_MS_T, a keyword to set 00387 * \param[out] trueFalseParam - a INT_MS_T, true if set 00388 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00389 * handled by the rule engine. The user does not include rei as a 00390 * parameter in the rule invocation. 00391 * 00392 * \DolVarDependence none 00393 * \DolVarModified none 00394 * \iCatAttrDependence none 00395 * \iCatAttrModified none 00396 * \sideeffect none 00397 * 00398 * \return integer 00399 * \retval 0 on success 00400 * \pre none 00401 * \post none 00402 * \sa none 00403 **/ 00404 int 00405 msiPropertiesExists( msParam_t *listParam, msParam_t* keywordParam, msParam_t* trueFalseParam, ruleExecInfo_t *rei ) 00406 { 00407 char* value = NULL; 00408 00409 RE_TEST_MACRO( " Calling msiPropertiesExists" ); 00410 00411 /* Check parameters */ 00412 if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 ) 00413 return USER_PARAM_TYPE_ERR; 00414 if ( strcmp( keywordParam->type, STR_MS_T ) != 0 ) 00415 return USER_PARAM_TYPE_ERR; 00416 00417 /* Get value and return true if exists */ 00418 value = getValByKey( (keyValPair_t*)listParam->inOutStruct, 00419 (char*)keywordParam->inOutStruct ); 00420 fillIntInMsParam( trueFalseParam, (value==NULL) ? 0 : 1 ); 00421 free( (char*)value ); 00422 return 0; 00423 } 00424 00425 00426 00427 00428 00429 /** 00430 * \fn msiPropertiesToString( msParam_t *listParam, msParam_t* stringParam, ruleExecInfo_t *rei ) 00431 * 00432 * \brief Convert a property list into a string buffer. The property list is left unmodified. 00433 * 00434 * \module properties 00435 * 00436 * \since pre-2.1 00437 * 00438 * \author David R. Nadeau / University of California, San Diego 00439 * \date 2007 00440 * 00441 * \note Convert a property list into a string buffer. 00442 * 00443 * \usage See clients/icommands/test/rules3.0/ 00444 * 00445 * \param[in] listParam - a KeyValPair_MS_T, the property list 00446 * \param[out] stringParam - a STR_MS_T, a string buffer 00447 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00448 * handled by the rule engine. The user does not include rei as a 00449 * parameter in the rule invocation. 00450 * 00451 * \DolVarDependence none 00452 * \DolVarModified none 00453 * \iCatAttrDependence none 00454 * \iCatAttrModified none 00455 * \sideeffect none 00456 * 00457 * \return integer 00458 * \retval 0 on success 00459 * \pre none 00460 * \post none 00461 * \sa none 00462 **/ 00463 int 00464 msiPropertiesToString( msParam_t *listParam, msParam_t* stringParam, ruleExecInfo_t *rei ) 00465 { 00466 char* string = NULL; 00467 00468 RE_TEST_MACRO( " Calling msiPropertiesToString" ); 00469 00470 /* Check parameters */ 00471 if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 ) 00472 return USER_PARAM_TYPE_ERR; 00473 00474 /* Create and return string */ 00475 keyValToString( (keyValPair_t*)listParam->inOutStruct, &string ); 00476 fillStrInMsParam( stringParam, string ); 00477 return 0; 00478 } 00479 00480 /** 00481 * \fn msiPropertiesFromString( msParam_t *stringParam, msParam_t* listParam, ruleExecInfo_t *rei ) 00482 * 00483 * \brief Parse a string into a new property list. The existing property list, if any, is deleted. 00484 * 00485 * \module properties 00486 * 00487 * \since pre-2.1 00488 * 00489 * \author David R. Nadeau / University of California, San Diego 00490 * \date 2007 00491 * 00492 * \usage See clients/icommands/test/rules3.0/ 00493 * 00494 * \param[in] stringParam - a STR_MS_T, a string buffer 00495 * \param[out] listParam - a KeyValPair_MS_T, the property list with the strings added 00496 * \param[in,out] rei - The RuleExecInfo structure that is automatically 00497 * handled by the rule engine. The user does not include rei as a 00498 * parameter in the rule invocation. 00499 * 00500 * \DolVarDependence none 00501 * \DolVarModified none 00502 * \iCatAttrDependence none 00503 * \iCatAttrModified none 00504 * \sideeffect none 00505 * 00506 * \return integer 00507 * \retval 0 on success 00508 * \pre none 00509 * \post none 00510 * \sa none 00511 **/ 00512 int 00513 msiPropertiesFromString( msParam_t *stringParam, msParam_t* listParam, ruleExecInfo_t *rei ) 00514 { 00515 keyValPair_t* list = NULL; 00516 00517 RE_TEST_MACRO( " Calling msiPropertiesToString" ); 00518 00519 /* Check parameters */ 00520 if ( strcmp( stringParam->type, STR_MS_T ) != 0 ) 00521 return USER_PARAM_TYPE_ERR; 00522 00523 /* Parse string and return list */ 00524 if ( keyValFromString( (char*)stringParam->inOutStruct, &list ) == 0 ) 00525 fillMsParam( listParam, NULL, KeyValPair_MS_T, list, NULL ); 00526 return 0; 00527 } 00528