unichar_t *u_GFileNormalize(unichar_t *name) { unichar_t *pt, *base, *ppt; if ( (pt = uc_strstr(name,"://"))!=NULL ) { base = u_strchr(pt+3,'/'); if ( base==NULL ) return( name ); ++base; } else if ( *name=='/' ) base = name+1; else base = name; for ( pt=base; *pt!='\0'; ) { if ( *pt=='/' ) u_strcpy(pt,pt+1); else if ( uc_strncmp(pt,"./",2)==0 ) u_strcpy(pt,pt+2); else if ( uc_strncmp(pt,"../",2)==0 ) { for ( ppt=pt-2; ppt>=base && *ppt!='/'; --ppt ); ++ppt; if ( ppt>=base ) { u_strcpy(ppt,pt+3); pt = ppt; } else pt += 3; } else { while ( *pt!='/' && *pt!='\0' ) ++pt; if ( *pt == '/' ) ++pt; } } return( name ); }
int u_GFileIsAbsolute(const unichar_t *file) { if ( *file=='/' ) return( true ); if ( uc_strstr(file,"://")!=NULL ) return( true ); return( false ); }
char *_GIO_decomposeURL(const unichar_t *uri) { unichar_t *pt; // file:///path/to.something, or /path/to/something pt = uc_strstr(uri, "://"); if (pt == NULL) { return cu_copy(uri); } pt += 3; return cu_copy(pt); }
int u_GFileIsAbsolute(const unichar_t *file) { #if defined(__MINGW32__) if( (file[1]==':') && (('a'<=file[0] && file[0]<='z') || ('A'<=file[0] && file[0]<='Z')) ) return ( true ); #else if ( *file=='/' ) return( true ); #endif if ( uc_strstr(file,"://")!=NULL ) return( true ); return( false ); }
char *_GIO_decomposeURL(const unichar_t *url,char **host, int *port, char **username, char **password) { unichar_t *pt, *pt2, *upt, *ppt; char *path; char proto[40]; /* ftp://[user[:password]@]ftpserver[:port]/url-path */ *username = NULL; *password = NULL; *port = -1; pt = uc_strstr(url,"://"); if ( pt==NULL ) { *host = NULL; return( cu_copy(url)); } cu_strncpy(proto,url,(size_t)(pt-url)<sizeof(proto)?(size_t)(pt-url):sizeof(proto)); pt += 3; pt2 = u_strchr(pt,'/'); if ( pt2==NULL ) { pt2 = pt+u_strlen(pt); path = copy("/"); } else { path = cu_copy(pt2); } upt = u_strchr(pt,'@'); if ( upt!=NULL && upt<pt2 ) { ppt = u_strchr(pt,':'); if ( ppt==NULL ) *username = cu_copyn(pt,upt-pt); else { *username = cu_copyn(pt,ppt-pt); *password = cu_copyn(ppt+1,upt-ppt-1); } pt = upt+1; } ppt = u_strchr(pt,':'); if ( ppt!=NULL && ppt<pt2 ) { char *temp = cu_copyn(ppt+1,pt2-ppt-1), *end; *port = strtol(temp,&end,10); if ( *end!='\0' ) *port = -2; free(temp); pt2 = ppt; } *host = cu_copyn(pt,pt2-pt); if ( *username ) *password = GIO_PasswordCache(proto,*host,*username,*password); return( path ); }
static void GIOdispatch(GIOControl *gc, enum giofuncs gf) { unichar_t *temp, *pt, *tpt; int i; gc->gf = gf; if ( _GIO_stdfuncs.useragent == NULL ) _GIO_stdfuncs.useragent = copy("*****@*****.**"); temp = _GIO_translateURL(gc->path,gf); if ( temp!=NULL ) { if ( gc->origpath==NULL ) gc->origpath = gc->path; else free(gc->path); gc->path = temp; } if ( gc->topath!=NULL ) { temp = _GIO_translateURL(gc->topath,gf); if ( temp!=NULL ) { free(gc->topath); gc->topath = temp; } if ( gf==gf_renamefile ) { if (( pt = uc_strstr(gc->path,"://"))== NULL ) pt = gc->path; else { pt=u_strchr(pt+3,'/'); if ( pt==NULL ) pt = gc->path+u_strlen(gc->path); } if (( tpt = uc_strstr(gc->topath,"://"))== NULL ) tpt = gc->topath; else { tpt=u_strchr(tpt+3,'/'); if ( tpt==NULL ) tpt = gc->topath+u_strlen(gc->topath); } if ( tpt-gc->topath!=pt-gc->path || u_strnmatch(gc->path,gc->topath,pt-gc->path)!=0 ) { _GIO_reporterror(gc,EXDEV); return; } } } pt = uc_strstr(gc->path,"://"); if ( pt!=NULL ) { for ( i=0; i<plen; ++i ) if ( u_strnmatch(protocols[i].proto,gc->path,pt-gc->path)==0 ) break; if ( i>=plen && !AddProtocol(gc->path,pt-gc->path) ) { gc->protocol_index = -2; gc->return_code = 501; gc->error = err501; uc_strcpy(gc->status,"No support for browsing: "); u_strncpy(gc->status+u_strlen(gc->status), gc->path, pt-gc->path ); gc->done = true; (gc->receiveerror)(gc); return; } gc->protocol_index = i; if ( !protocols[i].dothread ) (protocols[i].dispatcher)(gc); else { #ifndef HAVE_PTHREAD_H gc->return_code = 501; gc->error = err501; uc_strcpy(gc->status,"No support for protocol"); gc->done = true; (gc->receiveerror)(gc); return; #else static pthread_cond_t initcond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t initmutex = PTHREAD_MUTEX_INITIALIZER; /* could put stuff here to queue functions if we get too many */ /* threads, or perhaps even a thread pool */ uc_strcpy(gc->status,"Queued"); gc->threaddata = (struct gio_threaddata *) malloc(sizeof(struct gio_threaddata)); gc->threaddata->mutex = initmutex; gc->threaddata->cond = initcond; if ( _GIO_stdfuncs.gdraw_sync_thread!=NULL ) (_GIO_stdfuncs.gdraw_sync_thread)(NULL,NULL,NULL); pthread_create(&gc->threaddata->thread,NULL, (ptread_startfunc_t *) (protocols[i].dispatcher), gc); #endif } } else { gc->protocol_index = -1; _GIO_localDispatch(gc); } }
char * GIODecomposeURL (const uint32_t *url, char **host, int *port, char **username, char **password) { uint32_t *pt, *pt2, *upt, *ppt; char *path; char proto[40]; /* ftp://[user[:password]@]ftpserver[:port]/url-path */ *username = NULL; *password = NULL; *port = -1; pt = uc_strstr (url, "://"); if (pt == NULL) { *host = NULL; return (x_u32_to_u8 (u32_force_valid (url))); } cu_strncpy (proto, url, pt - url < sizeof (proto) ? pt - url : sizeof (proto)); pt += 3; pt2 = u32_strchr (pt, '/'); if (pt2 == NULL) { pt2 = pt + u32_strlen (pt); path = xstrdup ("/"); } else { path = x_u32_to_u8 (u32_force_valid (pt2)); } upt = u32_strchr (pt, '@'); if (upt != NULL && upt < pt2) { ppt = u32_strchr (pt, ':'); if (ppt == NULL) *username = x_u32_to_u8 (x_gc_u32_strmbndup (pt, upt - pt)); else { *username = x_u32_to_u8 (x_gc_u32_strmbndup (pt, ppt - pt)); *password = x_u32_to_u8 (x_gc_u32_strmbndup (ppt + 1, upt - ppt - 1)); } pt = upt + 1; } ppt = u32_strchr (pt, ':'); if (ppt != NULL && ppt < pt2) { char *temp = x_u32_to_u8 (x_gc_u32_strmbndup (ppt + 1, pt2 - ppt - 1)); char *end; *port = strtol (temp, &end, 10); if (*end != '\0') *port = -2; free (temp); pt2 = ppt; } *host = x_u32_to_u8 (x_gc_u32_strmbndup (pt, pt2 - pt)); if (*username) *password = GIO_PasswordCache (proto, *host, *username, *password); return (path); }