|
@@ -35,6 +35,8 @@
|
35
|
35
|
* @v uri URI
|
36
|
36
|
*/
|
37
|
37
|
static void dump_uri ( struct uri *uri ) {
|
|
38
|
+ if ( ! uri )
|
|
39
|
+ return;
|
38
|
40
|
if ( uri->scheme )
|
39
|
41
|
DBG ( " scheme \"%s\"", uri->scheme );
|
40
|
42
|
if ( uri->opaque )
|
|
@@ -174,12 +176,14 @@ struct uri * parse_uri ( const char *uri_string ) {
|
174
|
176
|
/**
|
175
|
177
|
* Get port from URI
|
176
|
178
|
*
|
177
|
|
- * @v uri URI
|
|
179
|
+ * @v uri URI, or NULL
|
178
|
180
|
* @v default_port Default port to use if none specified in URI
|
179
|
181
|
* @ret port Port
|
180
|
182
|
*/
|
181
|
183
|
unsigned int uri_port ( struct uri *uri, unsigned int default_port ) {
|
182
|
|
- return ( uri->port ? strtoul ( uri->port, NULL, 0 ) : default_port );
|
|
184
|
+ if ( ( ! uri ) || ( ! uri->port ) )
|
|
185
|
+ return default_port;
|
|
186
|
+ return ( strtoul ( uri->port, NULL, 0 ) );
|
183
|
187
|
}
|
184
|
188
|
|
185
|
189
|
/**
|
|
@@ -187,7 +191,7 @@ unsigned int uri_port ( struct uri *uri, unsigned int default_port ) {
|
187
|
191
|
*
|
188
|
192
|
* @v buf Buffer to fill with URI string
|
189
|
193
|
* @v size Size of buffer
|
190
|
|
- * @v uri URI to write into buffer
|
|
194
|
+ * @v uri URI to write into buffer, or NULL
|
191
|
195
|
* @ret len Length of URI string
|
192
|
196
|
*/
|
193
|
197
|
int unparse_uri ( char *buf, size_t size, struct uri *uri ) {
|
|
@@ -197,6 +201,13 @@ int unparse_uri ( char *buf, size_t size, struct uri *uri ) {
|
197
|
201
|
dump_uri ( uri );
|
198
|
202
|
DBG ( "\n" );
|
199
|
203
|
|
|
204
|
+ /* Special-case NULL URI */
|
|
205
|
+ if ( ! uri ) {
|
|
206
|
+ if ( size )
|
|
207
|
+ buf[0] = '\0';
|
|
208
|
+ return 0;
|
|
209
|
+ }
|
|
210
|
+
|
200
|
211
|
/* Special-case opaque URIs */
|
201
|
212
|
if ( uri->opaque ) {
|
202
|
213
|
return ssnprintf ( ( buf + used ), ( size - used ),
|
|
@@ -332,7 +343,7 @@ char * resolve_path ( const char *base_path,
|
332
|
343
|
/**
|
333
|
344
|
* Resolve base+relative URI
|
334
|
345
|
*
|
335
|
|
- * @v base_uri Base URI
|
|
346
|
+ * @v base_uri Base URI, or NULL
|
336
|
347
|
* @v relative_uri Relative URI
|
337
|
348
|
* @ret resolved_uri Resolved URI
|
338
|
349
|
*
|
|
@@ -347,7 +358,7 @@ struct uri * resolve_uri ( struct uri *base_uri,
|
347
|
358
|
struct uri *new_uri;
|
348
|
359
|
|
349
|
360
|
/* If relative URI is absolute, just re-use it */
|
350
|
|
- if ( uri_is_absolute ( relative_uri ) )
|
|
361
|
+ if ( uri_is_absolute ( relative_uri ) || ( ! base_uri ) )
|
351
|
362
|
return uri_get ( relative_uri );
|
352
|
363
|
|
353
|
364
|
/* Mangle URI */
|