-int fileio_open(fileio_t *fileio, char *url, enum fileio_access access,
- enum fileio_pri_type pri_type, void *pri_info, enum fileio_sec_type sec_type)
-{
- int retval = ERROR_OK;
- char *resource_identifier = NULL;
-
- /* try to identify file location */
- if ((resource_identifier = strstr(url, "bootp://")) && (resource_identifier == url))
- {
- ERROR("bootp resource location isn't supported yet");
- return ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN;
- }
- else if ((resource_identifier = strstr(url, "tftp://")) && (resource_identifier == url))
- {
- ERROR("tftp resource location isn't supported yet");
- return ERROR_FILEIO_RESOURCE_TYPE_UNKNOWN;
- }
- else
- {
- /* default to local files */
- fileio->location = FILEIO_LOCAL;
- }
-
- fileio->access = access;
- fileio->pri_type = pri_type;
- fileio->sec_type = sec_type;
- fileio->url = strdup(url);
-
- switch (fileio->location)
- {
- case FILEIO_LOCAL:
- retval = fileio_open_local(fileio);
- break;
- default:
- ERROR("BUG: should never get here");
- exit(-1);
- }
-
- if (retval != ERROR_OK)
- return retval;
-
- if (fileio->pri_type == FILEIO_TEXT)
- {
- /* do nothing for now */
- return ERROR_OK;
- }
- else if (fileio->pri_type == FILEIO_IMAGE)
- {
- fileio_image_t *image = malloc(sizeof(fileio_image_t));
- fileio_image_t *image_info = pri_info;
-
- fileio->pri_type_private = image;
- *image = *image_info;
-
- if (fileio->sec_type == FILEIO_PLAIN)
- {
- fileio->sec_type_private = NULL;
- }
- else if (fileio->sec_type == FILEIO_IHEX)
- {
- fileio_ihex_t *fileio_ihex;
-
- if (fileio->access != FILEIO_READ)
- {
- ERROR("can't write/append to a IHEX file");
- snprintf(fileio->error_str, FILEIO_MAX_ERROR_STRING, "can't write/append to a IHEX file");
- fileio_close(fileio);
- return ERROR_FILEIO_OPERATION_FAILED;
- }
-
- fileio_ihex = malloc(sizeof(fileio_ihex_t));
- fileio->sec_type_private = fileio_ihex;
-
- fileio_ihex->position = 0;
- fileio_ihex->raw_size = fileio->size;
-#ifdef FILEIO_BUFFER_COMPLETE_IHEX
- if (fileio_ihex_buffer_complete(fileio) != ERROR_OK)
- {
- fileio_close(fileio);
- return ERROR_FILEIO_OPERATION_FAILED;
- }
-#endif
- }
- }
-