mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-14 00:00:44 +00:00
switch another file parsing function to use buffered read
This commit is contained in:
parent
ee50ed23ab
commit
0fe6aa4d0a
@ -203,7 +203,7 @@ SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream
|
|||||||
SWITCH_DECLARE(switch_status_t) switch_stream_write_file_contents(switch_stream_handle_t *stream, const char *path)
|
SWITCH_DECLARE(switch_status_t) switch_stream_write_file_contents(switch_stream_handle_t *stream, const char *path)
|
||||||
{
|
{
|
||||||
char *dpath = NULL;
|
char *dpath = NULL;
|
||||||
int fd;
|
FILE *fd = NULL;
|
||||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||||
|
|
||||||
if (!switch_is_file_path(path)) {
|
if (!switch_is_file_path(path)) {
|
||||||
@ -211,12 +211,14 @@ SWITCH_DECLARE(switch_status_t) switch_stream_write_file_contents(switch_stream_
|
|||||||
path = dpath;
|
path = dpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(path, O_RDONLY)) > -1) {
|
if ((fd = fopen(path, "r"))) {
|
||||||
char buf[2048] = { 0 };
|
char *line_buf = NULL;
|
||||||
while (switch_fd_read_line(fd, buf, sizeof(buf))) {
|
switch_size_t llen = 0;
|
||||||
stream->write_function(stream, "%s", buf);
|
|
||||||
|
while (switch_fp_read_dline(fd, &line_buf, &llen)) {
|
||||||
|
stream->write_function(stream, "%s", line_buf);
|
||||||
}
|
}
|
||||||
close(fd);
|
fclose(fd);
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +248,7 @@ SWITCH_DECLARE(char *) switch_console_expand_alias(char *cmd, char *arg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_persist_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -682,7 +684,7 @@ SWITCH_DECLARE(unsigned char) switch_console_complete(const char *line, const ch
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_persist_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
||||||
return CC_ERROR;
|
return CC_ERROR;
|
||||||
}
|
}
|
||||||
@ -1774,7 +1776,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string)
|
|||||||
SWITCH_STANDARD_STREAM(mystream);
|
SWITCH_STANDARD_STREAM(mystream);
|
||||||
|
|
||||||
|
|
||||||
if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_persist_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
||||||
free(mystream.data);
|
free(mystream.data);
|
||||||
free(mydata);
|
free(mydata);
|
||||||
@ -1857,7 +1859,7 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string)
|
|||||||
switch_cache_db_handle_t *db = NULL;
|
switch_cache_db_handle_t *db = NULL;
|
||||||
char *sql = NULL;
|
char *sql = NULL;
|
||||||
|
|
||||||
if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_persist_db_handle(&db) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n");
|
||||||
free(mydata);
|
free(mydata);
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user