globus_result_t globus_xio_string_cntl_string_list( void * attr, const char * key, const char * val, int cmd, globus_xio_driver_attr_cntl_t cntl_func) { int i = 0; globus_list_t * val_list; globus_list_t * list; char ** argv; int argc; globus_result_t result; int del; /* delimitor is the first character */ if(val == NULL) { return GLOBUS_SUCCESS; } del = (int)*val; val++; val_list = globus_list_from_string(val, del, NULL); list = val_list; argc = globus_list_size(list); argv = (char **) calloc(argc+1, sizeof(char *)); i = argc - 1; while(!globus_list_empty(list)) { argv[i] = (char *)globus_list_first(list); list = globus_list_rest(list); i--; } result = globus_xio_string_cntl_bouncer(cntl_func, attr, cmd, argv); globus_list_destroy_all(val_list, globus_libc_free); globus_free(argv); return result; }
static void globus_l_gss_read_test_cases(char * filename) { int fd; int rc; struct stat st; char * buffer; char * line; compare_name_test_case_t * test_case; globus_list_t * rline_list = NULL; static char name_type1[32], name_type2[32]; static char name_token1[128], name_token2[128]; static char expectation[16]; rc = stat(filename, &st); if (rc != 0) { perror("stat"); exit(1); } buffer = malloc(st.st_size + 1); if (buffer == NULL) { perror("malloc"); exit(1); } fd = open(filename, O_RDONLY, 0); if (fd < 0) { perror("open"); exit(1); } rc = read(fd, buffer, st.st_size); if (rc != st.st_size) { perror("read"); exit(1); } buffer[st.st_size] = '\0'; /* reversed order list */ rline_list = globus_list_from_string(buffer, '\n', " \t\r\n"); while (! globus_list_empty(rline_list)) { line = globus_list_remove(&rline_list, rline_list); if (strlen(line) != 0) { test_case = calloc(1, sizeof(compare_name_test_case_t)); sscanf(line, "%[^,], %[^,], %[^,], %[^,], %[^,]", name_type1, name_token1, name_type2, name_token2, expectation); test_case->test_name = strdup(line); compare_l_parse_name_type( name_type1, name_token1, &test_case->name_type1, &test_case->name_token1); compare_l_parse_name_type( name_type2, name_token2, &test_case->name_type2, &test_case->name_token2); if (strcmp(expectation, "GLOBUS_TRUE") == 0) { test_case->expectation = GLOBUS_TRUE; } else if (strcmp(expectation, "GLOBUS_FALSE") == 0) { test_case->expectation = GLOBUS_FALSE; } else { globus_assert((strcmp(expectation, "GLOBUS_FALSE") == 0) || (strcmp(expectation, "GLOBUS_FALSE") == 0)); } globus_list_insert(&test_cases, test_case); } free(line); } free(buffer); }
/* STRING PARSING ATTR SETTING */ globus_result_t globus_i_xio_string_cntl_parser( const char * env_str, globus_xio_string_cntl_table_t * table, void * attr, globus_xio_driver_attr_cntl_t cntl_func) { int i; char * key; char * val; char * tmp_s; globus_list_t * list; globus_object_t * error = NULL; globus_result_t res = GLOBUS_SUCCESS; GlobusXIOName(globus_i_xio_string_cntl_parser); list = globus_list_from_string(env_str, ';', NULL); while(!globus_list_empty(list)) { key = (char *) globus_list_remove(&list, list); tmp_s = strchr(key, '='); if(tmp_s != NULL) { *tmp_s = '\0'; val = tmp_s + 1; for(i = 0; table[i].key != NULL; i++) { /* if we have a match */ if(strcmp(table[i].key, key) == 0) { res = table[i].parse_func( attr, key, val, table[i].cmd, cntl_func); if(res != GLOBUS_SUCCESS) { /* restore '=' */ *tmp_s = '='; res = GlobusXIOErrorWrapFailedWithMessage( res, "String cntl '%s' failed", key); } break; } } if(!table[i].key) { res = GlobusXIOErrorParameter(key); } } else { res = GlobusXIOErrorParameter(key); } if(res != GLOBUS_SUCCESS) { if(!error) { error = globus_error_construct_multiple( GLOBUS_XIO_MODULE, GLOBUS_XIO_ERROR_PARAMETER, "One or more of the string cntls failed"); } globus_error_mutliple_add_chain( error, globus_error_get(res), NULL); } globus_free(key); } return globus_error_put(error); }
static globus_result_t globus_l_xio_net_manager_attr_set_string_options( globus_l_xio_net_manager_attr_t *attr, const char *options_string) { globus_result_t result = GLOBUS_SUCCESS; globus_list_t *options = NULL; globus_list_t *rev_options; int num_options; globus_net_manager_attr_t *new_attrs; globus_net_manager_context_t new_context = NULL; char *scope = NULL; char *new_task_id = NULL; size_t attrnum = 0; rev_options = globus_list_from_string(options_string, ';', NULL); /* dislike that this func produces a reversed list */ while (!globus_list_empty(rev_options)) { globus_list_insert( &options, globus_list_remove(&rev_options, rev_options)); } num_options = globus_list_size(options); if (num_options == 0) { goto no_options; } new_attrs = calloc(num_options+1, sizeof(globus_net_manager_attr_t)); if (!new_attrs) { result = GlobusNetManagerErrorMemory("attr_array"); goto new_attrs_calloc_fail; } while (!globus_list_empty(options)) { char *opt, *val; opt = globus_list_remove(&options, options); if (*opt == '\0') { free(opt); continue; } val = strchr(opt, '='); if (!val) { result = GlobusNetManagerErrorParameter("Invalid option string."); free(opt); goto no_equals; } *val++ = '\0'; if (strcmp(opt, "manager") == 0) { result = globus_net_manager_attr_init( &new_attrs[attrnum++], "net_manager", opt, val); if (result) { free(opt); new_attrs[attrnum-1] = globus_net_manager_null_attr; goto new_attr_init_fail; } free(scope); scope = strdup(val); if (!scope) { result = GlobusNetManagerErrorMemory("scope"); free(opt); new_attrs[attrnum++] = globus_net_manager_null_attr; goto strdup_scope_fail; } } else if (strcmp(opt, "task-id") == 0) { free(new_task_id); new_task_id = strdup(val); if (!new_task_id) { result = GlobusNetManagerErrorMemory("task-id"); free(opt); new_attrs[attrnum++] = globus_net_manager_null_attr; goto strdup_task_id_fail; } } else { result = globus_net_manager_attr_init( &new_attrs[attrnum++], scope ? scope : "global", opt, val); if (result) { free(opt); new_attrs[attrnum-1] = globus_net_manager_null_attr; goto new_attr_init_fail; } } free(opt); } new_attrs[attrnum++] = globus_net_manager_null_attr; if (new_attrs) { result = globus_net_manager_context_init( &new_context, new_attrs); if (result) { goto new_context_fail; } globus_net_manager_context_destroy(attr->context); attr->context = new_context; } if (new_task_id) { free(attr->task_id); attr->task_id = new_task_id; new_task_id = NULL; } if (new_attrs) { globus_net_manager_attr_array_delete(attr->attr_array); attr->attr_array = new_attrs; new_attrs = NULL; } new_context_fail: new_attr_init_fail: strdup_task_id_fail: strdup_scope_fail: no_equals: free(new_task_id); free(scope); globus_net_manager_attr_array_delete(new_attrs); new_attrs_calloc_fail: globus_list_destroy_all(options, free); no_options: return result; }