annotate libmpdemux/url.c @ 4597:4ba62f7d04c6

yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
author arpi
date Sat, 09 Feb 2002 01:25:21 +0000
parents 639b3b47b138
children d2a7fcfeec6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
1 /*
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
2 * URL Helper
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
4 * (C) 2001, MPlayer team.
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
5 *
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
6 * TODO:
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
7 * Extract the username/password if present
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
8 */
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
9
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
10 #include <string.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
11 #include <stdlib.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
12 #include <stdio.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
13
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
14 #include "url.h"
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
15
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
16 URL_t*
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
17 url_new(char* url) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
18 int pos1, pos2;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
19 URL_t* Curl;
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3040
diff changeset
20 char *ptr1, *ptr2, *ptr3;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
21
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
22 // Create the URL container
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
23 Curl = (URL_t*)malloc(sizeof(URL_t));
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
24 if( Curl==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
25 printf("Memory allocation failed!\n");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
26 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
27 }
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
28 // Initialisation of the URL container members
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
29 memset( Curl, 0, sizeof(URL_t) );
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
30
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
31 // Copy the url in the URL container
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3496
diff changeset
32 Curl->url = strdup(url);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
33 if( Curl->url==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
34 printf("Memory allocation failed!\n");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
35 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
36 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
37
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
38 // extract the protocol
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
39 ptr1 = strstr(url, "://");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
40 if( ptr1==NULL ) {
997
647f5781d490 Modified code for path/filename extraction.
bertrand
parents: 902
diff changeset
41 printf("Not an URL!\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
42 return NULL;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
43 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
44 pos1 = ptr1-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
45 Curl->protocol = (char*)malloc(pos1+1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
46 strncpy(Curl->protocol, url, pos1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
47 Curl->protocol[pos1] = '\0';
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
48
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
49 // look if the port is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
50 ptr2 = strstr(ptr1+3, ":");
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3040
diff changeset
51 // If the : is after the first / it isn't the port
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3040
diff changeset
52 ptr3 = strstr(ptr1+3, "/");
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3040
diff changeset
53 if(ptr3 && ptr3 - ptr2 < 0) ptr2 = NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
54 if( ptr2==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
55 // No port is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
56 // Look if a path is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
57 ptr2 = strstr(ptr1+3, "/");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
58 if( ptr2==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
59 // No path/filename
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
60 // So we have an URL like http://www.hostname.com
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
61 pos2 = strlen(url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
62 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
63 // We have an URL like http://www.hostname.com/file.txt
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
64 pos2 = ptr2-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
65 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
66 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
67 // We have an URL beginning like http://www.hostname.com:1212
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
68 // Get the port number
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
69 Curl->port = atoi(ptr2+1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
70 pos2 = ptr2-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
71 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
72 // copy the hostname in the URL container
997
647f5781d490 Modified code for path/filename extraction.
bertrand
parents: 902
diff changeset
73 Curl->hostname = (char*)malloc(pos2-pos1-3+1);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
74 if( Curl->hostname==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
75 printf("Memory allocation failed!\n");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
76 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
77 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
78 strncpy(Curl->hostname, ptr1+3, pos2-pos1-3);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
79 Curl->hostname[pos2-pos1-3] = '\0';
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
80
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
81 // Look if a path is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
82 ptr2 = strstr(ptr1+3, "/");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
83 if( ptr2!=NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
84 // A path/filename is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
85 // check if it's not a trailing '/'
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
86 if( strlen(ptr2)>1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
87 // copy the path/filename in the URL container
3612
a1522fa7728a x = malloc(strlen(s) + c) ... strcpy(x, s)
pl
parents: 3496
diff changeset
88 Curl->file = strdup(ptr2);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
89 if( Curl->file==NULL ) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
90 printf("Memory allocation failed!\n");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
91 return NULL;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
92 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
93 }
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
94 }
997
647f5781d490 Modified code for path/filename extraction.
bertrand
parents: 902
diff changeset
95 // Check if a filenme was given or set, else set it with '/'
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
96 if( Curl->file==NULL ) {
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
97 Curl->file = (char*)malloc(2);
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
98 if( Curl->file==NULL ) {
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
99 printf("Memory allocation failed!\n");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
100 return NULL;
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
101 }
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
102 strcpy(Curl->file, "/");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
103 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
104
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
105 return Curl;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
106 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
107
3040
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
108 URL_t *
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
109 url_copy(URL_t* url) {
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
110 URL_t *dup_url;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
111
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
112 if( url==NULL ) return NULL;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
113 dup_url = (URL_t*)malloc(sizeof(URL_t));
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
114 if( dup_url==NULL ) {
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
115 printf("Memory allocation failed!\n");
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
116 return NULL;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
117 }
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
118 memcpy( dup_url, url, sizeof(URL_t) );
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
119
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
120 return dup_url;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
121 }
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
122
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
123
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
124 void
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
125 url_free(URL_t* url) {
1530
3effaac0ddb7 silly bug fixed - thanx Szekeres Istvan <szekeres@webvilag.com>
arpi
parents: 997
diff changeset
126 if(!url) return;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
127 if(url->url) free(url->url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
128 if(url->protocol) free(url->protocol);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
129 if(url->hostname) free(url->hostname);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
130 if(url->file) free(url->file);
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
131 if(url->username) free(url->username);
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
132 if(url->password) free(url->password);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
133 free(url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
134 }
3496
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
135
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
136
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
137 /* Replace escape sequences in an URL (or a part of an URL) */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
138 /* works like strcpy(), but without return argument */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
139 /* unescape_url_string comes from ASFRecorder */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
140 void
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
141 url_unescape_string(char *outbuf, char *inbuf)
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
142 {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
143 unsigned char c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
144 do {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
145 c = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
146 if (c == '%') {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
147 unsigned char c1 = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
148 unsigned char c2 = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
149 if ( ((c1>='0' && c1<='9') || (c1>='A' && c1<='F')) &&
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
150 ((c2>='0' && c2<='9') || (c2>='A' && c2<='F')) ) {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
151 if (c1>='0' && c1<='9') c1-='0';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
152 else c1-='A';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
153 if (c2>='0' && c2<='9') c2-='0';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
154 else c2-='A';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
155 c = (c1<<4) + c2;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
156 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
157 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
158 *outbuf++ = c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
159 } while (c != '\0');
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
160 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
161
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
162 /* Replace specific characters in the URL string by an escape sequence */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
163 /* works like strcpy(), but without return argument */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
164 /* escape_url_string comes from ASFRecorder */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
165 void
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
166 url_escape_string(char *outbuf, char *inbuf) {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
167 unsigned char c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
168 do {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
169 c = *inbuf++;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
170 if( (c >= 'A' && c <= 'Z') ||
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
171 (c >= 'a' && c <= 'z') ||
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
172 (c >= '0' && c <= '9') ||
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
173 (c >= 0x7f) || /* fareast languages(Chinese, Korean, Japanese) */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
174 c=='-' || c=='_' || c=='.' || c=='!' || c=='~' || /* mark characters */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
175 c=='*' || c=='\'' || c=='(' || c==')' || c=='%' || /* do not touch escape character */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
176 c==';' || c=='/' || c=='?' || c==':' || c=='@' || /* reserved characters */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
177 c=='&' || c=='=' || c=='+' || c=='$' || c==',' || /* see RFC 2396 */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
178 c=='\0' ) {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
179 *outbuf++ = c;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
180 } else {
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
181 /* all others will be escaped */
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
182 unsigned char c1 = ((c & 0xf0) >> 4);
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
183 unsigned char c2 = (c & 0x0f);
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
184 if (c1 < 10) c1+='0';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
185 else c1+='A';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
186 if (c2 < 10) c2+='0';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
187 else c2+='A';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
188 *outbuf++ = '%';
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
189 *outbuf++ = c1;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
190 *outbuf++ = c2;
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
191 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
192 } while (c != '\0');
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
193 }
5c8a533dfa09 Added 2 functions to escape/unescape the url as described in the RFC 2396.
bertrand
parents: 3494
diff changeset
194
4119
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
195 #ifdef __URL_DEBUG
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
196 void
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
197 url_debug(URL_t *url) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
198 if( url==NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
199 printf("URL pointer NULL\n");
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
200 return;
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
201 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
202 if( url->url!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
203 printf("url=%s\n", url->url );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
204 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
205 if( url->protocol!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
206 printf("protocol=%s\n", url->protocol );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
207 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
208 if( url->hostname!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
209 printf("hostname=%s\n", url->hostname );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
210 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
211 printf("port=%d\n", url->port );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
212 if( url->file!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
213 printf("file=%s\n", url->file );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
214 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
215 if( url->username!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
216 printf("username=%s\n", url->username );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
217 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
218 if( url->password!=NULL ) {
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
219 printf("password=%s\n", url->password );
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
220 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
221 }
639b3b47b138 Added a debug function to print the struct's variables.
bertrand
parents: 3612
diff changeset
222 #endif //__URL_DEBUG