globus_result_t globus_xio_contact_copy( globus_xio_contact_t * dst, const globus_xio_contact_t * src) { globus_result_t result; GlobusXIOName(globus_xio_contact_copy); if(dst == NULL) { result = GlobusXIOErrorParameter("dst"); goto error; } if(src == NULL) { result = GlobusXIOErrorParameter("src"); goto error; } memset(dst, '\0', sizeof(globus_xio_contact_t)); if(src->unparsed) { dst->unparsed = strdup(src->unparsed); } if(src->resource) { dst->resource = strdup(src->resource); } if(src->host) { dst->host = strdup(src->host); } if(src->port) { dst->port = strdup(src->port); } if(src->scheme) { dst->scheme = strdup(src->scheme); } if(src->user) { dst->user = strdup(src->user); } if(src->pass) { dst->pass = strdup(src->pass); } if(src->subject) { dst->subject = strdup(src->subject); } return GLOBUS_SUCCESS; error: return result; }
globus_result_t globus_xio_stack_copy( globus_xio_stack_t * dst, globus_xio_stack_t src) { globus_i_xio_stack_t * xio_stack_src; globus_i_xio_stack_t * xio_stack_dst; globus_result_t res; GlobusXIOName(globus_xio_stack_push_driver); GlobusXIODebugEnter(); if(dst == NULL) { res = GlobusXIOErrorParameter("dst"); goto err; } if(src == NULL) { res = GlobusXIOErrorParameter("src"); goto err; } xio_stack_src = src; xio_stack_dst = (globus_i_xio_stack_t *) globus_calloc(1, sizeof(globus_i_xio_stack_t)); /* check for memory alloc failure */ if(xio_stack_dst == NULL) { res = GlobusXIOErrorMemory("xio_stack_dst"); goto err; } xio_stack_dst->size = xio_stack_src->size; xio_stack_dst->driver_stack = globus_list_copy( xio_stack_src->driver_stack); *dst = xio_stack_dst; GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
/************************************************************************ * stack functions ***********************************************************************/ globus_result_t globus_xio_stack_init( globus_xio_stack_t * stack, globus_xio_attr_t stack_attr) { globus_i_xio_stack_t * xio_stack; GlobusXIOName(globus_xio_stack_init); GlobusXIODebugEnter(); if(stack == NULL) { GlobusXIODebugExitWithError(); return GlobusXIOErrorParameter("stack"); } xio_stack = globus_malloc(sizeof(globus_i_xio_stack_t)); memset(xio_stack, '\0', sizeof(globus_i_xio_stack_t)); *stack = xio_stack; GlobusXIODebugExit(); return GLOBUS_SUCCESS; }
globus_result_t globus_xio_stack_destroy( globus_xio_stack_t stack) { globus_result_t res; GlobusXIOName(globus_xio_stack_destroy); GlobusXIODebugEnter(); if(stack == NULL) { res = GlobusXIOErrorParameter("stack"); goto err; } globus_list_free(stack->driver_stack); globus_free(stack); GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
globus_result_t globus_xio_attr_init( globus_xio_attr_t * attr) { globus_result_t res; globus_i_xio_attr_t * xio_attr; GlobusXIOName(globus_xio_attr_init); GlobusXIODebugEnter(); if(attr == NULL) { res = GlobusXIOErrorParameter("attr"); goto err; } /* allocate the attr */ xio_attr = (globus_i_xio_attr_t *) globus_calloc(sizeof(globus_i_xio_attr_t), 1); if(xio_attr == NULL) { res = GlobusXIOErrorMemory("attr"); goto err; } xio_attr->entry = (globus_i_xio_attr_ent_t *) globus_calloc(sizeof(globus_i_xio_attr_ent_t) * GLOBUS_XIO_ATTR_ARRAY_BASE_SIZE, 1); if(xio_attr->entry == NULL) { *attr = GLOBUS_NULL; globus_free(xio_attr); res = GlobusXIOErrorMemory("attr->entry"); goto err; } /* zero it out */ xio_attr->max = GLOBUS_XIO_ATTR_ARRAY_BASE_SIZE; xio_attr->space = GLOBUS_CALLBACK_GLOBAL_SPACE; globus_mutex_lock(&globus_i_xio_mutex); { globus_list_insert(&globus_i_xio_outstanding_attrs_list, xio_attr); } globus_mutex_unlock(&globus_i_xio_mutex); *attr = xio_attr; GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
globus_result_t globus_xio_data_descriptor_cntl( globus_xio_data_descriptor_t data_desc, globus_xio_driver_t driver, int cmd, ...) { globus_result_t res; globus_i_xio_op_t * op; va_list ap; GlobusXIOName(globus_xio_data_descriptor_cntl); GlobusXIODebugEnter(); if(data_desc == NULL) { res = GlobusXIOErrorParameter("data_desc"); goto err; } op = (globus_i_xio_op_t *) data_desc; # ifdef HAVE_STDARG_H { va_start(ap, cmd); } # else { va_start(ap); } # endif res = globus_i_xio_driver_dd_cntl(op, driver, op->type, cmd, ap); va_end(ap); if(res != GLOBUS_SUCCESS) { goto err; } GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
globus_result_t globus_xio_attr_cntl( globus_xio_attr_t user_attr, globus_xio_driver_t driver, int cmd, ...) { va_list ap; globus_result_t res; globus_i_xio_attr_t * attr; GlobusXIOName(globus_xio_attr_cntl); GlobusXIODebugEnter(); if(user_attr == NULL) { res = GlobusXIOErrorParameter("user_attr"); goto err; } attr = user_attr; # ifdef HAVE_STDARG_H { va_start(ap, cmd); } # else { va_start(ap); } # endif res = globus_i_xio_driver_attr_cntl(attr, driver, cmd, ap); if(res != GLOBUS_SUCCESS) { va_end(ap); goto err; } va_end(ap); GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
globus_result_t globus_xio_stack_push_driver( globus_xio_stack_t stack, globus_xio_driver_t driver) { globus_xio_driver_t p_d; globus_i_xio_stack_t * xio_stack; globus_result_t res = GLOBUS_SUCCESS; GlobusXIOName(globus_xio_stack_push_driver); GlobusXIODebugEnter(); if(stack == NULL) { res = GlobusXIOErrorParameter("stack"); goto err; } if(driver == NULL) { res = GlobusXIOErrorParameter("driver"); goto err; } xio_stack = (globus_i_xio_stack_t *) stack; /* if in the transport position and has a push stack */ if(driver->push_driver_func != NULL && xio_stack->pushing_driver != driver) { p_d = xio_stack->pushing_driver; xio_stack->pushing_driver = driver; res = driver->push_driver_func(driver, xio_stack); xio_stack->pushing_driver = p_d; if(res != GLOBUS_SUCCESS) { goto err; } } /* if a transport driver position */ else if(xio_stack->size == 0) { if(driver->transport_open_func == NULL) { res = GlobusXIOErrorInvalidDriver( _XIOSL("open function not defined")); goto err; } else { xio_stack->size++; globus_list_insert(&xio_stack->driver_stack, driver); } } else if(driver->transport_open_func != NULL) { res = GlobusXIOErrorInvalidDriver( _XIOSL("transport can only be at bottom of stack")); goto err; } else { xio_stack->size++; globus_list_insert(&xio_stack->driver_stack, driver); } GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
globus_result_t globus_xio_data_descriptor_copy( globus_xio_data_descriptor_t * dst, globus_xio_data_descriptor_t src) { globus_i_xio_op_t * op_src; globus_i_xio_op_t * op_dst; globus_result_t res; int ctr; int ctr2; GlobusXIOName(globus_xio_data_descriptor_copy); GlobusXIODebugEnter(); if(dst == NULL) { res = GlobusXIOErrorParameter("dst"); goto err; } if(src == NULL) { res = GlobusXIOErrorParameter("src"); goto err; } op_src = src; res = globus_xio_data_descriptor_init(&op_dst, op_src->_op_handle); if(res != GLOBUS_SUCCESS) { goto err; } for(ctr = 0; ctr < op_src->stack_size; ctr++) { res = op_dst->_op_context->entry[ctr].driver->attr_copy_func( &op_dst->entry[ctr].dd, op_src->entry[ctr].dd); if(res != GLOBUS_SUCCESS) { for(ctr2 = 0; ctr2 < ctr; ctr2++) { /* ignore result here */ op_dst->_op_context->entry[ctr].driver->attr_destroy_func( op_dst->entry[ctr].dd); } globus_memory_push_node(&op_dst->_op_context->op_memory, op_dst); goto err_destroy_op; } } *dst = op_dst; GlobusXIODebugExit(); return GLOBUS_SUCCESS; err_destroy_op: globus_xio_data_descriptor_destroy(op_dst); err: GlobusXIODebugExitWithError(); return res; }
globus_result_t globus_xio_data_descriptor_destroy( globus_xio_data_descriptor_t data_desc) { globus_result_t res = GLOBUS_SUCCESS; globus_i_xio_op_t * op; globus_i_xio_handle_t * handle; globus_bool_t destroy_handle = GLOBUS_FALSE; globus_list_t * node; GlobusXIOName(globus_xio_data_descriptor_destroy); GlobusXIODebugEnter(); if(data_desc == NULL) { res = GlobusXIOErrorParameter("data_desc"); goto err; } op = (globus_i_xio_op_t *) data_desc; globus_mutex_lock(&globus_i_xio_mutex); { /* make sure we haven't destroyed it already */ node = globus_list_search(globus_i_xio_outstanding_dds_list, op); if(node) { globus_list_remove(&globus_i_xio_outstanding_dds_list, node); } } globus_mutex_unlock(&globus_i_xio_mutex); if(node == NULL) { res = GlobusXIOErrorParameter("data_desc already destroyed"); goto err; } handle = op->_op_handle; globus_mutex_lock(&handle->context->mutex); { GlobusXIOOpDec(op); if(op->ref == 0) { globus_i_xio_op_destroy(op, &destroy_handle); } } globus_mutex_unlock(&handle->context->mutex); if(destroy_handle) { globus_i_xio_handle_destroy(handle); } GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
/** * Modify the state of an HTTP handle * @ingroup globus_i_xio_http_handle * * Modify the state of an HTTP handle. This is called by the XIO driver via * globus_xio_handle_cntl(). * * @param handle * Void pointer to a #globus_i_xio_http_handle_t structure containing * information an HTTP request/response transaction. * @param cmd * Integer value indicating what command will be executed on the handle. * Valid command values are in the set defined by * #globus_xio_http_handle_cmd_t. * @param ap * Variable-length argument list containing any cmd-specific parameters. * * @retval GLOBUS_SUCCESS * The command was sucessfully executed. * @retval GLOBUS_XIO_ERROR_MEMORY * The command failed due to memory constraints. * @retval GLOBUS_XIO_ERROR_PARAMETER * Invalid @a cmd parameter or invlaid value of cmd-specific parameters * in @a ap */ globus_result_t globus_i_xio_http_handle_cntl( void * handle, int cmd, va_list ap) { char * in_header_name; char * in_header_value; globus_result_t result = GLOBUS_SUCCESS; globus_i_xio_http_handle_t * http_handle = handle; char * in_str; char * in_str2; char * save_str; int in_int; GlobusXIOName(globus_i_xio_http_handle_cntl); globus_mutex_lock(&http_handle->mutex); switch (cmd) { case GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HEADER: if (http_handle->target_info.is_client) { result = GlobusXIOErrorParameter("handle"); break; } if (http_handle->send_state != GLOBUS_XIO_HTTP_STATUS_LINE) { result = GlobusXIOErrorParameter("handle"); break; } in_str = va_arg(ap, char *); in_str2 = va_arg(ap, char *); result = globus_i_xio_http_header_info_set_header( &http_handle->response_info.headers, in_str, in_str2); break; case GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_STATUS_CODE: if (http_handle->target_info.is_client) { result = GlobusXIOErrorParameter("handle"); break; } if (http_handle->send_state != GLOBUS_XIO_HTTP_STATUS_LINE) { result = GlobusXIOErrorParameter("handle"); break; } in_int = va_arg(ap, int); if (in_int < 100 || in_int > 599) { result = GlobusXIOErrorParameter("status_code"); break; } http_handle->response_info.status_code = in_int; break; case GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_REASON_PHRASE: if (http_handle->target_info.is_client) { result = GlobusXIOErrorParameter("handle"); break; } if (http_handle->send_state != GLOBUS_XIO_HTTP_STATUS_LINE) { result = GlobusXIOErrorParameter("handle"); break; } in_str = va_arg(ap, char *); if (in_str == NULL) { result = GlobusXIOErrorParameter("reason_phrase"); } save_str = http_handle->response_info.reason_phrase; http_handle->response_info.reason_phrase = globus_libc_strdup(in_str); if (http_handle->response_info.reason_phrase == NULL) { result = GlobusXIOErrorMemory("reason_phrase"); break; } if (save_str) { globus_libc_free(save_str); } break; case GLOBUS_XIO_HTTP_HANDLE_SET_RESPONSE_HTTP_VERSION: if (http_handle->target_info.is_client) { result = GlobusXIOErrorParameter("handle"); break; } if (http_handle->send_state != GLOBUS_XIO_HTTP_STATUS_LINE) { result = GlobusXIOErrorParameter("handle"); break; } http_handle->response_info.http_version = va_arg(ap, globus_xio_http_version_t); break; case GLOBUS_XIO_HTTP_HANDLE_SET_END_OF_ENTITY: result = globus_i_xio_http_set_end_of_entity(http_handle); break; case GLOBUS_XIO_HTTP_HANDLE_SET_REQUEST_HEADER: in_header_name = va_arg(ap, char *); if (in_header_name == NULL) { result = GlobusXIOErrorParameter("name"); break; } in_header_value = va_arg(ap, char *); if (in_header_value == NULL) { result = GlobusXIOErrorParameter("value"); break; } result = globus_i_xio_http_header_info_set_header( &http_handle->request_info.headers, in_header_name, in_header_value); break; default: result = GlobusXIOErrorParameter("cmd"); break; } globus_mutex_unlock(&http_handle->mutex); return result; }
globus_result_t globus_xio_attr_copy( globus_xio_attr_t * dst, globus_xio_attr_t src) { globus_i_xio_attr_t * xio_attr_src; globus_i_xio_attr_t * xio_attr_dst; globus_result_t res; int ctr; int ctr2; GlobusXIOName(globus_xio_attr_copy); GlobusXIODebugEnter(); if(dst == NULL) { res = GlobusXIOErrorParameter("dst"); goto err; } if(src == NULL) { res = GlobusXIOErrorParameter("src"); goto err; } xio_attr_src = src; xio_attr_dst = (globus_i_xio_attr_t *) globus_malloc(sizeof(globus_i_xio_attr_t)); /* check for memory alloc failure */ if(xio_attr_dst == NULL) { res = GlobusXIOErrorMemory("xio_attr_dst"); goto err; } memset(xio_attr_dst, 0, sizeof(globus_i_xio_attr_t)); xio_attr_dst->entry = (globus_i_xio_attr_ent_t *) globus_malloc(sizeof(globus_i_xio_attr_ent_t) * GLOBUS_XIO_ATTR_ARRAY_BASE_SIZE); if(xio_attr_dst->entry == NULL) { globus_free(xio_attr_dst); res = GlobusXIOErrorMemory("xio_attr_dst->entry"); goto err; } memset(xio_attr_dst->entry, 0, sizeof(globus_i_xio_attr_ent_t) * GLOBUS_XIO_ATTR_ARRAY_BASE_SIZE); /* copy all general attrs */ xio_attr_dst->max = xio_attr_src->max; xio_attr_dst->ndx = xio_attr_src->ndx; xio_attr_dst->space = xio_attr_src->space; globus_callback_space_reference(xio_attr_dst->space); xio_attr_dst->open_timeout_cb = xio_attr_src->open_timeout_cb; xio_attr_dst->open_timeout_period = xio_attr_src->open_timeout_period; xio_attr_dst->read_timeout_cb = xio_attr_src->read_timeout_cb; xio_attr_dst->read_timeout_period = xio_attr_src->read_timeout_period; xio_attr_dst->write_timeout_cb = xio_attr_src->write_timeout_cb; xio_attr_dst->write_timeout_period = xio_attr_src->write_timeout_period; xio_attr_dst->close_timeout_cb = xio_attr_src->close_timeout_cb; xio_attr_dst->close_timeout_period = xio_attr_src->close_timeout_period; xio_attr_dst->accept_timeout_cb = xio_attr_src->accept_timeout_cb; xio_attr_dst->accept_timeout_period = xio_attr_src->accept_timeout_period; xio_attr_dst->cancel_open = xio_attr_src->cancel_open; xio_attr_dst->cancel_close = xio_attr_src->cancel_close; xio_attr_dst->cancel_read = xio_attr_src->cancel_read; xio_attr_dst->cancel_write = xio_attr_src->cancel_write; xio_attr_dst->no_cancel = xio_attr_src->no_cancel; xio_attr_dst->timeout_arg = xio_attr_src->timeout_arg; for(ctr = 0; ctr < xio_attr_dst->ndx; ctr++) { xio_attr_dst->entry[ctr].driver = xio_attr_src->entry[ctr].driver; res = xio_attr_dst->entry[ctr].driver->attr_copy_func( &xio_attr_dst->entry[ctr].driver_data, xio_attr_src->entry[ctr].driver_data); if(res != GLOBUS_SUCCESS) { for(ctr2 = 0; ctr2 < ctr; ctr2++) { /* ignore result here */ xio_attr_dst->entry[ctr].driver->attr_destroy_func( xio_attr_dst->entry[ctr].driver_data); } globus_free(xio_attr_dst->entry); globus_free(xio_attr_dst); goto err; } } globus_mutex_lock(&globus_i_xio_mutex); { globus_list_insert(&globus_i_xio_outstanding_attrs_list, xio_attr_dst); } globus_mutex_unlock(&globus_i_xio_mutex); *dst = xio_attr_dst; GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
globus_result_t globus_xio_attr_destroy( globus_xio_attr_t attr) { int ctr; globus_result_t res = GLOBUS_SUCCESS; globus_result_t tmp_res; GlobusXIOName(globus_xio_attr_destroy); GlobusXIODebugEnter(); if(attr == NULL) { res = GlobusXIOErrorParameter("attr"); goto err; } globus_mutex_lock(&globus_i_xio_mutex); { if(!attr->unloaded) { for(ctr = 0; ctr < attr->ndx; ctr++) { GlobusXIODebugPrintf( GLOBUS_XIO_DEBUG_INFO_VERBOSE, (_XIOSL("[globus_xio_attr_destroy]: destroying attr @0x%x " "driver @0x%x, %s\n"), attr, attr->entry[ctr].driver, attr->entry[ctr].driver->name)); /* report the last seen error but be sure to attempt to clean them all */ tmp_res = attr->entry[ctr].driver->attr_destroy_func( attr->entry[ctr].driver_data); if(tmp_res != GLOBUS_SUCCESS) { res = tmp_res; } } globus_list_remove( &globus_i_xio_outstanding_attrs_list, globus_list_search( globus_i_xio_outstanding_attrs_list, attr)); } } globus_mutex_unlock(&globus_i_xio_mutex); if(attr->user_open_sbj) { globus_free(attr->user_open_sbj); } if(attr->user_open_username) { globus_free(attr->user_open_username); } if(attr->user_open_pw) { globus_free(attr->user_open_pw); } globus_callback_space_destroy(attr->space); globus_free(attr->entry); globus_free(attr); if(res != GLOBUS_SUCCESS) { goto err; } GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: GlobusXIODebugExitWithError(); return res; }
/* driver list stuff */ globus_result_t globus_xio_driver_list_from_string( char * driver_string, globus_list_t ** driver_list, globus_hashtable_t * safe_table) { globus_result_t result; globus_bool_t done = GLOBUS_FALSE; globus_bool_t loaded; char * opts; char * ptr; char * driver_str; char * driver_name; char * tmp_str; globus_xio_driver_t driver; globus_list_t * list = NULL; globus_xio_driver_list_ent_t * list_ent; GlobusXIOName(globus_xio_driver_list_from_string); *driver_list = NULL; if(driver_string == NULL) { result = GlobusXIOErrorParameter("driver_string"); goto error_param; } driver_str = globus_libc_strdup(driver_string); tmp_str = driver_str; while(!done) { loaded = GLOBUS_FALSE; driver_name = tmp_str; ptr = strchr(driver_name, ','); if(ptr != NULL) { *ptr = '\0'; tmp_str = ptr+1; } else { done = GLOBUS_TRUE; } opts = strchr(driver_name, ':'); if(opts != NULL) { *opts = '\0'; opts++; /* decode the string */ globus_url_string_hex_decode(opts); } /* check against the safe list */ if(safe_table != NULL) { char * err_str; list_ent = (globus_xio_driver_list_ent_t *) globus_hashtable_lookup(safe_table, driver_name); if(list_ent == NULL) { err_str = globus_common_create_string( "%s driver not whitelisted", driver_name); result = GlobusXIOErrorParameter(err_str); globus_free(err_str); goto error_load; } driver = list_ent->driver; } else { result = globus_xio_driver_load(driver_name, &driver); if(result != GLOBUS_SUCCESS) { goto error_load; } loaded = GLOBUS_TRUE; } list_ent = (globus_xio_driver_list_ent_t *) globus_calloc(1, sizeof(globus_xio_driver_list_ent_t)); list_ent->opts = globus_libc_strdup(opts); list_ent->driver = driver; list_ent->driver_name = globus_libc_strdup(driver_name); list_ent->loaded = loaded; globus_list_insert(&list, list_ent); } globus_free(driver_str); /* reverse list */ while(!globus_list_empty(list)) { globus_list_insert(driver_list, globus_list_first(list)); globus_list_remove(&list, list); } return GLOBUS_SUCCESS; error_load: globus_free(driver_str); while(!globus_list_empty(list)) { list_ent = (globus_xio_driver_list_ent_t *) globus_list_remove(&list, list); if(list_ent->loaded) { globus_xio_driver_unload(list_ent->driver); } globus_free(list_ent->driver_name); if(list_ent->opts != NULL) { globus_free(list_ent->opts); } globus_free(list_ent); } error_param: return result; }
/* 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); }
globus_result_t globus_xio_data_descriptor_init( globus_xio_data_descriptor_t * data_desc, globus_xio_handle_t handle) { globus_result_t res = GLOBUS_SUCCESS; globus_i_xio_op_t * op; globus_i_xio_context_t * context; GlobusXIOName(globus_xio_data_descriptor_init); GlobusXIODebugEnter(); if(data_desc == NULL) { res = GlobusXIOErrorParameter("data_desc"); goto err_parm; } if(handle == NULL) { res = GlobusXIOErrorParameter("handle"); goto err; } context = handle->context; globus_mutex_lock(&context->mutex); { GlobusXIOOperationCreate(op, context); if(op != NULL) { op->type = GLOBUS_XIO_OPERATION_TYPE_DD; handle->ref++; GlobusXIODebugPrintf( GLOBUS_XIO_DEBUG_INFO_VERBOSE, (_XIOSL("[globus_xio_data_descriptor_init] :: handle ref at %d.\n"), handle->ref)); op->_op_handle = handle; op->ref = 1; op->is_user_dd = GLOBUS_TRUE; } else { res = GlobusXIOErrorMemory("xio_dd"); } } globus_mutex_unlock(&context->mutex); if(res != GLOBUS_SUCCESS) { goto err; } *data_desc = op; globus_mutex_lock(&globus_i_xio_mutex); { globus_list_insert(&globus_i_xio_outstanding_dds_list, op); } globus_mutex_unlock(&globus_i_xio_mutex); GlobusXIODebugExit(); return GLOBUS_SUCCESS; err: *data_desc = NULL; err_parm: GlobusXIODebugExitWithError(); return res; }
/** * Modify the state of an HTTP attribute * @ingroup globus_i_xio_http_attr * * Modify the state of an attribute. This is called by the XIO driver via * globus_xio_attr_cntl(). * * @param driver_attr * Void pointer to a #globus_i_xio_http_attr_t structure containing * the attribute's values. * @param cmd * Integer value indicating which attribute will be changed. Valid * commands values are in the set defined by #globus_xio_http_attr_cmd_t * @param ap * Variable-length argument list containing any cmd-specific parameters. * * @retval GLOBUS_SUCCESS * Attribute successfully modified. * @retval GLOBUS_XIO_ERROR_MEMORY * Attribute control failed due to memory constraints. * @retval GLOBUS_XIO_ERROR_PARAMETER * Invalid @a cmd parameter or invalid value for cmd-specific parameters * in @a ap. */ globus_result_t globus_i_xio_http_attr_cntl( void * driver_attr, int cmd, va_list ap) { globus_result_t res = GLOBUS_SUCCESS; globus_i_xio_http_attr_t * attr = driver_attr; char * in_string; char * save_string; globus_xio_http_version_t in_http_version; char * in_header_name; char * in_header_value; char ** out_method; char ** out_uri; globus_xio_http_version_t * out_http_version; globus_hashtable_t * out_headers; int * out_status_code; char ** out_reason_phrase; GlobusXIOName(globus_i_xio_http_attr_cntl); switch (cmd) { case GLOBUS_XIO_HTTP_ATTR_SET_REQUEST_METHOD: save_string = attr->request.method; in_string = va_arg(ap, char *); if (in_string == NULL) { res = GlobusXIOErrorParameter("method"); break; } attr->request.method = globus_libc_strdup(in_string); if (attr->request.method == NULL) { attr->request.method = save_string; res = GlobusXIOErrorMemory("method"); break; } if (save_string != NULL) { globus_libc_free(save_string); } break; case GLOBUS_XIO_HTTP_ATTR_SET_REQUEST_HTTP_VERSION: in_http_version = va_arg(ap, globus_xio_http_version_t); if (in_http_version != GLOBUS_XIO_HTTP_VERSION_1_0 && in_http_version != GLOBUS_XIO_HTTP_VERSION_1_1) { res = GlobusXIOErrorParameter("version"); break; } attr->request.http_version = in_http_version; break; case GLOBUS_XIO_HTTP_ATTR_SET_REQUEST_HEADER: in_header_name = va_arg(ap, char *); if (in_header_name == NULL) { res = GlobusXIOErrorParameter("name"); break; } in_header_value = va_arg(ap, char *); if (in_header_value == NULL) { res = GlobusXIOErrorParameter("value"); break; } res = globus_i_xio_http_header_info_set_header( &attr->request.headers, in_header_name, in_header_value, GLOBUS_FALSE); break; case GLOBUS_XIO_HTTP_ATTR_DELAY_WRITE_HEADER: attr->delay_write_header = 1; break; case GLOBUS_XIO_HTTP_GET_REQUEST: out_method = va_arg(ap, char **); out_uri = va_arg(ap, char **); out_http_version = va_arg(ap, globus_xio_http_version_t *); out_headers = va_arg(ap, globus_hashtable_t *); if (out_method != NULL) { *out_method = attr->request.method; } if (out_uri != NULL) { *out_uri = attr->request.uri; } if (out_http_version != NULL) { *out_http_version = attr->request.http_version; } if (out_headers != NULL) { *out_headers = attr->request.headers.headers; } break; case GLOBUS_XIO_HTTP_GET_RESPONSE: out_status_code = va_arg(ap, int *); out_reason_phrase = va_arg(ap, char **); out_http_version = va_arg(ap, globus_xio_http_version_t *); out_headers = va_arg(ap, globus_hashtable_t *); if (out_status_code != NULL) { *out_status_code = attr->response.status_code; } if (out_reason_phrase != NULL) { *out_reason_phrase = attr->response.reason_phrase; } if (out_http_version != NULL) { *out_http_version = attr->response.http_version; } if (out_headers != NULL) { *out_headers = attr->response.headers.headers; } break; default: res = GlobusXIOErrorParameter("cmd"); } return res; }
static globus_result_t globus_l_xio_test_read_buffer( globus_xio_handle_t handle, globus_byte_t * message, globus_size_t message_size, globus_size_t buffer_size) { globus_size_t offset=0; globus_size_t left = message_size; globus_size_t to_read; globus_size_t nbytes; globus_result_t result = GLOBUS_SUCCESS; globus_byte_t * buffer; GlobusXIOName(globus_l_xio_test_read_buffer); if (buffer_size == 0) { buffer_size = 1024; } buffer = malloc(buffer_size); if (buffer == NULL) { result = GlobusXIOErrorMemory("buffer"); } while ((left > 0) || (result == GLOBUS_SUCCESS)) { nbytes = 0; to_read = (left > buffer_size) ? buffer_size : (left > 0 ? left : buffer_size); result = globus_xio_read( handle, buffer, buffer_size, 1, &nbytes, NULL); if (nbytes > 0) { if (left > 0) { if (memcmp(message+offset, buffer, nbytes) != 0) { fprintf(stderr, "File doesn't match\n"); result = GlobusXIOErrorParameter("buffer"); } left -= nbytes; } else { fprintf(stderr, "File doesn't match\n"); result = GlobusXIOErrorParameter("buffer"); } offset += nbytes; } } if (offset == message_size && http_is_eof(result)) { result = GLOBUS_SUCCESS; } else if (result != GLOBUS_SUCCESS) { fprintf(stderr, "Error reading from http: %s\n", globus_object_printable_to_string(globus_error_peek(result))); fprintf(stderr, "after reading %lu of %lu bytes\n", (unsigned long) offset, (unsigned long) message_size); } return result; }