Blame src/url.h

Packit Service a2489d
/*
Packit Service a2489d
 * lftp - file transfer program
Packit Service a2489d
 *
Packit Service a2489d
 * Copyright (c) 1996-2017 by Alexander V. Lukyanov (lav@yars.free.net)
Packit Service a2489d
 *
Packit Service a2489d
 * This program is free software; you can redistribute it and/or modify
Packit Service a2489d
 * it under the terms of the GNU General Public License as published by
Packit Service a2489d
 * the Free Software Foundation; either version 3 of the License, or
Packit Service a2489d
 * (at your option) any later version.
Packit Service a2489d
 *
Packit Service a2489d
 * This program is distributed in the hope that it will be useful,
Packit Service a2489d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2489d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service a2489d
 * GNU General Public License for more details.
Packit Service a2489d
 *
Packit Service a2489d
 * You should have received a copy of the GNU General Public License
Packit Service a2489d
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service a2489d
 */
Packit Service a2489d
Packit Service a2489d
#ifndef URL_H
Packit Service a2489d
#define URL_H
Packit Service a2489d
Packit Service a2489d
#include "xstring.h"
Packit Service a2489d
Packit Service a2489d
class ParsedURL
Packit Service a2489d
{
Packit Service a2489d
public:
Packit Service a2489d
   xstring_c proto;
Packit Service a2489d
   xstring_c user;
Packit Service a2489d
   xstring_c pass;
Packit Service a2489d
   xstring_c host;
Packit Service a2489d
   xstring_c port;
Packit Service a2489d
   xstring path;
Packit Service a2489d
Packit Service a2489d
   xstring_c orig_url;
Packit Service a2489d
Packit Service a2489d
   ParsedURL() {}
Packit Service a2489d
   ParsedURL(const char *url,bool proto_required=false,bool use_rfc1738=true);
Packit Service a2489d
   void parse(const char *url,bool proto_required=false,bool use_rfc1738=true);
Packit Service a2489d
   ~ParsedURL();
Packit Service a2489d
Packit Service a2489d
   xstring& CombineTo(xstring &buf,const char *home=0,bool use_rfc1738=true) const;
Packit Service a2489d
   const char *CombineTo(xstring_c &buf,const char *home=0,bool use_rfc1738=true) const {
Packit Service a2489d
      xstring tmp; tmp.move_here(buf);
Packit Service a2489d
      return buf.move_here(CombineTo(tmp,home,use_rfc1738));
Packit Service a2489d
   }
Packit Service a2489d
   // returns allocated memory
Packit Service a2489d
   char *Combine(const char *home=0,bool use_rfc1738=true);
Packit Service a2489d
};
Packit Service a2489d
Packit Service a2489d
# define URL_UNSAFE " <>\"'%{}|\\^[]`"
Packit Service a2489d
# define URL_PATH_UNSAFE URL_UNSAFE"#;?&+"
Packit Service a2489d
# define URL_HOST_UNSAFE URL_UNSAFE":/"
Packit Service a2489d
# define URL_PORT_UNSAFE URL_UNSAFE"/"
Packit Service a2489d
# define URL_USER_UNSAFE URL_UNSAFE"/:@"
Packit Service a2489d
# define URL_PASS_UNSAFE URL_UNSAFE"/:@"
Packit Service a2489d
class url
Packit Service a2489d
{
Packit Service a2489d
public:
Packit Service a2489d
   char	 *proto;
Packit Service a2489d
   char  *user;
Packit Service a2489d
   char	 *pass;
Packit Service a2489d
   char  *host;
Packit Service a2489d
   char	 *port;
Packit Service a2489d
   char  *path;
Packit Service a2489d
Packit Service a2489d
   url(const char *u);
Packit Service a2489d
   url();
Packit Service a2489d
   ~url();
Packit Service a2489d
Packit Service a2489d
   void SetPath(const char *p,const char *q=URL_PATH_UNSAFE);
Packit Service a2489d
   char *Combine();
Packit Service a2489d
Packit Service a2489d
   // encode unsafe chars as %XY
Packit Service a2489d
   static const xstring& encode(const char *s,int len,const char *unsafe,unsigned flags=0);
Packit Service a2489d
   static const xstring& encode(const xstring &s,const char *unsafe,unsigned flags=0) { return encode(s,s.length(),unsafe,flags); }
Packit Service a2489d
   static const xstring& encode(const char *s,const char *unsafe,unsigned flags=0) { return encode(s,strlen(s),unsafe,flags); }
Packit Service a2489d
   static const xstring& decode(const char *) __attribute__((warn_unused_result));
Packit Service a2489d
Packit Service a2489d
   static bool is_url(const char *p);
Packit Service a2489d
   static int path_index(const char *p);
Packit Service a2489d
   static const char *path_ptr(const char *p);
Packit Service a2489d
   static bool dir_needs_trailing_slash(const char *proto);
Packit Service a2489d
   static bool find_password_pos(const char *url,int *start,int *len);
Packit Service a2489d
   static const char *remove_password(const char *url);
Packit Service a2489d
   static const char *hide_password(const char *url);
Packit Service a2489d
};
Packit Service a2489d
Packit Service a2489d
#endif//URL_H