1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/*
* Copyright (C) 1995, 1996, 1997, 1998
* Civil Engineering in Cyberspace
* Copyright (C) 1997, 1998
* Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <uri_util.h>
#include <uri.h>
#include <uri_private.h>
#include <uri_schemes.h>
#include <uri_scheme_generic.h>
char* uri_parse_gopher_path(uri_t* object, char* p);
/*
* Information from draft-murali-url-gopher.txt
*/
int uri_scheme_gopher_parse(uri_t* object)
{
char* p = object->pool;
p = uri_parse_scheme(object, p, 0);
p = uri_parse_netloc(object, p, URI_SCHEME_GENERIC_PARSE_SKIP_AUTH);
static_alloc(&object->gopher_tmp, &object->gopher_tmp_size, strlen(p));
strcpy(object->gopher_tmp, uri_unescape(p));
if(uri_parse_gopher_path(object, object->gopher_tmp))
return 0;
else
return -1;
}
char* uri_parse_gopher_path(uri_t* object, char* p)
{
char* start = p;
char c = *start;
char buf[2];
/*
* Type
*/
#define GOPHER_TYPES "0123456789+IgT"
if(!*start) c = '1';
if(!strchr(GOPHER_TYPES, c)) {
uri_error(object->pool_size, _("%c is not a know gopher type (" GOPHER_TYPES ") in uri %s"), c, p);
return 0;
}
buf[0] = c; buf[1] = '\0';
{
int f = mode.flag;
mode.flag |= URI_MODE_FIELD_MALLOC;
uri_gopher_type_set(object, buf);
mode.flag = f;
}
if(!*start) return p;
start++;
/*
* Selector
*/
object->gopher_selector = start;
{
/*
* Search
*/
char* tmp;
if((tmp = strchr(start, '\t'))) {
*tmp = '\0';
start = tmp + 1;
object->gopher_search = start;
/*
* String
*/
if((tmp = strchr(start, '\t'))) {
*tmp = '\0';
start = tmp + 1;
object->gopher_string = start;
}
}
}
return p;
}
int uri_scheme_gopher_cannonicalize(uri_t* original, uri_t* object, char* tmp, int* tmp_sizep)
{
int tmp_size = 0;
{
int size;
#define normalize(w,s) \
if(object->w) \
{ \
size = cannonicalize_component(object, object->w, tmp + tmp_size, (s), #s); \
if(size < 0) \
return URI_NOT_CANNONICAL; \
object->w = tmp + tmp_size; \
tmp_size += size; \
}
/*
* WARNING! keep the following call in the same order as in the
* original string.
*/
normalize(scheme, SPEC_SCHEME);
normalize(host, SPEC_NETLOC);
normalize(gopher_type, SPEC_PARAMS);
normalize(gopher_selector, SPEC_PARAMS);
normalize(gopher_search, SPEC_PARAMS);
normalize(gopher_string, SPEC_PARAMS);
}
if(object->host) strlower(object->host, -1);
*tmp_sizep = tmp_size;
return URI_CANNONICAL;
}
void uri_scheme_gopher_string(uri_t* object, char** stringp, int* string_sizep, int flags)
{
char* string;
static_alloc(stringp, string_sizep, uri_estimate_pool_size(object));
string = *stringp;
string[0] = '\0';
if(object->scheme && object->host) {
sprintf(string, "%s://%s/", object->scheme, uri_netloc(object));
} else {
uri_error(0, _("gopher_string: unexpected empty field"));
return;
}
strcat(string, uri_path(object));
}
void uri_scheme_gopher_path_set(uri_t* object, char* value)
{
if(value) {
static_alloc(&object->gopher_tmp, &object->gopher_tmp_size, strlen(value));
strcpy(object->gopher_tmp, uri_unescape(value));
}
uri_gopher_type_set(object, 0);
uri_gopher_selector_set(object, 0);
uri_gopher_search_set(object, 0);
uri_gopher_string_set(object, 0);
if(value)
uri_parse_gopher_path(object, object->gopher_tmp);
}
char* uri_scheme_gopher_path(uri_t* object)
{
static char* string = 0;
static int string_size = 0;
{
int length = 5 +
(object->gopher_selector ? strlen(object->gopher_selector) : 0) +
(object->gopher_search ? (strlen(object->gopher_search) + 4) : 0) +
(object->gopher_string ? (strlen(object->gopher_string) + 4) : 0);
static_alloc(&string, &string_size, length);
}
string[0] = '\0';
if(object->gopher_type == 0) {
uri_error(0, _("gopher_string: unexpected empty type"));
return 0;
}
if(object->gopher_selector || object->gopher_type[0] != '1') {
strcat(string, object->gopher_type);
if(object->gopher_selector) strcat(string, object->gopher_selector);
if(object->gopher_search) {
strcat(string, "%09");
strcat(string, object->gopher_search);
}
if(object->gopher_string) {
strcat(string, "%09");
strcat(string, object->gopher_string);
}
}
return string;
}
uri_scheme_desc_t uri_scheme_gopher_desc = {
/* parse */ uri_scheme_gopher_parse,
/* cannonicalize */ uri_scheme_gopher_cannonicalize,
/* string */ uri_scheme_gopher_string,
/* scheme */ uri_scheme_generic_scheme,
/* host */ uri_scheme_generic_host,
/* port */ uri_scheme_generic_port,
/* path */ uri_scheme_gopher_path,
/* params */ uri_scheme_generic_params,
/* query */ uri_scheme_generic_query,
/* frag */ uri_scheme_generic_frag,
/* user */ uri_scheme_generic_user,
/* passwd */ uri_scheme_generic_passwd,
/* netloc */ uri_scheme_generic_netloc,
/* passwd */ uri_scheme_generic_auth,
/* all_path */ uri_scheme_generic_all_path,
/* scheme_set */ uri_scheme_generic_scheme_set,
/* host_set */ uri_scheme_generic_host_set,
/* port_set */ uri_scheme_generic_port_set,
/* path_set */ uri_scheme_gopher_path_set,
/* params_set */ uri_scheme_generic_params_set,
/* query_set */ uri_scheme_generic_query_set,
/* frag_set */ uri_scheme_generic_frag_set,
/* user_set */ uri_scheme_generic_user_set,
/* passwd_set */ uri_scheme_generic_passwd_set,
/* specs */ uri_scheme_generic_specs,
/* port_int */ -1,
/* port_char */ 0
};
char* uri_gopher_type(uri_t* object) { return uri_user(object); }
char* uri_gopher_selector(uri_t* object) { return uri_params(object); }
char* uri_gopher_search(uri_t* object) { return uri_query(object); }
char* uri_gopher_string(uri_t* object) { return uri_frag(object); }
void uri_gopher_type_set(uri_t* object, char* value) { uri_user_set(object, value); }
void uri_gopher_selector_set(uri_t* object, char* value) { uri_params_set(object, value); }
void uri_gopher_search_set(uri_t* object, char* value) { uri_query_set(object, value); }
void uri_gopher_string_set(uri_t* object, char* value) { uri_frag_set(object, value); }
|