error:
if (output) {
g_string_free(output, TRUE);
+ output = NULL;
}
end:
at += end_pos;
- /* :// */
+ /* `://` */
if (strncmp(at, "://", 3) != 0) {
if (error_buf) {
snprintf(error_buf, error_buf_size,
goto error;
}
+ /* Skip `://` */
at += 3;
/* Hostname */
}
if (at[end_pos] == '\0') {
+ /* Relay daemon hostname and ports provided only */
goto end;
}
at += end_pos;
- /* /host/ */
+ /* `/host/` */
if (strncmp(at, "/host/", 6) != 0) {
if (error_buf) {
snprintf(error_buf, error_buf_size,
}
if (at[end_pos] == '\0') {
- goto end;
+ if (error_buf) {
+ snprintf(error_buf, error_buf_size,
+ "Missing `/` after target hostname (`%s`)",
+ parts.target_hostname->str);
+ }
+
+ goto error;
}
+ /* Skip `/` */
at += end_pos + 1;
/* Session name */
}
return print_len;
}
+
+BT_HIDDEN
+int bt_common_append_file_content_to_g_string(GString *str, FILE *fp)
+{
+ const size_t chunk_size = 4096;
+ int ret = 0;
+ char *buf;
+ size_t read_len;
+ gsize orig_len = str->len;
+
+ BT_ASSERT(str);
+ BT_ASSERT(fp);
+ buf = g_malloc(chunk_size);
+ if (!buf) {
+ ret = -1;
+ goto end;
+ }
+
+ while (true) {
+ if (ferror(fp)) {
+ ret = -1;
+ goto end;
+ }
+
+ if (feof(fp)) {
+ break;
+ }
+
+ read_len = fread(buf, 1, chunk_size, fp);
+ g_string_append_len(str, buf, read_len);
+ }
+
+end:
+ if (ret) {
+ /* Remove what was appended */
+ g_string_truncate(str, orig_len);
+ }
+
+ g_free(buf);
+ return ret;
+}