Remove obsolete file URI support
authorJ. Ali Harlow <ali@juiblex.co.uk>
Wed Jun 22 17:32:44 2016 +0100 (2016-06-22)
changeset 45a166277bc796
parent 44 43ffed8669ce
child 46 360621bc323e
Remove obsolete file URI support
plover/uri-handler.c
     1.1 --- a/plover/uri-handler.c	Wed Jun 22 17:04:28 2016 +0100
     1.2 +++ b/plover/uri-handler.c	Wed Jun 22 17:32:44 2016 +0100
     1.3 @@ -26,13 +26,11 @@
     1.4  #include "plover/plover.h"
     1.5  #include "uri-handler.h"
     1.6  
     1.7 -static GList *open_razor_files;
     1.8 -
     1.9  static gboolean has_valid_scheme(const char *uri)
    1.10  {
    1.11      /*
    1.12 -     * RFC 2396 defines valid schemes as:
    1.13 -     * scheme = alpha *( alpha | digit | "+" | "-" | "." )
    1.14 +     * RFC 3986 defines valid schemes as:
    1.15 +     * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
    1.16       */
    1.17      const char *s;
    1.18      if (!g_ascii_isalpha(*uri))
    1.19 @@ -65,20 +63,13 @@
    1.20  {
    1.21      GFile *file;
    1.22      GFileInfo *info;
    1.23 -    gchar *path;
    1.24      int retval;
    1.25      GError *err=NULL;
    1.26      g_message("uri_mkdir(%s)",uri);
    1.27      file=file_for_uri(uri);
    1.28 -    path=g_file_get_path(file);
    1.29 -    if (path)
    1.30 +    retval=!g_file_make_directory(file,NULL,&err);
    1.31 +    if (retval)
    1.32      {
    1.33 -	retval=razor_file_default_mkdir(path,mode,error);
    1.34 -	g_free(path);
    1.35 -    }
    1.36 -    else if (!g_file_make_directory(file,NULL,&err))
    1.37 -    {
    1.38 -	retval=-1;
    1.39  	if (g_error_matches(err,G_IO_ERROR,G_IO_ERROR_EXISTS))
    1.40  	{
    1.41  	    info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE,
    1.42 @@ -97,8 +88,6 @@
    1.43  	if (err)
    1.44  	    plover_propagate_g_error(error,err);
    1.45      }
    1.46 -    else
    1.47 -	retval=0;
    1.48      g_object_unref(file);
    1.49      return retval;
    1.50  }
    1.51 @@ -106,48 +95,13 @@
    1.52  int uri_unlink(const char *uri,struct razor_error **error)
    1.53  {
    1.54      GFile *file;
    1.55 -    gchar *path;
    1.56      int retval;
    1.57      GError *err=NULL;
    1.58      g_message("uri_unlink(%s)",uri);
    1.59      file=file_for_uri(uri);
    1.60 -    path=g_file_get_path(file);
    1.61 -    if (path)
    1.62 -    {
    1.63 -	retval=razor_file_default_unlink(path,error);
    1.64 -	g_free(path);
    1.65 -    }
    1.66 -    else if (!g_file_delete(file,NULL,&err))
    1.67 -    {
    1.68 +    retval=!g_file_delete(file,NULL,&err);
    1.69 +    if (retval)
    1.70  	plover_propagate_g_error(error,err);
    1.71 -	retval=-1;
    1.72 -    }
    1.73 -    else
    1.74 -	retval=0;
    1.75 -    g_object_unref(file);
    1.76 -    return retval;
    1.77 -}
    1.78 -
    1.79 -int uri_open(const char *uri,int flags,mode_t mode,struct razor_error **error)
    1.80 -{
    1.81 -    GFile *file;
    1.82 -    gchar *path;
    1.83 -    int retval;
    1.84 -    GError *err=NULL;
    1.85 -    g_message("uri_open(%s)",uri);
    1.86 -    file=file_for_uri(uri);
    1.87 -    path=g_file_get_path(file);
    1.88 -    if (path)
    1.89 -    {
    1.90 -	retval=razor_file_default_open(path,flags,mode,error);
    1.91 -	g_free(path);
    1.92 -    }
    1.93 -    else
    1.94 -    {
    1.95 -	razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED,
    1.96 -	  uri,"File is not local");
    1.97 -	retval=-1;
    1.98 -    }
    1.99      g_object_unref(file);
   1.100      return retval;
   1.101  }
   1.102 @@ -156,25 +110,14 @@
   1.103    struct razor_error **error)
   1.104  {
   1.105      GFile *src,*dst;
   1.106 -    gchar *src_path,*dst_path;
   1.107      int retval;
   1.108      GError *err=NULL;
   1.109      g_message("uri_move(%s,%s)",src_uri,dst_uri);
   1.110      src=file_for_uri(src_uri);
   1.111      dst=file_for_uri(dst_uri);
   1.112 -    src_path=g_file_get_path(src);
   1.113 -    dst_path=g_file_get_path(dst);
   1.114 -    if (src_path && dst_path)
   1.115 -	retval=razor_file_default_move(src_path,dst_path,error);
   1.116 -    else if (!g_file_move(src,dst,G_FILE_COPY_OVERWRITE,NULL,NULL,NULL,&err))
   1.117 -    {
   1.118 +    retval=!g_file_move(src,dst,G_FILE_COPY_OVERWRITE,NULL,NULL,NULL,&err);
   1.119 +    if (retval)
   1.120  	plover_propagate_g_error(error,err);
   1.121 -	retval=-1;
   1.122 -    }
   1.123 -    else
   1.124 -	retval=0;
   1.125 -    g_free(src_path);
   1.126 -    g_free(dst_path);
   1.127      g_object_unref(src);
   1.128      g_object_unref(dst);
   1.129      return retval;
   1.130 @@ -184,212 +127,107 @@
   1.131    struct razor_error **error)
   1.132  {
   1.133      GFile *file;
   1.134 -    gchar *path;
   1.135      void *addr;
   1.136      char *contents;
   1.137      gsize len;
   1.138      GError *err=NULL;
   1.139      g_message("uri_get_contents(%s)",uri);
   1.140      file=file_for_uri(uri);
   1.141 -    path=g_file_get_path(file);
   1.142 -    if (path)
   1.143 -    {
   1.144 -	g_object_unref(file);
   1.145 -	addr=razor_file_default_get_contents(path,length,private,error);
   1.146 -	if (addr)
   1.147 -	    open_razor_files=g_list_prepend(open_razor_files,addr);
   1.148 -	g_free(path);
   1.149 -    }
   1.150 -    else if (!g_file_load_contents(file,NULL,&contents,&len,NULL,&err))
   1.151 +    if (!g_file_load_contents(file,NULL,&contents,&len,NULL,&err))
   1.152      {
   1.153  	plover_propagate_g_error(error,err);
   1.154 -	g_object_unref(file);
   1.155  	addr=NULL;
   1.156      }
   1.157      else
   1.158      {
   1.159 -	g_object_unref(file);
   1.160  	addr=contents;
   1.161  	if (length)
   1.162  	    *length=len;
   1.163      }
   1.164 +    g_object_unref(file);
   1.165      return addr;
   1.166  }
   1.167  
   1.168  static int uri_free_contents(void *addr,size_t length)
   1.169  {
   1.170 -    int retval;
   1.171 -    GList *lnk;
   1.172      g_message("uri_free_contents(%p)",addr);
   1.173 -    lnk=g_list_find(open_razor_files,addr);
   1.174 -    if (lnk)
   1.175 -    {
   1.176 -	open_razor_files=g_list_delete_link(open_razor_files,lnk);
   1.177 -	retval=razor_file_default_free_contents(addr,length);
   1.178 -    }
   1.179 -    else
   1.180 -    {
   1.181 -	g_free(addr);
   1.182 -	retval=0;
   1.183 -    }
   1.184 -    return retval;
   1.185 +    g_free(addr);
   1.186 +    return 0;
   1.187  }
   1.188  
   1.189  int uri_is_directory(const char *uri,struct razor_error **error)
   1.190  {
   1.191      GFile *file;
   1.192      GFileInfo *info;
   1.193 -    gchar *path;
   1.194      int retval;
   1.195      GError *err=NULL;
   1.196      g_message("uri_is_directory(%s)",uri);
   1.197      file=file_for_uri(uri);
   1.198 -    path=g_file_get_path(file);
   1.199 -    if (path)
   1.200 +    info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE,
   1.201 +      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,&err);
   1.202 +    if (info)
   1.203      {
   1.204 -	retval=razor_file_default_is_directory(path,error);
   1.205 -	g_free(path);
   1.206 +	if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY)
   1.207 +	    retval=1;
   1.208 +	else
   1.209 +	    retval=0;
   1.210 +	g_object_unref(info);
   1.211      }
   1.212      else
   1.213      {
   1.214 -	info=g_file_query_info(file,G_FILE_ATTRIBUTE_STANDARD_TYPE,
   1.215 -	  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,&err);
   1.216 -	if (info)
   1.217 -	{
   1.218 -	    if (g_file_info_get_file_type(info)==G_FILE_TYPE_DIRECTORY)
   1.219 -		retval=1;
   1.220 -	    else
   1.221 -		retval=0;
   1.222 -	    g_object_unref(info);
   1.223 -	}
   1.224 -	else
   1.225 -	{
   1.226 -	    retval=-1;
   1.227 -	    plover_propagate_g_error(error,err);
   1.228 -	}
   1.229 +	retval=-1;
   1.230 +	plover_propagate_g_error(error,err);
   1.231      }
   1.232      g_object_unref(file);
   1.233      return retval;
   1.234  }
   1.235  
   1.236 -char *uri_mkdtemp_near(const char *uri,const char *template,
   1.237 -  struct razor_error **error)
   1.238 -{
   1.239 -    GFile *file;
   1.240 -    gchar *path,*tmpuri;
   1.241 -    char *tmppath,*retval;
   1.242 -    GError *err=NULL;
   1.243 -    g_message("uri_mkdtemp_near(%s)",uri);
   1.244 -    file=file_for_uri(uri);
   1.245 -    path=g_file_get_path(file);
   1.246 -    g_object_unref(file);
   1.247 -    if (path)
   1.248 -    {
   1.249 -	tmppath=razor_file_default_mkdtemp_near(path,template,error);
   1.250 -	g_free(path);
   1.251 -	if (tmppath)
   1.252 -	{
   1.253 -	    file=g_file_new_for_path(tmppath);
   1.254 -	    tmpuri=g_file_get_uri(file);
   1.255 -	    g_object_unref(file);
   1.256 -	    retval=strdup(tmpuri);
   1.257 -	    g_free(tmpuri);
   1.258 -	}
   1.259 -	else
   1.260 -	    retval=NULL;
   1.261 -    }
   1.262 -    else
   1.263 -    {
   1.264 -	razor_set_error(error,RAZOR_GENERAL_ERROR,RAZOR_GENERAL_ERROR_FAILED,
   1.265 -	  uri,"File is not local");
   1.266 -	retval=NULL;
   1.267 -    }
   1.268 -    return retval;
   1.269 -}
   1.270 -
   1.271 -struct uri_dir {
   1.272 -    void *razor_file_default;
   1.273 -    GFileEnumerator *enumerator;
   1.274 -};
   1.275 -
   1.276  void *uri_opendir(const char *uri,struct razor_error **error)
   1.277  {
   1.278      GFile *file;
   1.279 -    gchar *path;
   1.280 -    struct uri_dir *dir;
   1.281 +    GFileEnumerator *dir;
   1.282      GError *err=NULL;
   1.283      g_message("uri_opendir(%s)",uri);
   1.284 -    dir=g_new0(struct uri_dir,1);
   1.285      file=file_for_uri(uri);
   1.286 -    path=g_file_get_path(file);
   1.287 -    if (path)
   1.288 -    {
   1.289 -	dir->razor_file_default=razor_file_default_opendir(path,error);
   1.290 -	if (!dir->razor_file_default)
   1.291 -	{
   1.292 -	    g_free(dir);
   1.293 -	    dir=NULL;
   1.294 -	}
   1.295 -	g_free(path);
   1.296 -    }
   1.297 -    else
   1.298 -    {
   1.299 -	dir->enumerator=g_file_enumerate_children(file,
   1.300 -	  G_FILE_ATTRIBUTE_STANDARD_NAME,G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
   1.301 -	  NULL,&err);
   1.302 -	if (!dir->enumerator)
   1.303 -	{
   1.304 -	    g_free(dir);
   1.305 -	    dir=NULL;
   1.306 -	    plover_propagate_g_error(error,err);
   1.307 -	}
   1.308 -    }
   1.309 +    dir=g_file_enumerate_children(file,G_FILE_ATTRIBUTE_STANDARD_NAME,
   1.310 +      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,NULL,&err);
   1.311 +    if (!dir)
   1.312 +	plover_propagate_g_error(error,err);
   1.313      g_object_unref(file);
   1.314      return dir;
   1.315  }
   1.316  
   1.317  char *uri_readdir(void *dp,struct razor_error **error)
   1.318  {
   1.319 -    struct uri_dir *dir=dp;
   1.320 +    GFileEnumerator *dir=dp;
   1.321      char *name;
   1.322      GError *err=NULL;
   1.323      GFileInfo *info;
   1.324      g_message("uri_readdir(%p)",dp);
   1.325 -    if (dir->razor_file_default)
   1.326 -	name=razor_file_default_readdir(dir->razor_file_default,error);
   1.327 +    info=g_file_enumerator_next_file(dir,NULL,&err);
   1.328 +    if (!info)
   1.329 +    {
   1.330 +	name=NULL;
   1.331 +	plover_propagate_g_error(error,err);
   1.332 +    }
   1.333      else
   1.334      {
   1.335 -	info=g_file_enumerator_next_file(dir->enumerator,NULL,&err);
   1.336 -	if (!info)
   1.337 -	{
   1.338 -	    name=NULL;
   1.339 -	    plover_propagate_g_error(error,err);
   1.340 -	}
   1.341 -	else
   1.342 -	{
   1.343 -	    name=strdup(g_file_info_get_name(info));
   1.344 -	    g_object_unref(info);
   1.345 -	}
   1.346 +	name=strdup(g_file_info_get_name(info));
   1.347 +	g_object_unref(info);
   1.348      }
   1.349      return name;
   1.350  }
   1.351  
   1.352  int uri_closedir(void *dp,struct razor_error **error)
   1.353  {
   1.354 -    struct uri_dir *dir=dp;
   1.355 +    GFileEnumerator *dir=dp;
   1.356      int retval;
   1.357      GError *err=NULL;
   1.358      g_message("uri_closedir(%p)",dp);
   1.359 -    if (dir->razor_file_default)
   1.360 -	retval=razor_file_default_closedir(dir->razor_file_default,error);
   1.361 -    else
   1.362 -    {
   1.363 -	retval=g_file_enumerator_close(dir->enumerator,NULL,&err)?0:-1;
   1.364 -	if (retval)
   1.365 -	    plover_propagate_g_error(error,err);
   1.366 -	g_object_unref(dir->enumerator);
   1.367 -    }
   1.368 -    g_free(dir);
   1.369 +    retval=!g_file_enumerator_close(dir,NULL,&err);
   1.370 +    if (retval)
   1.371 +	plover_propagate_g_error(error,err);
   1.372 +    g_object_unref(dir);
   1.373      return retval;
   1.374  }
   1.375  
   1.376 @@ -403,12 +241,10 @@
   1.377  	uri_vtable.structure_size=sizeof(uri_vtable);
   1.378  	uri_vtable.mkdir=uri_mkdir;
   1.379  	uri_vtable.unlink=uri_unlink;
   1.380 -	uri_vtable.open=uri_open;
   1.381  	uri_vtable.move=uri_move;
   1.382  	uri_vtable.get_contents=uri_get_contents;
   1.383  	uri_vtable.free_contents=uri_free_contents;
   1.384  	uri_vtable.is_directory=uri_is_directory;
   1.385 -	uri_vtable.mkdtemp_near=uri_mkdtemp_near;
   1.386  	uri_vtable.opendir=uri_opendir;
   1.387  	uri_vtable.readdir=uri_readdir;
   1.388  	uri_vtable.closedir=uri_closedir;