+
+int __io_url_path(abc_io_t** io, scf_string_t** spath, const char* main, const char* current)
+{
+ scf_string_t* path = scf_string_alloc();
+ if (!path)
+ return -ENOMEM;
+
+ int prefix = -1;
+ int proto;
+ int ret;
+
+ if (main) {
+ if ('.' == main[0] || '/' == main[0]) {
+ prefix = 0;
+ proto = ABC_PROTO_FILE;
+
+ } else if (!strncmp(main, "file://", 7)) {
+ prefix = 7;
+ proto = ABC_PROTO_FILE;
+
+ } else if (!strncmp(main, "http://", 7)) {
+ prefix = 7;
+ proto = ABC_PROTO_HTTP;
+ } else {
+ scf_loge("proto of '%s' NOT support\n", main);
+
+ scf_string_free(path);
+ return -EINVAL;
+ }
+
+ const char* p = main + prefix;
+ const char* p2 = NULL;
+
+ while (*p) {
+ if ('/' == *p)
+ p2 = p;
+ p++;
+ }
+
+ if (!p2)
+ p2 = p;
+
+ ret = scf_string_cat_cstr_len(path, main, (size_t)(p2 - main));
+ if (ret < 0) {
+ scf_string_free(path);
+ return ret;
+ }
+ }
+
+ if (!strncmp(current, "file://", 7)) {
+ prefix = 7;
+ proto = ABC_PROTO_FILE;
+
+ ret = scf_string_copy_cstr(path, current);
+
+ } else if (!strncmp(current, "http://", 7)) {
+ prefix = 7;
+ proto = ABC_PROTO_HTTP;
+
+ ret = scf_string_copy_cstr(path, current);
+ } else {
+ if (prefix < 0) {
+ prefix = 0;
+ proto = ABC_PROTO_FILE;
+
+ } else if ('/' != current[0]) {
+
+ ret = scf_string_cat_cstr_len(path, "/", 1);
+ if (ret < 0) {
+ scf_string_free(path);
+ return ret;
+ }
+ }
+
+ ret = scf_string_cat_cstr(path, current);
+ }
+
+ if (ret < 0) {
+ scf_string_free(path);
+ return ret;
+ }
+
+ *io = abc_io_array[proto];
+ *spath = path;
+ return prefix;
+}