cupsのhttpConnectEncryptがdeprecatedなのでhttpConnect2を使う

CUPSのAPIにhttpConnectEncryptがありますが、Deprecatedになっています。
古いコードを最新のSDKなどでビルドするとワーニングになってしまいます。
マニュアルをみるとhttpConnect2を使うように記載されていますが、httpConnect2をみると引数が4つほど増えています。
マニュアルをみるだけだと、謎の引数に何を設定すれば良いのかわからないので、CUPSのソースコードを見てみることにました。

httpConnect2の記述はこんな感じ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * 'httpConnect2()' - Connect to a HTTP server.
 *
 * @since CUPS 1.7/macOS 10.9@
 */
 
http_t *    /* O - New HTTP connection */
httpConnect2(
    const char        *host,  /* I - Host to connect to */
    int               port,  /* I - Port number */
    http_addrlist_t   *addrlist, /* I - List of addresses or @code NULL@ to lookup */
    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, 0 means don't connect */
    int               *cancel)  /* I - Pointer to "cancel" variable */
{
  http_t *http;   /* New HTTP connection */
:

引数がかなりいっぱいあります。
そこでhttpConnectEncryptの定義を見てみると...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * 'httpConnectEncrypt()' - Connect to a HTTP server using encryption.
 *
 * This function is now deprecated. Please use the @link httpConnect2@ function
 * instead.
 *
 * @deprecated@ @exclude all@
 */
 
http_t *    /* O - New HTTP connection */
httpConnectEncrypt(
    const char        *host,  /* I - Host to connect to */
    int               port,  /* I - Port number */
    http_encryption_t encryption) /* I - Type of encryption to use */
{
  DEBUG_printf(("httpConnectEncrypt(host=\"%s\", port=%d, encryption=%d)",
                host, port, encryption));
 
  return (httpConnect2(host, port, NULL, AF_UNSPEC, encryption, 1, 30000,
                       NULL));
}

内部ではhttpConnect2をcallしていました。
なので、httpConnect2によびかえる場合はhttpConnectEncryptの呼び方と同じにしておけば良さそうです。
ソースコードをみると色々とわかります。
もっと普段からソースコードを確認しようと思いました。

0 件のコメント :

コメントを投稿