{
    "module": "network",
    "depends": [
        "core"
    ],
    "testDir": "../../config.tests",

    "commandline": {
        "assignments": {
            "OPENSSL_PATH": "openssl.prefix"
        },
        "options": {
            "libproxy": "boolean",
            "openssl": { "type": "optionalString", "values": [ "no", "yes", "linked", "runtime" ] },
            "openssl-linked": { "type": "void", "name": "openssl", "value": "linked" },
            "openssl-runtime": { "type": "void", "name": "openssl", "value": "runtime" },
            "sctp": "boolean",
            "securetransport": "boolean",
            "ssl": "boolean",
            "system-proxies": "boolean"
        }
    },

    "libraries": {
        "corewlan": {
            "label": "CoreWLan",
            "export": "",
            "test": "corewlan",
            "sources": [
                "-framework CoreWLAN -framework Foundation"
            ]
        },
        "network": {
            "export": "",
            "sources": [
                { "type": "makeSpec", "spec": "NETWORK" }
            ]
        },
        "libproxy": {
            "label": "libproxy",
            "test": {
                "include": [ "proxy.h" ],
                "main": [
                    "pxProxyFactory *factory = px_proxy_factory_new();",
                    "px_proxy_factory_get_proxies(factory, \"http://qt-project.org\");",
                    "px_proxy_factory_free(factory);"
                ]
            },
            "sources": [
                "-lproxy"
            ]
        },
        "openssl_headers": {
            "label": "OpenSSL Headers",
            "export": "openssl",
            "test": "openssl",
            "sources": [
                {
                    "comment": "placeholder for OPENSSL_PATH",
                    "libs": ""
                }
            ]
        },
        "openssl": {
            "label": "OpenSSL",
            "test": "openssl",
            "sources": [
                { "type": "openssl" },
                {
                    "comment": "placeholder for OPENSSL_{PATH,LIBS{,_{DEBUG,RELEASE}}}",
                    "libs": "",
                    "condition": "config.win32 && !features.shared"
                },
                {
                    "libs": "-lssleay32 -llibeay32",
                    "condition": "config.win32 && features.shared"
                },
                { "libs": "-lssl -lcrypto", "condition": "!config.win32" }
            ]
        }
    },

    "tests": {
        "getaddrinfo": {
            "label": "getaddrinfo()",
            "type": "compile",
            "test": {
                "head": [
                    "#include <stdio.h>",
                    "#include <stdlib.h>",
                    "#ifdef __MINGW32__",
                    "#  include <winsock2.h>",
                    "#  include <ws2tcpip.h>",
                    "#else",
                    "#  include <sys/types.h>",
                    "#  include <sys/socket.h>",
                    "#  include <netdb.h>",
                    "#endif"
                ],
                "main": [
                    "addrinfo *res = 0;",
                    "(void) getaddrinfo(\"foo\", 0, 0, &res);",
                    "freeaddrinfo(res);",
                    "gai_strerror(0);"
                ]
            },
            "use": "network"
        },
        "getifaddrs": {
            "label": "getifaddrs()",
            "type": "compile",
            "test": {
                "include": [ "sys/types.h", "sys/socket.h", "net/if.h", "ifaddrs.h" ],
                "main": [
                    "ifaddrs *list;",
                    "getifaddrs(&list);",
                    "freeifaddrs(list);"
                ]
            },
            "use": "network"
        },
        "ipv6ifname": {
            "label": "IPv6 ifname",
            "type": "compile",
            "test": {
                "include": [ "sys/types.h", "sys/socket.h", "net/if.h" ],
                "main": [
                    "char buf[IFNAMSIZ];",
                    "if_nametoindex(\"eth0\");",
                    "if_indextoname(1, buf);",
                    "if_freenameindex(if_nameindex());"
                ]
            },
            "use": "network"
        },
        "sctp": {
            "label": "SCTP support",
            "type": "compile",
            "test": {
                "include": [ "sys/types.h", "sys/socket.h", "netinet/in.h", "netinet/sctp.h" ],
                "main": [
                    "sctp_initmsg sctpInitMsg;",
                    "socklen_t sctpInitMsgSize = sizeof(sctpInitMsg);",
                    "(void) socket(PF_INET, SOCK_STREAM, IPPROTO_SCTP);",
                    "(void) getsockopt(-1, SOL_SCTP, SCTP_INITMSG, &sctpInitMsg, &sctpInitMsgSize);"
                ]
            },
            "use": "network"
        }
    },

    "features": {
        "corewlan": {
            "label": "CoreWLan",
            "condition": "libs.corewlan",
            "emitIf": "config.darwin",
            "output": [ "feature", "privateFeature" ]
        },
        "getaddrinfo": {
            "label": "getaddrinfo()",
            "condition": "tests.getaddrinfo",
            "output": [ "feature" ]
        },
        "getifaddrs": {
            "label": "getifaddrs()",
            "condition": "tests.getifaddrs",
            "output": [ "feature" ]
        },
        "ipv6ifname": {
            "label": "IPv6 ifname",
            "condition": "tests.ipv6ifname",
            "output": [ "feature" ]
        },
        "libproxy": {
            "label": "libproxy",
            "autoDetect": false,
            "condition": "libs.libproxy",
            "output": [ "privateFeature" ]
        },
        "openssl": {
            "label": "OpenSSL",
            "enable": "input.openssl == 'yes' || input.openssl == 'linked' || input.openssl == 'runtime'",
            "disable": "input.openssl == 'no' || input.ssl == 'no'",
            "autoDetect": "!config.winrt",
            "condition": "!features.securetransport && (features.openssl-linked || libs.openssl_headers)",
            "output": [
                "privateFeature",
                { "type": "publicQtConfig", "condition": "!features.openssl-linked" },
                { "type": "define", "negative": true, "name": "QT_NO_OPENSSL" }
            ]
        },
        "openssl-linked": {
            "label": "  Qt directly linked to OpenSSL",
            "enable": "input.openssl == 'linked'",
            "disable": "input.openssl != 'linked'",
            "condition": "!features.securetransport && libs.openssl",
            "output": [
                "privateFeature",
                { "type": "define", "name": "QT_LINKED_OPENSSL" }
            ]
        },
        "securetransport": {
            "label": "SecureTransport",
            "disable": "input.securetransport == 'no' || input.ssl == 'no'",
            "condition": "config.darwin && (input.openssl == '' || input.openssl == 'no')",
            "output": [
                "privateFeature",
                { "type": "define", "name": "QT_SECURETRANSPORT" }
            ]
        },
        "ssl": {
            "label": "SSL",
            "condition": "config.winrt || features.securetransport || features.openssl",
            "output": [ "publicFeature", "feature" ]
        },
        "sctp": {
            "label": "SCTP",
            "autoDetect": false,
            "condition": "tests.sctp",
            "output": [ "publicFeature", "feature" ]
        },
        "system-proxies": {
            "label": "Use system proxies",
            "output": [ "privateFeature" ]
        },
        "ftp": {
            "label": "FTP",
            "purpose": "Provides support for the File Transfer Protocol in QNetworkAccessManager.",
            "section": "Networking",
            "condition": "features.textdate",
            "output": [ "publicFeature", "feature" ]
        },
        "http": {
            "label": "HTTP",
            "purpose": "Provides support for the Hypertext Transfer Protocol in QNetworkAccessManager.",
            "section": "Networking",
            "output": [ "publicFeature", "feature" ]
        },
        "udpsocket": {
            "label": "QUdpSocket",
            "purpose": "Provides access to UDP sockets.",
            "section": "Networking",
            "output": [ "publicFeature", "feature" ]
        },
        "networkproxy": {
            "label": "QNetworkProxy",
            "purpose": "Provides network proxy support.",
            "section": "Networking",
            "condition": "!config.winrt",
            "output": [ "publicFeature", "feature" ]
        },
        "socks5": {
            "label": "SOCKS5",
            "purpose": "Provides SOCKS5 support in QNetworkProxy.",
            "section": "Networking",
            "condition": "!config.winrt && features.networkproxy",
            "output": [ "publicFeature", "feature" ]
        },
        "networkinterface": {
            "label": "QNetworkInterface",
            "purpose": "Supports enumerating a host's IP addresses and network interfaces.",
            "section": "Networking",
            "output": [ "publicFeature", "feature" ]
        },
        "networkdiskcache": {
            "label": "QNetworkDiskCache",
            "purpose": "Provides a disk cache for network resources.",
            "section": "Networking",
            "condition": "features.temporaryfile",
            "output": [ "publicFeature", "feature" ]
        },
        "bearermanagement": {
            "label": "Bearer management",
            "purpose": "Provides bearer management for the network stack.",
            "section": "Networking",
            "condition": "features.library && features.networkinterface && features.properties",
            "output": [ "publicFeature", "feature" ]
        },
        "localserver": {
            "label": "QLocalServer",
            "purpose": "Provides a local socket based server.",
            "section": "Networking",
            "condition": "features.temporaryfile",
            "output": [ "publicFeature", "feature" ]
        }
    },

    "report": [
        {
            "type": "note",
            "condition": "features.openssl-linked && libs.openssl.source != 0
                          && input.openssl.prefix == '' && input.openssl.libs == '' && input.openssl.libs.debug == ''",
            "message": "When linking against OpenSSL, you can override the default
library names through OPENSSL_LIBS.
For example:
    OPENSSL_LIBS='-L/opt/ssl/lib -lssl -lcrypto' ./configure -openssl-linked"
        },
        {
            "type": "warning",
            "condition": "features.libproxy && input.qt_namespace == ''",
            "message": "Some of libproxy's plugins may use incompatible Qt versions.

    Some platforms and distributions ship libproxy with plugins, such
    as config_kde4.so, that are linked against old versions of Qt; and
    libproxy loads these plugins automatically when initialized. If Qt
    is not in a namespace, that loading causes a crash. Even if the
    systems on which you build and test have no such plugins, your
    users' systems may have them. We therefore recommend that you
    combine -libproxy with -qtnamespace when configuring Qt."
        }
    ],

    "summary": [
        {
            "section": "Qt Network",
            "entries": [
                {
                    "type": "feature",
                    "args": "corewlan",
                    "condition": "config.darwin"
                },
                "getaddrinfo", "getifaddrs", "ipv6ifname", "libproxy",
                {
                    "type": "feature",
                    "args": "securetransport",
                    "condition": "config.darwin"
                },
                "openssl",
                "openssl-linked",
                "sctp",
                "system-proxies"
            ]
        }
    ]
}
