# libcurl sources to include in curltool lib we use for test binaries
CURLTOOL_LIBCURL_CFILES = \
../lib/base64.c \
- ../lib/dynbuf.c \
- ../lib/curl_get_line.c
+ ../lib/dynbuf.c
# libcurl has sources that provide functions named curlx_* that are not part of
# the official API, but we reuse the code here to avoid duplication.
CURLX_CFILES = \
../lib/base64.c \
- ../lib/curl_get_line.c \
../lib/curl_multibyte.c \
../lib/dynbuf.c \
../lib/nonblock.c \
CURLX_HFILES = \
../lib/curl_ctype.h \
- ../lib/curl_get_line.h \
../lib/curl_multibyte.h \
../lib/curl_setup.h \
../lib/dynbuf.h \
static const char *unslashquote(const char *line, char *param);
#define MAX_CONFIG_LINE_LENGTH (10*1024*1024)
-static bool my_get_line(FILE *fp, struct curlx_dynbuf *, bool *error);
-
/* return 0 on everything-is-fine, and non-zero otherwise */
int parseconfig(const char *filename, struct GlobalConfig *global)
if(alloced_param)
Curl_safefree(param);
-
- curlx_dyn_reset(&buf);
}
curlx_dyn_free(&buf);
if(file != stdin)
/*
* Reads a line from the given file, ensuring is NUL terminated.
*/
-static bool my_get_line(FILE *fp, struct curlx_dynbuf *db,
- bool *error)
+
+bool my_get_line(FILE *input, struct dynbuf *buf, bool *error)
{
- char buf[4096];
- *error = FALSE;
- do {
- /* fgets() returns s on success, and NULL on error or when end of file
- occurs while no characters have been read. */
- if(!fgets(buf, sizeof(buf), fp))
- /* only if there is data in the line, return TRUE */
- return curlx_dyn_len(db);
- if(curlx_dyn_add(db, buf)) {
- *error = TRUE; /* error */
- return FALSE; /* stop reading */
- }
- } while(!strchr(buf, '\n'));
+ CURLcode result;
+ char buffer[128];
+ curlx_dyn_reset(buf);
+ while(1) {
+ char *b = fgets(buffer, sizeof(buffer), input);
+
+ if(b) {
+ size_t rlen = strlen(b);
+
+ if(!rlen)
+ break;
- return TRUE; /* continue */
+ result = curlx_dyn_addn(buf, b, rlen);
+ if(result) {
+ /* too long line or out of memory */
+ *error = TRUE;
+ return FALSE; /* error */
+ }
+
+ else if(b[rlen-1] == '\n')
+ /* end of the line */
+ return TRUE; /* all good */
+
+ else if(feof(input)) {
+ /* append a newline */
+ result = curlx_dyn_addn(buf, "\n", 1);
+ if(result) {
+ /* too long line or out of memory */
+ *error = TRUE;
+ return FALSE; /* error */
+ }
+ return TRUE; /* all good */
+ }
+ }
+ else
+ break;
+ }
+ return FALSE;
}
#include "tool_ssls.h"
#include "dynbuf.h"
#include "curl_base64.h"
-#include "curl_get_line.h"
+#include "tool_parsecfg.h"
/* The maximum line length for an ecoded session ticket */
#define MAX_SSLS_LINE (64 * 1024)
size_t shmac_len, sdata_len;
CURLcode r = CURLE_OK;
int i, imported;
+ bool error = FALSE;
curlx_dyn_init(&buf, MAX_SSLS_LINE);
fp = fopen(filename, FOPEN_READTEXT);
goto out;
i = imported = 0;
- while(Curl_get_line(&buf, fp)) {
+ while(my_get_line(fp, &buf, &error)) {
++i;
curl_free(shmac);
curl_free(sdata);
}
++imported;
}
- r = CURLE_OK;
+ if(error)
+ r = CURLE_FAILED_INIT;
+ else
+ r = CURLE_OK;
out:
if(easy)