annotate url.c @ 1123:5b69dabe5823

Issues about P3 performance and SSE2 support.
author nickols_k
date Wed, 13 Jun 2001 16:12:14 +0000
parents 647f5781d490
children 3effaac0ddb7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
1 /*
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;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
20 char *ptr1, *ptr2;
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");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
26 exit(1);
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
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
32 Curl->url = (char*)malloc(strlen(url)+1);
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");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
35 exit(1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
36 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
37 strcpy(Curl->url, url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
38
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
39 // extract the protocol
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
40 ptr1 = strstr(url, "://");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
41 if( ptr1==NULL ) {
997
647f5781d490 Modified code for path/filename extraction.
bertrand
parents: 902
diff changeset
42 printf("Not an URL!\n");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
43 return NULL;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
44 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
45 pos1 = ptr1-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
46 Curl->protocol = (char*)malloc(pos1+1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
47 strncpy(Curl->protocol, url, pos1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
48 Curl->protocol[pos1] = '\0';
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
49
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
50 // look if the port is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
51 ptr2 = strstr(ptr1+3, ":");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
52 if( ptr2==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
53 // No port is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
54 // Look if a path is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
55 ptr2 = strstr(ptr1+3, "/");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
56 if( ptr2==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
57 // No path/filename
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
58 // So we have an URL like http://www.hostname.com
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
59 pos2 = strlen(url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
60 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
61 // We have an URL like http://www.hostname.com/file.txt
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
62 pos2 = ptr2-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
63 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
64 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
65 // We have an URL beginning like http://www.hostname.com:1212
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
66 // Get the port number
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
67 Curl->port = atoi(ptr2+1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
68 pos2 = ptr2-url;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
69 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
70 // copy the hostname in the URL container
997
647f5781d490 Modified code for path/filename extraction.
bertrand
parents: 902
diff changeset
71 Curl->hostname = (char*)malloc(pos2-pos1-3+1);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
72 if( Curl->hostname==NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
73 printf("Memory allocation failed!\n");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
74 exit(1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
75 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
76 strncpy(Curl->hostname, ptr1+3, pos2-pos1-3);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
77 Curl->hostname[pos2-pos1-3] = '\0';
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
78
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
79 // Look if a path is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
80 ptr2 = strstr(ptr1+3, "/");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
81 if( ptr2!=NULL ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
82 // A path/filename is given
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
83 // check if it's not a trailing '/'
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
84 if( strlen(ptr2)>1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
85 // copy the path/filename in the URL container
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
86 Curl->file = (char*)malloc(strlen(ptr2)+1);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
87 if( Curl->file==NULL ) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
88 printf("Memory allocation failed!\n");
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
89 exit(1);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
90 }
997
647f5781d490 Modified code for path/filename extraction.
bertrand
parents: 902
diff changeset
91 strcpy(Curl->file, ptr2);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
92 }
869
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
93 }
997
647f5781d490 Modified code for path/filename extraction.
bertrand
parents: 902
diff changeset
94 // 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
95 if( Curl->file==NULL ) {
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
96 Curl->file = (char*)malloc(2);
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
97 if( Curl->file==NULL ) {
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
98 printf("Memory allocation failed!\n");
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
99 exit(1);
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
100 }
e350849ff400 Url given without a filename/path get the filename/path '/'
bertrand
parents: 840
diff changeset
101 strcpy(Curl->file, "/");
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
102 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
103
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
104 return Curl;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
105 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
106
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
107 void
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
108 url_free(URL_t* url) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
109 if(url) return;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
110 if(url->url) free(url->url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
111 if(url->protocol) free(url->protocol);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
112 if(url->hostname) free(url->hostname);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
113 if(url->file) free(url->file);
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
114 if(url->username) free(url->username);
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
115 if(url->password) free(url->password);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
116 free(url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
117 }