3 #include "etherboot.h" /* for arptable */
7 * Parse a URL and deduce a struct protocol *, a struct sockaddr_in
8 * and a char *filename.
10 * We accept URLs of the form
12 * [protocol://[host][:port]/]path/to/file
14 * Returns 1 for success, 0 for failure (e.g. unknown protocol).
17 int parse_url ( char *url, struct protocol **proto,
18 struct sockaddr_in *server, char **filename ) {
20 char *protocol = NULL;
25 DBG ( "URL parsing \"%s\"\n", url );
27 /* If no protocol is present, the whole URL will be a filename */
30 /* Search for a protocol delimiter. If found, parse out the
31 * host and port parts of the URL, inserting NULs to terminate
32 * the different sections.
34 for ( p = url ; *p ; p++ ) {
35 if ( memcmp ( p, "://", 3 ) != 0 )
38 /* URL has an explicit protocol */
44 /* Search for port and file delimiters */
60 DBG ( "URL protocol \"%s\" host \"%s\" port \"%s\" file \"%s\"\n",
61 protocol ? protocol : "(default)", host ? host : "(default)",
62 port ? port : "(default)", *filename );
64 /* Identify the protocol */
65 *proto = identify_protocol ( protocol );
67 DBG ( "URL unknown protocol \"%s\"\n",
68 protocol ? protocol : "(default)" );
72 /* Identify the host */
73 server->sin_addr = arptable[ARP_SERVER].ipaddr;
74 if ( host && host[0] ) {
75 if ( ! resolv ( &server->sin_addr, host ) ) {
76 DBG ( "URL unknown host \"%s\"\n", host );
81 /* Identify the port */
82 server->sin_port = (*proto)->default_port;
83 if ( port && port[0] ) {
84 server->sin_port = strtoul ( port, NULL, 10 );
90 /* Fill back in the original URL */
92 (*filename)[-1] = '/';