annotate libmpdemux/url.c @ 3041:6b31e121f36a

Changed the some functions prototypes for the network streaming.
author bertrand
date Tue, 20 Nov 2001 22:17:16 +0000
parents 9fad4017ec37
children fb9de639ed30
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");
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
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");
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 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");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
74 return NULL;
833
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");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
89 return NULL;
833
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");
1631
09284c9c2b49 exit() -> return NULL
arpi
parents: 1530
diff changeset
99 return NULL;
869
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
3040
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
107 URL_t *
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
108 url_copy(URL_t* url) {
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
109 URL_t *dup_url;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
110
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
111 if( url==NULL ) return NULL;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
112 dup_url = (URL_t*)malloc(sizeof(URL_t));
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
113 if( dup_url==NULL ) {
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
114 printf("Memory allocation failed!\n");
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
115 return NULL;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
116 }
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
117 memcpy( dup_url, url, sizeof(URL_t) );
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
118
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
119 return dup_url;
9fad4017ec37 Added a function to copy URL.
bertrand
parents: 2310
diff changeset
120 }
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
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
123 void
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
124 url_free(URL_t* url) {
1530
3effaac0ddb7 silly bug fixed - thanx Szekeres Istvan <szekeres@webvilag.com>
arpi
parents: 997
diff changeset
125 if(!url) return;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
126 if(url->url) free(url->url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
127 if(url->protocol) free(url->protocol);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
128 if(url->hostname) free(url->hostname);
840
9141234715a2 Added initialisation of URL pointers.
bertrand
parents: 833
diff changeset
129 if(url->file) free(url->file);
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
130 if(url->username) free(url->username);
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 869
diff changeset
131 if(url->password) free(url->password);
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
132 free(url);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
133 }