-/* $Id: gopher.cc,v 1.21 1996/04/09 23:28:33 wessels Exp $ */
+/* $Id: gopher.cc,v 1.22 1996/04/10 03:53:59 wessels Exp $ */
/*
* DEBUG: Section 10 gopher: GOPHER
char *type_id;
char *request;
{
- static char atypebuf[MAX_URL];
+ static char proto[MAX_URL];
static char hostbuf[MAX_URL];
- char *tmp = NULL;
int t;
- atypebuf[0] = hostbuf[0] = '\0';
+ proto[0] = hostbuf[0] = '\0';
host[0] = request[0] = '\0';
(*port) = 0;
(*type_id) = 0;
- t = sscanf(url, "%[a-zA-Z]://%[^/]/%c%s", atypebuf, hostbuf,
+ t = sscanf(url, "%[a-zA-Z]://%[^/]/%c%s", proto, hostbuf,
type_id, request);
- if ((t < 2) || strcasecmp(atypebuf, "gopher")) {
+ if ((t < 2) || strcasecmp(proto, "gopher")) {
return -1;
} else if (t == 2) {
(*type_id) = GOPHER_DIRECTORY;
request[0] = '\0';
} else {
/* convert %xx to char */
- tmp = url_convert_hex(request);
- strncpy(request, tmp, MAX_URL);
- safe_free(tmp);
+ (void) url_convert_hex(request, 0);
}
host[0] = '\0';
-/* $Id: url.cc,v 1.6 1996/04/04 01:30:53 wessels Exp $ */
+/* $Id: url.cc,v 1.7 1996/04/10 03:54:00 wessels Exp $ */
/*
* DEBUG: Section 23 url
/* convert %xx in url string to a character
* Allocate a new string and return a pointer to converted string */
-char *url_convert_hex(org_url)
+char *url_convert_hex(org_url, allocate)
char *org_url;
+ int allocate;
{
- int i;
- char temp[MAX_URL], hexstr[MAX_URL];
- static char *url;
-
- url = (char *) xcalloc(1, MAX_URL);
- strncpy(url, org_url, MAX_URL);
-
- i = 0;
- while (i < (int) (strlen(url) - 2)) {
- if (url[i] == '%') {
- /* found %xx, convert it to char */
- strncpy(temp, url, i);
- strncpy(hexstr, url + i + 1, 2);
- hexstr[2] = '\0';
- temp[i] = (char) ((int) strtol(hexstr, (char **) NULL, 16));
- temp[i + 1] = '\0';
- strncat(temp, url + i + 3, MAX_URL);
- strcpy(url, temp);
+ static char *code = "00";
+ char *url = NULL;
+ char *s = NULL;
+ char *t = NULL;
+
+ url = allocate ? (char *) xstrdup(org_url) : org_url;
+
+ for (s=t=url; *(s+2); s++) {
+ if (*s == '%') {
+ *code = *++s;
+ *(code+1) = *++s;
+ *t++ = (char) strtol(code, NULL, 16);
+ } else {
+ *t++ = *s;
}
- i++;
}
-
+ do {
+ *t++ = *s;
+ } while (*s++);
return url;
}