|
|
@ -56,6 +56,7 @@ static map<string, external_log_format *> LOG_FORMATS;
|
|
|
|
static external_log_format *ensure_format(yajlpp_parse_context *ypc)
|
|
|
|
static external_log_format *ensure_format(yajlpp_parse_context *ypc)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const string &name = ypc->get_path_fragment(0);
|
|
|
|
const string &name = ypc->get_path_fragment(0);
|
|
|
|
|
|
|
|
vector<string> *formats = (vector<string> *)ypc->ypc_userdata;
|
|
|
|
external_log_format *retval;
|
|
|
|
external_log_format *retval;
|
|
|
|
|
|
|
|
|
|
|
|
retval = LOG_FORMATS[name];
|
|
|
|
retval = LOG_FORMATS[name];
|
|
|
@ -64,6 +65,10 @@ static external_log_format *ensure_format(yajlpp_parse_context *ypc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval->elf_source_path.insert(ypc->ypc_source.substr(0, ypc->ypc_source.rfind('/')));
|
|
|
|
retval->elf_source_path.insert(ypc->ypc_source.substr(0, ypc->ypc_source.rfind('/')));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (find(formats->begin(), formats->end(), name) == formats->end()) {
|
|
|
|
|
|
|
|
formats->push_back(name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -415,33 +420,30 @@ static void write_sample_file(void)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void load_from_path(const string &path, std::vector<string> &errors)
|
|
|
|
std::vector<string> load_format_file(const string &filename, std::vector<string> &errors)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string format_path = path + "/formats/*/*.json";
|
|
|
|
std::vector<string> retval;
|
|
|
|
static_root_mem<glob_t, globfree> gl;
|
|
|
|
|
|
|
|
yajl_handle handle;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_info("loading formats from path: %s", format_path.c_str());
|
|
|
|
|
|
|
|
if (glob(format_path.c_str(), 0, NULL, gl.inout()) == 0) {
|
|
|
|
|
|
|
|
for (int lpc = 0; lpc < (int)gl->gl_pathc; lpc++) {
|
|
|
|
|
|
|
|
string filename(gl->gl_pathv[lpc]);
|
|
|
|
|
|
|
|
auto_fd fd;
|
|
|
|
auto_fd fd;
|
|
|
|
|
|
|
|
|
|
|
|
log_info("loading formats from file: %s", filename.c_str());
|
|
|
|
log_info("loading formats from file: %s", filename.c_str());
|
|
|
|
yajlpp_parse_context ypc(filename, format_handlers);
|
|
|
|
yajlpp_parse_context ypc(filename, format_handlers);
|
|
|
|
if ((fd = open(gl->gl_pathv[lpc], O_RDONLY)) == -1) {
|
|
|
|
ypc.ypc_userdata = &retval;
|
|
|
|
|
|
|
|
if ((fd = open(filename.c_str(), O_RDONLY)) == -1) {
|
|
|
|
char errmsg[1024];
|
|
|
|
char errmsg[1024];
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(errmsg, sizeof(errmsg),
|
|
|
|
snprintf(errmsg, sizeof(errmsg),
|
|
|
|
"error: unable to open format file -- %s",
|
|
|
|
"error: unable to open format file -- %s",
|
|
|
|
gl->gl_pathv[lpc]);
|
|
|
|
filename.c_str());
|
|
|
|
perror(errmsg);
|
|
|
|
errors.push_back(errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
yajl_handle handle;
|
|
|
|
char buffer[2048];
|
|
|
|
char buffer[2048];
|
|
|
|
|
|
|
|
off_t offset = 0;
|
|
|
|
int rc = -1;
|
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
|
|
|
|
handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc);
|
|
|
|
handle = yajl_alloc(&ypc.ypc_callbacks, NULL, &ypc);
|
|
|
|
|
|
|
|
yajl_config(handle, yajl_allow_comments, 1);
|
|
|
|
while (true) {
|
|
|
|
while (true) {
|
|
|
|
rc = read(fd, buffer, sizeof(buffer));
|
|
|
|
rc = read(fd, buffer, sizeof(buffer));
|
|
|
|
if (rc == 0) {
|
|
|
|
if (rc == 0) {
|
|
|
@ -453,12 +455,18 @@ static void load_from_path(const string &path, std::vector<string> &errors)
|
|
|
|
string(strerror(errno)));
|
|
|
|
string(strerror(errno)));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset == 0 && (rc > 2) &&
|
|
|
|
|
|
|
|
(buffer[0] == '#') && (buffer[1] == '!')) {
|
|
|
|
|
|
|
|
// Turn it into a JavaScript comment.
|
|
|
|
|
|
|
|
buffer[0] = buffer[1] = '/';
|
|
|
|
|
|
|
|
}
|
|
|
|
if (yajl_parse(handle, (const unsigned char *)buffer, rc) != yajl_status_ok) {
|
|
|
|
if (yajl_parse(handle, (const unsigned char *)buffer, rc) != yajl_status_ok) {
|
|
|
|
errors.push_back(filename +
|
|
|
|
errors.push_back(filename +
|
|
|
|
": invalid json -- " +
|
|
|
|
": invalid json -- " +
|
|
|
|
string((char *)yajl_get_error(handle, 1, (unsigned char *)buffer, rc)));
|
|
|
|
string((char *)yajl_get_error(handle, 1, (unsigned char *)buffer, rc)));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc == 0) {
|
|
|
|
if (rc == 0) {
|
|
|
|
if (yajl_complete_parse(handle) != yajl_status_ok) {
|
|
|
|
if (yajl_complete_parse(handle) != yajl_status_ok) {
|
|
|
@ -469,6 +477,25 @@ static void load_from_path(const string &path, std::vector<string> &errors)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yajl_free(handle);
|
|
|
|
yajl_free(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void load_from_path(const string &path, std::vector<string> &errors)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string format_path = path + "/formats/*/*.json";
|
|
|
|
|
|
|
|
static_root_mem<glob_t, globfree> gl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_info("loading formats from path: %s", format_path.c_str());
|
|
|
|
|
|
|
|
if (glob(format_path.c_str(), 0, NULL, gl.inout()) == 0) {
|
|
|
|
|
|
|
|
for (int lpc = 0; lpc < (int)gl->gl_pathc; lpc++) {
|
|
|
|
|
|
|
|
string filename(gl->gl_pathv[lpc]);
|
|
|
|
|
|
|
|
vector<string> format_list;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
format_list = load_format_file(filename, errors);
|
|
|
|
|
|
|
|
if (format_list.empty()) {
|
|
|
|
|
|
|
|
log_warning("Empty format file: %s", filename.c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -484,6 +511,8 @@ void load_formats(const std::vector<std::string> &extra_paths,
|
|
|
|
write_sample_file();
|
|
|
|
write_sample_file();
|
|
|
|
|
|
|
|
|
|
|
|
handle = yajl_alloc(&ypc_builtin.ypc_callbacks, NULL, &ypc_builtin);
|
|
|
|
handle = yajl_alloc(&ypc_builtin.ypc_callbacks, NULL, &ypc_builtin);
|
|
|
|
|
|
|
|
ypc_builtin.ypc_userdata = &retval;
|
|
|
|
|
|
|
|
yajl_config(handle, yajl_allow_comments, 1);
|
|
|
|
if (yajl_parse(handle,
|
|
|
|
if (yajl_parse(handle,
|
|
|
|
(const unsigned char *)default_log_formats_json,
|
|
|
|
(const unsigned char *)default_log_formats_json,
|
|
|
|
strlen(default_log_formats_json)) != yajl_status_ok) {
|
|
|
|
strlen(default_log_formats_json)) != yajl_status_ok) {
|
|
|
|