diff options
Diffstat (limited to 'lib/libtinytac/lmemory.c')
| -rw-r--r-- | lib/libtinytac/lmemory.c | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/lib/libtinytac/lmemory.c b/lib/libtinytac/lmemory.c index c9a005f..0664d12 100644 --- a/lib/libtinytac/lmemory.c +++ b/lib/libtinytac/lmemory.c | |||
| @@ -94,6 +94,13 @@ tinytac_set_option_host( | |||
| 94 | const char * invalue ); | 94 | const char * invalue ); |
| 95 | 95 | ||
| 96 | 96 | ||
| 97 | static int | ||
| 98 | tinytac_set_option_keys( | ||
| 99 | TinyTac * tt, | ||
| 100 | const char * invalue, | ||
| 101 | char * const * invalues ); | ||
| 102 | |||
| 103 | |||
| 97 | //-------------------// | 104 | //-------------------// |
| 98 | // object prototypes // | 105 | // object prototypes // |
| 99 | //-------------------// | 106 | //-------------------// |
| @@ -115,6 +122,7 @@ const char * tinytac_dflt_hosts = TTAC_DFLT_HOSTS; | |||
| 115 | char tinytac_dflt_hosts_buff[128]; | 122 | char tinytac_dflt_hosts_buff[128]; |
| 116 | unsigned tinytac_dflt_opts = TTAC_DFLT_OPTS; | 123 | unsigned tinytac_dflt_opts = TTAC_DFLT_OPTS; |
| 117 | unsigned tinytac_dflt_opts_neg = TTAC_DFLT_OPTS_NEG; | 124 | unsigned tinytac_dflt_opts_neg = TTAC_DFLT_OPTS_NEG; |
| 125 | char ** tinytac_dflt_keys = NULL; | ||
| 118 | 126 | ||
| 119 | 127 | ||
| 120 | ///////////////// | 128 | ///////////////// |
| @@ -139,8 +147,8 @@ tinytac_tiytac_free( | |||
| 139 | 147 | ||
| 140 | if ((tt->hosts)) | 148 | if ((tt->hosts)) |
| 141 | free(tt->hosts); | 149 | free(tt->hosts); |
| 142 | if ((tt->key)) | 150 | if ((tt->keys)) |
| 143 | free(tt->key); | 151 | tinytacb_strsfree(tt->keys); |
| 144 | 152 | ||
| 145 | memset(tt, 0, sizeof(TinyTac)); | 153 | memset(tt, 0, sizeof(TinyTac)); |
| 146 | free(tt); | 154 | free(tt); |
| @@ -264,10 +272,10 @@ tinytac_initialize( | |||
| 264 | tinytac_tiytac_free(tt); | 272 | tinytac_tiytac_free(tt); |
| 265 | return(rc); | 273 | return(rc); |
| 266 | }; | 274 | }; |
| 267 | if ((tt->key = strdup(key)) == NULL) | 275 | if ((rc = tinytac_set_option(tt, TTAC_OPT_KEY, key)) != TTAC_SUCCESS) |
| 268 | { | 276 | { |
| 269 | tinytac_tiytac_free(tt); | 277 | tinytac_tiytac_free(tt); |
| 270 | return(TTAC_ENOMEM); | 278 | return(rc); |
| 271 | }; | 279 | }; |
| 272 | 280 | ||
| 273 | *ttp = tinytac_obj_retain(&tt->obj); | 281 | *ttp = tinytac_obj_retain(&tt->obj); |
| @@ -334,6 +342,14 @@ tinytac_set_option( | |||
| 334 | TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_HOSTS, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); | 342 | TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_HOSTS, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); |
| 335 | return(tinytac_set_option_host(tt, invalue)); | 343 | return(tinytac_set_option_host(tt, invalue)); |
| 336 | 344 | ||
| 345 | case TTAC_OPT_KEY: | ||
| 346 | TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_KEY, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); | ||
| 347 | return(tinytac_set_option_keys(tt, invalue, NULL)); | ||
| 348 | |||
| 349 | case TTAC_OPT_KEYS: | ||
| 350 | TinyTacDebug(TTAC_DEBUG_ARGS, " == %s( %s, TTAC_OPT_KEYS, invalue )", __func__, (((tt)) ? "tt" : "NULL") ); | ||
| 351 | return(tinytac_set_option_keys(tt, NULL, invalue)); | ||
| 352 | |||
| 337 | default: | 353 | default: |
| 338 | break; | 354 | break; |
| 339 | }; | 355 | }; |
| @@ -403,6 +419,44 @@ tinytac_set_option_host( | |||
| 403 | } | 419 | } |
| 404 | 420 | ||
| 405 | 421 | ||
| 422 | int | ||
| 423 | tinytac_set_option_keys( | ||
| 424 | TinyTac * tt, | ||
| 425 | const char * invalue, | ||
| 426 | char * const * invalues ) | ||
| 427 | { | ||
| 428 | char *** strsp; | ||
| 429 | char ** strs; | ||
| 430 | |||
| 431 | TinyTacDebugTrace(); | ||
| 432 | |||
| 433 | strs = NULL; | ||
| 434 | strsp = ((tt)) ? &tt->keys : &tinytac_dflt_keys; | ||
| 435 | |||
| 436 | if ((invalue)) | ||
| 437 | { | ||
| 438 | if (tinytacb_strsadd(&strs, invalue) != 0) | ||
| 439 | return(TTAC_ENOMEM); | ||
| 440 | } | ||
| 441 | else if ((invalues)) | ||
| 442 | { | ||
| 443 | if (tinytacb_strsdup(&strs, invalues) != 0) | ||
| 444 | return(TTAC_ENOMEM); | ||
| 445 | } | ||
| 446 | else if ((tt)) | ||
| 447 | { | ||
| 448 | if ((tinytac_dflt_keys)) | ||
| 449 | if (tinytacb_strsdup(&strs, tinytac_dflt_keys) != 0) | ||
| 450 | return(TTAC_ENOMEM); | ||
| 451 | }; | ||
| 452 | |||
| 453 | tinytacb_strsfree(*strsp); | ||
| 454 | *strsp = strs; | ||
| 455 | |||
| 456 | return(TTAC_SUCCESS); | ||
| 457 | } | ||
| 458 | |||
| 459 | |||
| 406 | //------------------// | 460 | //------------------// |
| 407 | // object functions // | 461 | // object functions // |
| 408 | //------------------// | 462 | //------------------// |
