From: mike Date: Mon, 28 Jan 2013 18:51:47 +0000 (+0000) Subject: Get 1.7 back into shape to use/test on 10.8. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a5c43f434876d693342ad41659db79a4d60e059;p=thirdparty%2Fcups.git Get 1.7 back into shape to use/test on 10.8. Revert changes to _httpCreate private API to the CUPS 1.6 version, and add a new static function with the new API that gets used in libcups. Change httpConnect2 to return an unconnected http_t if msec == 0. Change all remaining callers of _httpCreate to use httpConnect2 with msec = 0. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10841 7a7537e8-13f0-0310-91df-b6672ffda945 --- diff --git a/backend/ipp.c b/backend/ipp.c index 4fcedecee5..73c1a33b35 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -691,8 +691,8 @@ main(int argc, /* I - Number of command-line args */ return (CUPS_BACKEND_OK); } - http = _httpCreate(hostname, port, addrlist, AF_UNSPEC, cupsEncryption(), 1, - _HTTP_MODE_CLIENT); + http = httpConnect2(hostname, port, addrlist, AF_UNSPEC, cupsEncryption(), 1, + 0, NULL); httpSetTimeout(http, 30.0, timeout_cb, NULL); /* @@ -2244,8 +2244,8 @@ monitor_printer( * Make a copy of the printer connection... */ - http = _httpCreate(monitor->hostname, monitor->port, NULL, AF_UNSPEC, - monitor->encryption, 1, _HTTP_MODE_CLIENT); + http = httpConnect2(monitor->hostname, monitor->port, NULL, AF_UNSPEC, + monitor->encryption, 1, 0, NULL); httpSetTimeout(http, 30.0, timeout_cb, NULL); if (username[0]) cupsSetUser(username); diff --git a/cups/adminutil.c b/cups/adminutil.c index 38f3de6f80..7a8de0b897 100644 --- a/cups/adminutil.c +++ b/cups/adminutil.c @@ -901,9 +901,8 @@ cupsAdminGetServerSettings( if (!cg->http) { - if ((cg->http = _httpCreate(cupsServer(), ippPort(), NULL, AF_UNSPEC, - cupsEncryption(), 1, - _HTTP_MODE_CLIENT)) == NULL) + if ((cg->http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, + cupsEncryption(), 1, 0, NULL)) == NULL) { if (errno) _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0); diff --git a/cups/dest.c b/cups/dest.c index b27fb3b8ab..4ac40f16c0 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -3,7 +3,7 @@ * * User-defined destination (and option) support for CUPS. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2007 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -722,8 +722,8 @@ cupsConnectDest( else encryption = HTTP_ENCRYPT_IF_REQUESTED; - http = _httpCreate(hostname, port, addrlist, AF_UNSPEC, encryption, 1, - _HTTP_MODE_CLIENT); + http = httpConnect2(hostname, port, addrlist, AF_UNSPEC, encryption, 1, 0, + NULL); /* * Connect if requested... diff --git a/cups/http-private.h b/cups/http-private.h index 910d7ec48d..d326a0a80e 100644 --- a/cups/http-private.h +++ b/cups/http-private.h @@ -403,9 +403,9 @@ extern char *_httpAssembleUUID(const char *server, int port, char *buffer, size_t bufsize) _CUPS_INTERNAL_MSG("Use httpAssembleUUID instead."); extern http_t *_httpCreate(const char *host, int port, - http_addrlist_t *addrlist, int family, + http_addrlist_t *addrlist, http_encryption_t encryption, - int blocking, _http_mode_t mode) + int family) _CUPS_INTERNAL_MSG("Use httpConnect2 or httpAccept instead."); extern http_tls_credentials_t _httpCreateCredentials(cups_array_t *credentials); diff --git a/cups/http.c b/cups/http.c index 7b7446cd7a..efd6d807ee 100644 --- a/cups/http.c +++ b/cups/http.c @@ -37,7 +37,6 @@ * httpConnectEncrypt() - Connect to a HTTP server using encryption. * httpCopyCredentials() - Copy the credentials associated with an * encrypted connection. - * _httpCreate() - Create an unconnected HTTP connection. * _httpCreateCredentials() - Create credentials in the internal format. * httpDelete() - Send a DELETE request to the server. * _httpDisconnect() - Disconnect a HTTP connection. @@ -118,6 +117,7 @@ * http_bio_write() - Write data for OpenSSL. * http_content_coding_finish() - Finish doing any content encoding. * http_content_coding_start() - Start doing content encoding. + * http_create() - Create an unconnected HTTP connection. * http_debug_hex() - Do a hex dump of a buffer. * http_field() - Return the field index for a field name. * http_read() - Read a buffer from a HTTP connection. @@ -167,6 +167,10 @@ static void http_content_coding_finish(http_t *http); static void http_content_coding_start(http_t *http, const char *value); #endif /* HAVE_LIBZ */ +static http_t *http_create(const char *host, int port, + http_addrlist_t *addrlist, int family, + http_encryption_t encryption, + int blocking, _http_mode_t mode); #ifdef DEBUG static void http_debug_hex(const char *prefix, const char *buffer, int bytes); @@ -318,7 +322,7 @@ httpAcceptConnection(int fd, /* I - Listen socket file descriptor */ memset(&addrlist, 0, sizeof(addrlist)); - if ((http = _httpCreate(NULL, 0, &addrlist, AF_UNSPEC, + if ((http = http_create(NULL, 0, &addrlist, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, blocking, _HTTP_MODE_SERVER)) == NULL) return (NULL); @@ -606,7 +610,7 @@ httpConnect2( int family, /* I - Address family to use or @code AF_UNSPEC@ for any */ http_encryption_t encryption, /* I - Type of encryption to use */ int blocking, /* I - 1 for blocking connection, 0 for non-blocking */ - int msec, /* I - Connection timeout in milliseconds */ + int msec, /* I - Connection timeout in milliseconds, 0 means don't connect */ int *cancel) /* I - Pointer to "cancel" variable */ { http_t *http; /* New HTTP connection */ @@ -620,15 +624,15 @@ httpConnect2( * Create the HTTP structure... */ - if ((http = _httpCreate(host, port, addrlist, family, encryption, blocking, + if ((http = http_create(host, port, addrlist, family, encryption, blocking, _HTTP_MODE_CLIENT)) == NULL) return (NULL); /* - * Connect to the remote system... + * Optionally connect to the remote system... */ - if (!httpReconnect2(http, msec, cancel)) + if (msec == 0 || !httpReconnect2(http, msec, cancel)) return (http); /* @@ -734,96 +738,6 @@ httpCopyCredentials( } -/* - * '_httpCreate()' - Create an unconnected HTTP connection. - */ - -http_t * /* O - HTTP connection */ -_httpCreate( - const char *host, /* I - Hostname */ - int port, /* I - Port number */ - http_addrlist_t *addrlist, /* I - Address list or NULL */ - int family, /* I - Address family or AF_UNSPEC */ - http_encryption_t encryption, /* I - Encryption to use */ - int blocking, /* I - 1 for blocking mode */ - _http_mode_t mode) /* I - _HTTP_MODE_CLIENT or _SERVER */ -{ - http_t *http; /* New HTTP connection */ - char service[255]; /* Service name */ - http_addrlist_t *myaddrlist = NULL; /* My address list */ - - - DEBUG_printf(("4_httpCreate(host=\"%s\", port=%d, addrlist=%p, family=%d, " - "encryption=%d, blocking=%d, mode=%d)", host, port, addrlist, - family, encryption, blocking, mode)); - - if (!host && mode == _HTTP_MODE_CLIENT) - return (NULL); - - httpInitialize(); - - /* - * Lookup the host... - */ - - if (addrlist) - { - myaddrlist = httpAddrCopyList(addrlist); - } - else - { - snprintf(service, sizeof(service), "%d", port); - - myaddrlist = httpAddrGetList(host, family, service); - } - - if (!myaddrlist) - return (NULL); - - /* - * Allocate memory for the structure... - */ - - if ((http = calloc(sizeof(http_t), 1)) == NULL) - { - _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno), 0); - httpAddrFreeList(addrlist); - return (NULL); - } - - /* - * Initialize the HTTP data... - */ - - http->mode = mode; - http->activity = time(NULL); - http->addrlist = myaddrlist; - http->blocking = blocking; - http->fd = -1; -#ifdef HAVE_GSSAPI - http->gssctx = GSS_C_NO_CONTEXT; - http->gssname = GSS_C_NO_NAME; -#endif /* HAVE_GSSAPI */ - http->version = HTTP_VERSION_1_1; - - if (host) - strlcpy(http->hostname, host, sizeof(http->hostname)); - - if (port == 443) /* Always use encryption for https */ - http->encryption = HTTP_ENCRYPTION_ALWAYS; - else - http->encryption = encryption; - - http_set_wait(http); - - /* - * Return the new structure... - */ - - return (http); -} - - /* * '_httpCreateCredentials()' - Create credentials in the internal format. */ @@ -4373,6 +4287,102 @@ http_content_coding_start( #endif /* HAVE_LIBZ */ +/* + * 'http_create()' - Create an unconnected HTTP connection. + */ + +static http_t * /* O - HTTP connection */ +http_create( + const char *host, /* I - Hostname */ + int port, /* I - Port number */ + http_addrlist_t *addrlist, /* I - Address list or NULL */ + int family, /* I - Address family or AF_UNSPEC */ + http_encryption_t encryption, /* I - Encryption to use */ + int blocking, /* I - 1 for blocking mode */ + _http_mode_t mode) /* I - _HTTP_MODE_CLIENT or _SERVER */ +{ + http_t *http; /* New HTTP connection */ + char service[255]; /* Service name */ + http_addrlist_t *myaddrlist = NULL; /* My address list */ + + + DEBUG_printf(("4http_create(host=\"%s\", port=%d, addrlist=%p, family=%d, " + "encryption=%d, blocking=%d, mode=%d)", host, port, addrlist, + family, encryption, blocking, mode)); + + if (!host && mode == _HTTP_MODE_CLIENT) + return (NULL); + + httpInitialize(); + + /* + * Lookup the host... + */ + + if (addrlist) + { + myaddrlist = httpAddrCopyList(addrlist); + } + else + { + snprintf(service, sizeof(service), "%d", port); + + myaddrlist = httpAddrGetList(host, family, service); + } + + if (!myaddrlist) + return (NULL); + + /* + * Allocate memory for the structure... + */ + + if ((http = calloc(sizeof(http_t), 1)) == NULL) + { + _cupsSetError(IPP_INTERNAL_ERROR, strerror(errno), 0); + httpAddrFreeList(addrlist); + return (NULL); + } + + /* + * Initialize the HTTP data... + */ + + http->mode = mode; + http->activity = time(NULL); + http->addrlist = myaddrlist; + http->blocking = blocking; + http->fd = -1; +#ifdef HAVE_GSSAPI + http->gssctx = GSS_C_NO_CONTEXT; + http->gssname = GSS_C_NO_NAME; +#endif /* HAVE_GSSAPI */ + http->version = HTTP_VERSION_1_1; + + if (host) + strlcpy(http->hostname, host, sizeof(http->hostname)); + + if (port == 443) /* Always use encryption for https */ + http->encryption = HTTP_ENCRYPTION_ALWAYS; + else + http->encryption = encryption; + + http_set_wait(http); + + /* + * Return the new structure... + */ + + return (http); +} + +/* For OS X 10.8 and earlier */ +http_t *_httpCreate(const char *host, int port, http_addrlist_t *addrlist, + http_encryption_t encryption, int family) +{ return (http_create(host, port, addrlist, family, encryption, 1, + _HTTP_MODE_CLIENT)); } + + #ifdef DEBUG /* * 'http_debug_hex()' - Do a hex dump of a buffer. diff --git a/test/ipptool.c b/test/ipptool.c index 34caa4a022..53ec0e3742 100644 --- a/test/ipptool.c +++ b/test/ipptool.c @@ -413,7 +413,10 @@ main(int argc, /* I - Number of command-line args */ } if (vars.filename) + { free(vars.filename); + vars.filename = NULL; + } if (access(argv[i], 0)) { @@ -436,6 +439,8 @@ main(int argc, /* I - Number of command-line args */ cg->cups_datadir, argv[i]); if (access(filename, 0)) vars.filename = strdup(argv[i]); + else + vars.filename = strdup(filename); } else vars.filename = strdup(filename);