Line | Count | Source |
1 | | #ifndef HEADER_CURL_CREDS_H |
2 | | #define HEADER_CURL_CREDS_H |
3 | | /*************************************************************************** |
4 | | * _ _ ____ _ |
5 | | * Project ___| | | | _ \| | |
6 | | * / __| | | | |_) | | |
7 | | * | (__| |_| | _ <| |___ |
8 | | * \___|\___/|_| \_\_____| |
9 | | * |
10 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
11 | | * |
12 | | * This software is licensed as described in the file COPYING, which |
13 | | * you should have received as part of this distribution. The terms |
14 | | * are also available at https://curl.se/docs/copyright.html. |
15 | | * |
16 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
17 | | * copies of the Software, and permit persons to whom the Software is |
18 | | * furnished to do so, under the terms of the COPYING file. |
19 | | * |
20 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
21 | | * KIND, either express or implied. |
22 | | * |
23 | | * SPDX-License-Identifier: curl |
24 | | * |
25 | | ***************************************************************************/ |
26 | | |
27 | | struct Curl_easy; |
28 | | |
29 | 0 | #define CREDS_NONE 0 /* used for default username/passwd */ |
30 | 25.5k | #define CREDS_URL 1 /* username/passwd from URL */ |
31 | 2.70k | #define CREDS_OPTION 2 /* username/passwd set with a CURLOPT_ */ |
32 | 0 | #define CREDS_NETRC 3 /* username/passwd found in netrc */ |
33 | | |
34 | | struct Curl_creds { |
35 | | const char *user; /* non-NULL, maybe empty string */ |
36 | | const char *passwd; /* non-NULL, maybe empty string */ |
37 | | const char *oauth_bearer; /* non-NULL, maybe empty string */ |
38 | | const char *sasl_authzid; /* non-NULL, maybe empty string */ |
39 | | const char *sasl_service; /* non-NULL, maybe empty string */ |
40 | | uint32_t refcount; |
41 | | uint8_t source; /* CREDS_* value */ |
42 | | size_t bufsize; /* extra bytes added to sizeof(struct Curl_creds) */ |
43 | | char buf[1]; |
44 | | }; |
45 | | |
46 | | CURLcode Curl_creds_create(const char *user, |
47 | | const char *passwd, |
48 | | const char *oauth_bearer, |
49 | | const char *sasl_authzid, |
50 | | const char *sasl_service, |
51 | | uint8_t source, |
52 | | struct Curl_creds **pcreds); |
53 | | |
54 | | /* Create credentials by overriding `user` and/or `passwd` in `creds_in` */ |
55 | | CURLcode Curl_creds_merge(const char *user, |
56 | | const char *passwd, |
57 | | struct Curl_creds *creds_in, |
58 | | uint8_t source, |
59 | | struct Curl_creds **pcreds_out); |
60 | | |
61 | | /* Unlink any creds in `*pdest`, assign src, increase src |
62 | | * refcount when not NULL. */ |
63 | | void Curl_creds_link(struct Curl_creds **pdest, struct Curl_creds *src); |
64 | | |
65 | | /* Drop a reference, creds may be passed as NULL */ |
66 | | void Curl_creds_unlink(struct Curl_creds **pcreds); |
67 | | |
68 | | /* TRUE if both creds are NULL or have same values, except source. */ |
69 | | bool Curl_creds_same(struct Curl_creds *c1, struct Curl_creds *c2); |
70 | | |
71 | | /* TRUE if both creds are NULL or have all values equal. */ |
72 | | bool Curl_creds_equal(struct Curl_creds *c1, struct Curl_creds *c2); |
73 | | |
74 | | /* Provides properties for creds or, if creds is NULL, the empty string */ |
75 | 2.65k | #define Curl_creds_has_user(c) ((c) && (c)->user[0]) |
76 | 0 | #define Curl_creds_has_passwd(c) ((c) && (c)->passwd[0]) |
77 | | #define Curl_creds_has_user_or_pass(c) \ |
78 | 3.09k | ((c) && ((c)->user[0] || (c)->passwd[0])) |
79 | 2.35k | #define Curl_creds_has_oauth_bearer(c) ((c) && (c)->oauth_bearer[0]) |
80 | 0 | #define Curl_creds_has_sasl_service(c) ((c) && (c)->sasl_service[0]) |
81 | 3.90k | #define Curl_creds_user(c) ((c) ? (c)->user : "") |
82 | 3.91k | #define Curl_creds_passwd(c) ((c) ? (c)->passwd : "") |
83 | 2.39k | #define Curl_creds_oauth_bearer(c) ((c) ? (c)->oauth_bearer : "") |
84 | 2.38k | #define Curl_creds_sasl_authzid(c) ((c) ? (c)->sasl_authzid : "") |
85 | 2.38k | #define Curl_creds_sasl_service(c) ((c) ? (c)->sasl_service : "") |
86 | | |
87 | | #ifdef CURLVERBOSE |
88 | | void Curl_creds_trace(struct Curl_easy *data, struct Curl_creds *creds, |
89 | | const char *msg); |
90 | | #endif |
91 | | |
92 | | #endif /* HEADER_CURL_CREDS_H */ |