Blame src/url.h

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