示例#1
0
om_http_response_ptr om_net_do_http_post(const char *url, const char *post_data) {
	om_net_mock_vars_var->last_post_data = om_string_copy(post_data);
	
	om_http_response_ptr resp = om_malloc(sizeof(om_http_response));
	resp->status_code = om_net_mock_vars_var->do_http_post_result->status_code;
	resp->result = om_string_copy(om_net_mock_vars_var->do_http_post_result->result);
	return resp;
}
示例#2
0
om_http_response_ptr om_net_do_http_get_to_file_output_stream(const char *url, 
															  om_file_output_stream_ptr ostream, 
															  void (*call_back)(void *callback_data, om_http_response_ptr response, om_uint32 bytes_total, om_uint32 bytes_downloaded), 
															  void *callback_data) {
	om_net_mock_vars_var->last_input_stream_passed = ostream;
	om_net_mock_vars_var->last_get_url_passed = om_string_copy(url);
	
	om_http_response_ptr resp = om_malloc(sizeof(om_http_response));
	resp->status_code = om_net_mock_vars_var->do_http_get_result->status_code;
	resp->result = om_string_copy(om_net_mock_vars_var->do_http_get_result->result);
	
	return resp;
}
示例#3
0
char * om_string_implode(om_list_ptr list, const char sep) {

	int items = om_list_count(list);
	char separ[] = {sep,'\0'};
	char *ret=OM_NULL;
	char *t=OM_NULL;
	
	for( int i=0; i<items; i++ ) {
		char *ptr = om_string_copy( om_list_get(list,i) );
		
		if(ret==OM_NULL) {
			ret=ptr;
		} else {
			t=ret;
			ret = om_string_append(t,ptr);
			om_free(t);
            om_free(ptr);
			if( ret==OM_NULL ) {
				return OM_NULL;
            }
		}
		
		if( i<items-1 ) {
			t=ret;
			ret = om_string_append(t,separ);
			om_free(t);
			if( ret==OM_NULL ) {
				return OM_NULL;
            }
		}
	}
	

	return ret;
}
示例#4
0
void om_error_set(om_error_code code, const char * message) {
	om_error_set_code(code);
	if( last_message!=OM_NULL ) {
		om_free(last_message);
		last_message=OM_NULL;
	}
	if( om_last_error_code != OM_ERR_MALLOC )
		last_message = om_string_copy(message);
}
示例#5
0
文件: zip.c 项目: MOconcepts/OpenMEAP
int __om_unzip_makedir (om_unzip_archive_ptr archive, const char *rootExportPath, char *newdir) {
	
	char *buffer = om_string_copy(newdir);
	if( buffer==OM_NULL ) {
		return UNZ_INTERNALERROR;
	}
	char *p;
	int len = (int)strlen(newdir);
	
	if (len <= 0)
		return 0;
	
	// prefix with the location where we want to create the dir structure
	if( buffer[0]==OM_FS_FILE_SEP ) {
		p = om_string_append(rootExportPath,buffer);
	} else {
		p = om_string_format("%s%c%s",rootExportPath,OM_FS_FILE_SEP,buffer);
	}
	om_free(buffer);
	buffer = p;
	p = OM_NULL;
	
	// if the path ended with a '/',
	// then take that off
	if (buffer[len-1] == '/') {
		buffer[len-1] = '\0';
	}
	if (__om_unzip_mymkdir(archive,buffer) == 0) {
		om_free(buffer);
		return 1;
    }
	
	p = buffer+1;
	while (1) {
		char hold;
		
		// we shouldn't need to create the rootExportPath
		if( strcmp(rootExportPath,buffer)==0 )
			break;
		
		while(*p && *p != '\\' && *p != '/')
			p++;
		hold = *p;
		*p = 0;
		if ( (__om_unzip_mymkdir(archive,buffer) == -1) && (errno == ENOENT) ) {
			__om_unzip_append_error(archive,om_string_format("couldn't create directory %s\n",buffer));
			om_free(buffer);
			return 0;
        }
		if ( hold == 0 )
			break;
		*p++ = hold;
    }
	om_free(buffer);
	return 1;
}
示例#6
0
om_dict_ptr om_dict_from_query_string(const char *queryString) {
    
    om_list_ptr keyValPairs = om_string_explode(queryString,'&');
    om_dict_ptr ret = om_dict_new(5);
    ret->release_func=om_dict_release_default_func;
    int c = om_list_count(keyValPairs);
    for( int i=0; i<c; i++ ) {
        char * val = om_list_get(keyValPairs,i);
        om_list_ptr keyVal = om_string_explode( val, '=' );
        if( om_list_count(keyVal)==2 ) {
           om_dict_put( ret, om_string_copy(om_list_get(keyVal,0)), om_string_copy(om_list_get(keyVal,1)) );
        } else if( om_list_count(keyVal)==1 ) {
           om_dict_put( ret, om_string_copy(om_list_get(keyVal,0)), "" ); 
        }
        om_list_release(keyVal);
    }
    om_list_release(keyValPairs);
    return ret;
}
示例#7
0
char * om_string_toupper(const char *str_in) {
	char *str = om_string_copy(str_in);
	int i;	
	for (i = 0; str[i] != '\0'; ++i) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			str[i] = str[i] - ('a'-'A');	
		} 
 	}
	return str;
}
示例#8
0
char * om_mock_prefs_get(const om_prefs_ptr prefs, const char *key) {
	char *val = (char*)om_dict_get((om_dict_ptr)prefs->device_data,key);
	if( val==OM_NULL )
		return OM_NULL;
	char *ret = om_string_copy(val);
	if( ret==OM_NULL ) {
		om_error_set(OM_ERR_MALLOC,"Could not malloc() for string in om_prefs_get()");
		return OM_NULL;
	}
	return ret;
}
示例#9
0
char * om_string_format(const char *formatting, ...) {
	char *str = om_malloc(OM_STRING_FORMAT_LIMIT+1);
	if( str==OM_NULL )
		return OM_NULL;
	va_list ap;
	va_start(ap,formatting);
	vsnprintf(str, OM_STRING_FORMAT_LIMIT, formatting, ap);
	va_end(ap);
	char *ret = om_string_copy(str);
	om_free(str);
	if( ret==OM_NULL )
		return OM_NULL;
	return ret;
}
示例#10
0
char * om_mock_props_get(om_props_ptr props, const char *key) {
	char * ptr = om_dict_get(props->device_data,key);
	if( ptr==OM_NULL )
		return ptr;
	return om_string_copy(ptr);
}
示例#11
0
om_bool om_mock_prefs_set(const om_prefs_ptr prefs, const char *key, const char *value) {
	// the device implementation will have to copy these
	return om_dict_put((om_prefs_ptr)prefs->device_data,om_string_copy(key),om_string_copy(value))!=OM_NULL ? OM_TRUE : OM_FALSE;
}