diff options
author | Daniel Stenberg <daniel@haxx.se> | 2021-01-08 17:58:15 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-01-17 23:56:09 +0100 |
commit | 215db086e09665ee7af9b646ad6c4d6e281001ac (patch) | |
tree | 50c74f8456df87e86de6d72e90190a3563083a1a /lib/krb5.c | |
parent | 0d26ab9ed3ac29da2a383d313e93df3e9f5295a2 (diff) | |
download | curl-215db086e09665ee7af9b646ad6c4d6e281001ac.tar.gz |
lib: pass in 'struct Curl_easy *' to most functions
... in most cases instead of 'struct connectdata *' but in some cases in
addition to.
- We mostly operate on transfers and not connections.
- We need the transfer handle to log, store data and more. Everything in
libcurl is driven by a transfer (the CURL * in the public API).
- This work clarifies and separates the transfers from the connections
better.
- We should avoid "conn->data". Since individual connections can be used
by many transfers when multiplexing, making sure that conn->data
points to the current and correct transfer at all times is difficult
and has been notoriously error-prone over the years. The goal is to
ultimately remove the conn->data pointer for this reason.
Closes #6425
Diffstat (limited to 'lib/krb5.c')
-rw-r--r-- | lib/krb5.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/krb5.c b/lib/krb5.c index 269d026e4..898d74144 100644 --- a/lib/krb5.c +++ b/lib/krb5.c @@ -2,7 +2,7 @@ * * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). - * Copyright (c) 2004 - 2020 Daniel Stenberg + * Copyright (c) 2004 - 2021 Daniel Stenberg * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -89,7 +89,7 @@ static CURLcode ftpsend(struct connectdata *conn, const char *cmd) #ifdef HAVE_GSSAPI conn->data_prot = PROT_CMD; #endif - result = Curl_write(conn, conn->sock[FIRSTSOCKET], sptr, write_len, + result = Curl_write(conn->data, conn->sock[FIRSTSOCKET], sptr, write_len, &bytes_written); #ifdef HAVE_GSSAPI DEBUGASSERT(data_sec > PROT_NONE && data_sec < PROT_LAST); @@ -246,7 +246,7 @@ krb5_auth(void *app_data, struct connectdata *conn) if(result) return -2; - if(Curl_GetFTPResponse(&nread, conn, NULL)) + if(Curl_GetFTPResponse(data, &nread, NULL)) return -1; if(data->state.buffer[0] != '3') @@ -331,7 +331,7 @@ krb5_auth(void *app_data, struct connectdata *conn) break; } - if(Curl_GetFTPResponse(&nread, conn, NULL)) { + if(Curl_GetFTPResponse(data, &nread, NULL)) { ret = -1; break; } @@ -443,7 +443,7 @@ static char level_to_char(int level) /* Send an FTP command defined by |message| and the optional arguments. The function returns the ftp_code. If an error occurs, -1 is returned. */ -static int ftp_send_command(struct connectdata *conn, const char *message, ...) +static int ftp_send_command(struct Curl_easy *data, const char *message, ...) { int ftp_code; ssize_t nread = 0; @@ -454,11 +454,11 @@ static int ftp_send_command(struct connectdata *conn, const char *message, ...) mvsnprintf(print_buffer, sizeof(print_buffer), message, args); va_end(args); - if(ftpsend(conn, print_buffer)) { + if(ftpsend(data->conn, print_buffer)) { ftp_code = -1; } else { - if(Curl_GetFTPResponse(&nread, conn, &ftp_code)) + if(Curl_GetFTPResponse(data, &nread, &ftp_code)) ftp_code = -1; } @@ -503,7 +503,7 @@ socket_write(struct connectdata *conn, curl_socket_t fd, const void *to, ssize_t written; while(len > 0) { - result = Curl_write_plain(conn, fd, to_p, len, &written); + result = Curl_write_plain(conn->data, fd, to_p, len, &written); if(!result) { len -= written; to_p += written; @@ -556,18 +556,19 @@ buffer_read(struct krb5buffer *buf, void *data, size_t len) } /* Matches Curl_recv signature */ -static ssize_t sec_recv(struct connectdata *conn, int sockindex, +static ssize_t sec_recv(struct Curl_easy *data, int sockindex, char *buffer, size_t len, CURLcode *err) { size_t bytes_read; size_t total_read = 0; + struct connectdata *conn = data->conn; curl_socket_t fd = conn->sock[sockindex]; *err = CURLE_OK; /* Handle clear text response. */ if(conn->sec_complete == 0 || conn->data_prot == PROT_CLEAR) - return sread(fd, buffer, len); + return sread(fd, buffer, len); if(conn->in_buffer.eof_flag) { conn->in_buffer.eof_flag = 0; @@ -673,9 +674,10 @@ static ssize_t sec_write(struct connectdata *conn, curl_socket_t fd, } /* Matches Curl_send signature */ -static ssize_t sec_send(struct connectdata *conn, int sockindex, +static ssize_t sec_send(struct Curl_easy *data, int sockindex, const void *buffer, size_t len, CURLcode *err) { + struct connectdata *conn = data->conn; curl_socket_t fd = conn->sock[sockindex]; *err = CURLE_OK; return sec_write(conn, fd, buffer, len); @@ -736,9 +738,10 @@ int Curl_sec_read_msg(struct connectdata *conn, char *buffer, return ret_code; } -static int sec_set_protection_level(struct connectdata *conn) +static int sec_set_protection_level(struct Curl_easy *data) { int code; + struct connectdata *conn = data->conn; enum protection_level level = conn->request_data_prot; DEBUGASSERT(level > PROT_NONE && level < PROT_LAST); @@ -757,7 +760,7 @@ static int sec_set_protection_level(struct connectdata *conn) char *pbsz; static unsigned int buffer_size = 1 << 20; /* 1048576 */ - code = ftp_send_command(conn, "PBSZ %u", buffer_size); + code = ftp_send_command(data, "PBSZ %u", buffer_size); if(code < 0) return -1; @@ -767,7 +770,7 @@ static int sec_set_protection_level(struct connectdata *conn) } conn->buffer_size = buffer_size; - pbsz = strstr(conn->data->state.buffer, "PBSZ="); + pbsz = strstr(data->state.buffer, "PBSZ="); if(pbsz) { /* ignore return code, use default value if it fails */ (void)sscanf(pbsz, "PBSZ=%u", &buffer_size); @@ -776,8 +779,8 @@ static int sec_set_protection_level(struct connectdata *conn) } } - /* Now try to negotiate the protection level. */ - code = ftp_send_command(conn, "PROT %c", level_to_char(level)); + /* Now try to negiociate the protection level. */ + code = ftp_send_command(data, "PROT %c", level_to_char(level)); if(code < 0) return -1; @@ -830,7 +833,7 @@ static CURLcode choose_mech(struct connectdata *conn) } infof(data, "Trying mechanism %s...\n", mech->name); - ret = ftp_send_command(conn, "AUTH %s", mech->name); + ret = ftp_send_command(data, "AUTH %s", mech->name); if(ret < 0) return CURLE_COULDNT_CONNECT; @@ -873,7 +876,7 @@ static CURLcode choose_mech(struct connectdata *conn) conn->command_prot = PROT_SAFE; /* Set the requested protection level */ /* BLOCKING */ - (void)sec_set_protection_level(conn); + (void)sec_set_protection_level(data); } return CURLE_OK; |