20
20
21
21
#include "asterisk/utils.h"
22
22
#include "asterisk/logger.h"
23
+ #include "asterisk/file.h"
23
24
#include "curl.h"
24
25
#include "general.h"
25
26
#include "stir_shaken.h"
@@ -151,42 +152,11 @@ static CURL *get_curl_instance(struct curl_cb_data *data)
151
152
return curl ;
152
153
}
153
154
154
- /*!
155
- * \brief Create a temporary file located at path
156
- *
157
- * \note This function assumes path does not end with a '/'
158
- *
159
- * \param path The directory path to create the file in
160
- * \param filename Function allocates memory and stores full filename (including path) here
161
- *
162
- * \retval -1 on failure
163
- * \return file descriptor on success
164
- */
165
- static int create_temp_file (const char * path , char * * filename )
166
- {
167
- const char * template_name = "certXXXXXX" ;
168
- int fd ;
169
-
170
- if (ast_asprintf (filename , "%s/%s" , path , template_name ) < 0 ) {
171
- ast_log (LOG_ERROR , "Failed to set up temporary file path for CURL\n" );
172
- return -1 ;
173
- }
174
-
175
- ast_mkdir (path , 0644 );
176
-
177
- if ((fd = mkstemp (* filename )) < 0 ) {
178
- ast_log (LOG_NOTICE , "Failed to create temporary file for CURL\n" );
179
- ast_free (* filename );
180
- return -1 ;
181
- }
182
-
183
- return fd ;
184
- }
185
-
186
155
char * curl_public_key (const char * public_cert_url , const char * path , struct curl_cb_data * data )
187
156
{
188
157
FILE * public_key_file ;
189
158
RAII_VAR (char * , tmp_filename , NULL , ast_free );
159
+ const char * template_name = "certXXXXXX" ;
190
160
char * filename ;
191
161
char * serial ;
192
162
int fd ;
@@ -199,9 +169,9 @@ char *curl_public_key(const char *public_cert_url, const char *path, struct curl
199
169
/* For now, it's fine to pass in path as is - it shouldn't end with a '/'. However,
200
170
* if we decide to change how certificates are stored in the future (configurable paths),
201
171
* then we will need to check to see if path ends with '/', copy everything up to the '/',
202
- * and use this new variable for create_temp_file as well as for ast_asprintf below.
172
+ * and use this new variable for ast_create_temp_file as well as for ast_asprintf below.
203
173
*/
204
- fd = create_temp_file (path , & tmp_filename );
174
+ fd = ast_file_fdtemp (path , & tmp_filename , template_name );
205
175
if (fd == -1 ) {
206
176
ast_log (LOG_ERROR , "Failed to get temporary file descriptor for CURL\n" );
207
177
return NULL ;
0 commit comments