comparison utils.c @ 5755:dbc61b2840eb libavformat

Add a function ff_url_join for assembling URLs
author mstorsjo
date Fri, 05 Mar 2010 22:31:45 +0000
parents 2e5aecabfb1e
children 8ba33938e06f
comparison
equal deleted inserted replaced
5754:65b77d0674d0 5755:dbc61b2840eb
25 #include "libavutil/avstring.h" 25 #include "libavutil/avstring.h"
26 #include "riff.h" 26 #include "riff.h"
27 #include <sys/time.h> 27 #include <sys/time.h>
28 #include <time.h> 28 #include <time.h>
29 #include <strings.h> 29 #include <strings.h>
30 #include <stdarg.h>
31 #if CONFIG_NETWORK
32 #include "network.h"
33 #endif
30 34
31 #undef NDEBUG 35 #undef NDEBUG
32 #include <assert.h> 36 #include <assert.h>
33 37
34 /** 38 /**
3444 av_log(NULL, AV_LOG_WARNING, "st:%d has too large timebase, reducing\n", s->index); 3448 av_log(NULL, AV_LOG_WARNING, "st:%d has too large timebase, reducing\n", s->index);
3445 3449
3446 if(!s->time_base.num || !s->time_base.den) 3450 if(!s->time_base.num || !s->time_base.den)
3447 s->time_base.num= s->time_base.den= 0; 3451 s->time_base.num= s->time_base.den= 0;
3448 } 3452 }
3453
3454 int ff_url_join(char *str, int size, const char *proto,
3455 const char *authorization, const char *hostname,
3456 int port, const char *fmt, ...)
3457 {
3458 #if CONFIG_NETWORK
3459 struct addrinfo hints, *ai;
3460 #endif
3461
3462 str[0] = '\0';
3463 if (proto)
3464 av_strlcatf(str, size, "%s://", proto);
3465 if (authorization)
3466 av_strlcatf(str, size, "%s@", authorization);
3467 #if CONFIG_NETWORK && defined(AF_INET6)
3468 /* Determine if hostname is a numerical IPv6 address,
3469 * properly escape it within [] in that case. */
3470 memset(&hints, 0, sizeof(hints));
3471 hints.ai_flags = AI_NUMERICHOST;
3472 if (!getaddrinfo(hostname, NULL, &hints, &ai)) {
3473 if (ai->ai_family == AF_INET6) {
3474 av_strlcat(str, "[", size);
3475 av_strlcat(str, hostname, size);
3476 av_strlcat(str, "]", size);
3477 } else {
3478 av_strlcat(str, hostname, size);
3479 }
3480 freeaddrinfo(ai);
3481 } else
3482 #endif
3483 /* Not an IPv6 address, just output the plain string. */
3484 av_strlcat(str, hostname, size);
3485
3486 if (port >= 0)
3487 av_strlcatf(str, size, ":%d", port);
3488 if (fmt) {
3489 va_list vl;
3490 int len = strlen(str);
3491
3492 va_start(vl, fmt);
3493 vsnprintf(str + len, size > len ? size - len : 0, fmt, vl);
3494 va_end(vl);
3495 }
3496 return strlen(str);
3497 }