src/flb_upstream.c
/* Create an upstream context using a valid URL (protocol, host and port) */
Create an upstream context using a valid URL (protocol, host and port)
Create an upstream context using a valid URL ( protocol host and port )
struct flb_upstream *flb_upstream_create_url(struct flb_config *config,
                                             const char *url, int flags,
                                             struct flb_tls *tls)
{
    int ret;
    int tmp_port = 0;
    char *prot = NULL;
    char *host = NULL;
    char *port = NULL;
    char *uri = NULL;
    struct flb_upstream *u = NULL;
    ret = flb_utils_url_split(url, &prot, &host, &port, &uri);
    if (ret == -1) {
        flb_error("[upstream] invalid URL: %s", url);
        return NULL;
    }
    if (!prot) {
        flb_error("[upstream] unknown protocol type from URL: %s", url);
        goto out;
    }
    if (!port) {
        if (strcasecmp(prot, "http") == 0) {
            tmp_port = 80;
        }
        else if (strcasecmp(prot, "https") == 0) {
            tmp_port = 443;
            if ((flags & FLB_IO_TLS) == 0) {
                flags |= FLB_IO_TLS;
            }
        }
    }
    else {
        tmp_port = atoi(port);
    }
    if (tmp_port <= 0) {
        flb_error("[upstream] unknown TCP port in URL: %s", url);
        goto out;
    }
    u = flb_upstream_create(config, host, tmp_port, flags, tls);
    if (!u) {
        flb_error("[upstream] error creating context from URL: %s", url);
    }
 out:
    if (prot) {
        flb_free(prot);
    }
    if (host) {
        flb_free(host);
    }
    if (port) {
        flb_free(port);
    }
    if (uri) {
        flb_free(uri);
    }
    return u;
}
struct flb_upstream * flb_upstream_create_url ( struct flb_config * config , const char * url , int flags , struct flb_tls * tls ) { int ret ; int tmp_port = 0 ; char * prot = NULL ; char * host = NULL ; char * port = NULL ; char * uri = NULL ; struct flb_upstream * u = NULL ; ret = flb_utils_url_split ( url , & prot , & host , & port , & uri ) ; if ( ret == -1 ) { flb_error ( " " , url ) ; return NULL ; } if ( ! prot ) { flb_error ( " " , url ) ; goto out ; } if ( ! port ) { if ( strcasecmp ( prot , " " ) == 0 ) { tmp_port = 80 ; } else if ( strcasecmp ( prot , " " ) == 0 ) { tmp_port = 443 ; if ( ( flags & FLB_IO_TLS ) == 0 ) { flags |= FLB_IO_TLS ; } } } else { tmp_port = atoi ( port ) ; } if ( tmp_port <= 0 ) { flb_error ( " " , url ) ; goto out ; } u = flb_upstream_create ( config , host , tmp_port , flags , tls ) ; if ( ! u ) { flb_error ( " " , url ) ; } out : if ( prot ) { flb_free ( prot ) ; } if ( host ) { flb_free ( host ) ; } if ( port ) { flb_free ( port ) ; } if ( uri ) { flb_free ( uri ) ; } return u ; }
Create an upstream context using a valid URL (protocol, host and port)
Create an upstream context using a valid URL ( protocol host and port )
/* Parse and split URL */ /* Manage some default ports */