gmni

a gemini line mode client
git clone https://git.clttr.info/gmni.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

escape.h (9553B)


      1 #ifndef ESCAPE_H
      2 #define ESCAPE_H
      3 /***************************************************************************
      4  *                                  _   _ ____  _
      5  *  Project                     ___| | | |  _ \| |
      6  *                             / __| | | | |_) | |
      7  *                            | (__| |_| |  _ <| |___
      8  *                             \___|\___/|_| \_\_____|
      9  *
     10  * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
     11  *
     12  * This software is licensed as described in the file COPYING, which
     13  * you should have received as part of this distribution. The terms
     14  * are also available at https://curl.haxx.se/docs/copyright.html.
     15  *
     16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     17  * copies of the Software, and permit persons to whom the Software is
     18  * furnished to do so, under the terms of the COPYING file.
     19  *
     20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     21  * KIND, either express or implied.
     22  *
     23  ***************************************************************************/
     24 
     25 /* from curl.h */
     26 typedef enum {
     27   CURLE_OK = 0,
     28   CURLE_UNSUPPORTED_PROTOCOL,    /* 1 */
     29   CURLE_FAILED_INIT,             /* 2 */
     30   CURLE_URL_MALFORMAT,           /* 3 */
     31   CURLE_NOT_BUILT_IN,            /* 4 - [was obsoleted in August 2007 for
     32                                     7.17.0, reused in April 2011 for 7.21.5] */
     33   CURLE_COULDNT_RESOLVE_PROXY,   /* 5 */
     34   CURLE_COULDNT_RESOLVE_HOST,    /* 6 */
     35   CURLE_COULDNT_CONNECT,         /* 7 */
     36   CURLE_WEIRD_SERVER_REPLY,      /* 8 */
     37   CURLE_REMOTE_ACCESS_DENIED,    /* 9 a service was denied by the server
     38                                     due to lack of access - when login fails
     39                                     this is not returned. */
     40   CURLE_FTP_ACCEPT_FAILED,       /* 10 - [was obsoleted in April 2006 for
     41                                     7.15.4, reused in Dec 2011 for 7.24.0]*/
     42   CURLE_FTP_WEIRD_PASS_REPLY,    /* 11 */
     43   CURLE_FTP_ACCEPT_TIMEOUT,      /* 12 - timeout occurred accepting server
     44                                     [was obsoleted in August 2007 for 7.17.0,
     45                                     reused in Dec 2011 for 7.24.0]*/
     46   CURLE_FTP_WEIRD_PASV_REPLY,    /* 13 */
     47   CURLE_FTP_WEIRD_227_FORMAT,    /* 14 */
     48   CURLE_FTP_CANT_GET_HOST,       /* 15 */
     49   CURLE_HTTP2,                   /* 16 - A problem in the http2 framing layer.
     50                                     [was obsoleted in August 2007 for 7.17.0,
     51                                     reused in July 2014 for 7.38.0] */
     52   CURLE_FTP_COULDNT_SET_TYPE,    /* 17 */
     53   CURLE_PARTIAL_FILE,            /* 18 */
     54   CURLE_FTP_COULDNT_RETR_FILE,   /* 19 */
     55   CURLE_OBSOLETE20,              /* 20 - NOT USED */
     56   CURLE_QUOTE_ERROR,             /* 21 - quote command failure */
     57   CURLE_HTTP_RETURNED_ERROR,     /* 22 */
     58   CURLE_WRITE_ERROR,             /* 23 */
     59   CURLE_OBSOLETE24,              /* 24 - NOT USED */
     60   CURLE_UPLOAD_FAILED,           /* 25 - failed upload "command" */
     61   CURLE_READ_ERROR,              /* 26 - couldn't open/read from file */
     62   CURLE_OUT_OF_MEMORY,           /* 27 */
     63   /* Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error
     64            instead of a memory allocation error if CURL_DOES_CONVERSIONS
     65            is defined
     66   */
     67   CURLE_OPERATION_TIMEDOUT,      /* 28 - the timeout time was reached */
     68   CURLE_OBSOLETE29,              /* 29 - NOT USED */
     69   CURLE_FTP_PORT_FAILED,         /* 30 - FTP PORT operation failed */
     70   CURLE_FTP_COULDNT_USE_REST,    /* 31 - the REST command failed */
     71   CURLE_OBSOLETE32,              /* 32 - NOT USED */
     72   CURLE_RANGE_ERROR,             /* 33 - RANGE "command" didn't work */
     73   CURLE_HTTP_POST_ERROR,         /* 34 */
     74   CURLE_SSL_CONNECT_ERROR,       /* 35 - wrong when connecting with SSL */
     75   CURLE_BAD_DOWNLOAD_RESUME,     /* 36 - couldn't resume download */
     76   CURLE_FILE_COULDNT_READ_FILE,  /* 37 */
     77   CURLE_LDAP_CANNOT_BIND,        /* 38 */
     78   CURLE_LDAP_SEARCH_FAILED,      /* 39 */
     79   CURLE_OBSOLETE40,              /* 40 - NOT USED */
     80   CURLE_FUNCTION_NOT_FOUND,      /* 41 - NOT USED starting with 7.53.0 */
     81   CURLE_ABORTED_BY_CALLBACK,     /* 42 */
     82   CURLE_BAD_FUNCTION_ARGUMENT,   /* 43 */
     83   CURLE_OBSOLETE44,              /* 44 - NOT USED */
     84   CURLE_INTERFACE_FAILED,        /* 45 - CURLOPT_INTERFACE failed */
     85   CURLE_OBSOLETE46,              /* 46 - NOT USED */
     86   CURLE_TOO_MANY_REDIRECTS,      /* 47 - catch endless re-direct loops */
     87   CURLE_UNKNOWN_OPTION,          /* 48 - User specified an unknown option */
     88   CURLE_TELNET_OPTION_SYNTAX,    /* 49 - Malformed telnet option */
     89   CURLE_OBSOLETE50,              /* 50 - NOT USED */
     90   CURLE_OBSOLETE51,              /* 51 - NOT USED */
     91   CURLE_GOT_NOTHING,             /* 52 - when this is a specific error */
     92   CURLE_SSL_ENGINE_NOTFOUND,     /* 53 - SSL crypto engine not found */
     93   CURLE_SSL_ENGINE_SETFAILED,    /* 54 - can not set SSL crypto engine as
     94                                     default */
     95   CURLE_SEND_ERROR,              /* 55 - failed sending network data */
     96   CURLE_RECV_ERROR,              /* 56 - failure in receiving network data */
     97   CURLE_OBSOLETE57,              /* 57 - NOT IN USE */
     98   CURLE_SSL_CERTPROBLEM,         /* 58 - problem with the local certificate */
     99   CURLE_SSL_CIPHER,              /* 59 - couldn't use specified cipher */
    100   CURLE_PEER_FAILED_VERIFICATION, /* 60 - peer's certificate or fingerprint
    101                                      wasn't verified fine */
    102   CURLE_BAD_CONTENT_ENCODING,    /* 61 - Unrecognized/bad encoding */
    103   CURLE_LDAP_INVALID_URL,        /* 62 - Invalid LDAP URL */
    104   CURLE_FILESIZE_EXCEEDED,       /* 63 - Maximum file size exceeded */
    105   CURLE_USE_SSL_FAILED,          /* 64 - Requested FTP SSL level failed */
    106   CURLE_SEND_FAIL_REWIND,        /* 65 - Sending the data requires a rewind
    107                                     that failed */
    108   CURLE_SSL_ENGINE_INITFAILED,   /* 66 - failed to initialise ENGINE */
    109   CURLE_LOGIN_DENIED,            /* 67 - user, password or similar was not
    110                                     accepted and we failed to login */
    111   CURLE_TFTP_NOTFOUND,           /* 68 - file not found on server */
    112   CURLE_TFTP_PERM,               /* 69 - permission problem on server */
    113   CURLE_REMOTE_DISK_FULL,        /* 70 - out of disk space on server */
    114   CURLE_TFTP_ILLEGAL,            /* 71 - Illegal TFTP operation */
    115   CURLE_TFTP_UNKNOWNID,          /* 72 - Unknown transfer ID */
    116   CURLE_REMOTE_FILE_EXISTS,      /* 73 - File already exists */
    117   CURLE_TFTP_NOSUCHUSER,         /* 74 - No such user */
    118   CURLE_CONV_FAILED,             /* 75 - conversion failed */
    119   CURLE_CONV_REQD,               /* 76 - caller must register conversion
    120                                     callbacks using curl_easy_setopt options
    121                                     CURLOPT_CONV_FROM_NETWORK_FUNCTION,
    122                                     CURLOPT_CONV_TO_NETWORK_FUNCTION, and
    123                                     CURLOPT_CONV_FROM_UTF8_FUNCTION */
    124   CURLE_SSL_CACERT_BADFILE,      /* 77 - could not load CACERT file, missing
    125                                     or wrong format */
    126   CURLE_REMOTE_FILE_NOT_FOUND,   /* 78 - remote file not found */
    127   CURLE_SSH,                     /* 79 - error from the SSH layer, somewhat
    128                                     generic so the error message will be of
    129                                     interest when this has happened */
    130 
    131   CURLE_SSL_SHUTDOWN_FAILED,     /* 80 - Failed to shut down the SSL
    132                                     connection */
    133   CURLE_AGAIN,                   /* 81 - socket is not ready for send/recv,
    134                                     wait till it's ready and try again (Added
    135                                     in 7.18.2) */
    136   CURLE_SSL_CRL_BADFILE,         /* 82 - could not load CRL file, missing or
    137                                     wrong format (Added in 7.19.0) */
    138   CURLE_SSL_ISSUER_ERROR,        /* 83 - Issuer check failed.  (Added in
    139                                     7.19.0) */
    140   CURLE_FTP_PRET_FAILED,         /* 84 - a PRET command failed */
    141   CURLE_RTSP_CSEQ_ERROR,         /* 85 - mismatch of RTSP CSeq numbers */
    142   CURLE_RTSP_SESSION_ERROR,      /* 86 - mismatch of RTSP Session Ids */
    143   CURLE_FTP_BAD_FILE_LIST,       /* 87 - unable to parse FTP file list */
    144   CURLE_CHUNK_FAILED,            /* 88 - chunk callback reported error */
    145   CURLE_NO_CONNECTION_AVAILABLE, /* 89 - No connection available, the
    146                                     session will be queued */
    147   CURLE_SSL_PINNEDPUBKEYNOTMATCH, /* 90 - specified pinned public key did not
    148                                      match */
    149   CURLE_SSL_INVALIDCERTSTATUS,   /* 91 - invalid certificate status */
    150   CURLE_HTTP2_STREAM,            /* 92 - stream error in HTTP/2 framing layer
    151                                     */
    152   CURLE_RECURSIVE_API_CALL,      /* 93 - an api function was called from
    153                                     inside a callback */
    154   CURL_LAST /* never use! */
    155 } CURLcode;
    156 
    157 /* Escape and unescape URL encoding in strings. The functions return a new
    158  * allocated string or NULL if an error occurred.  */
    159 
    160 bool Curl_isunreserved(unsigned char in);
    161 CURLcode Curl_urldecode(const char *string, size_t length,
    162                         char **ostring, size_t *olen,
    163                         bool reject_crlf);
    164 
    165 char *curl_easy_escape(const char *string, int length);
    166 
    167 char *curl_escape(const char *string, int length);
    168 
    169 char *curl_easy_unescape(const char *string,
    170 		int length, int *outlength);
    171 
    172 char *curl_unescape(const char *string, int length);
    173 
    174 
    175 #endif /* HEADER_CURL_ESCAPE_H */