File: java-template-proxy.c

package info (click to toggle)
syslog-ng 3.19.1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,176 kB
  • sloc: ansic: 114,472; makefile: 4,697; sh: 4,391; python: 4,282; java: 4,047; xml: 2,435; yacc: 1,108; lex: 426; perl: 193; awk: 184
file content (77 lines) | stat: -rw-r--r-- 2,986 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (c) 2010-2015 Balabit
 * Copyright (c) 2010-2015 Viktor Juhasz <viktor.juhasz@balabit.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * As an additional exemption you are allowed to compile & link against the
 * OpenSSL libraries as published by the OpenSSL project. See the file
 * COPYING for details.
 *
 */


#include "java-template-proxy.h"
#include "messages.h"


JNIEXPORT jlong JNICALL
Java_org_syslog_1ng_LogTemplate_create_1new_1template_1instance(JNIEnv *env, jobject obj, jlong cfg_handle)
{
  GlobalConfig *cfg = (GlobalConfig *)cfg_handle;
  LogTemplate *template = log_template_new(cfg, NULL);
  return (jlong)template;
}


JNIEXPORT jboolean
JNICALL Java_org_syslog_1ng_LogTemplate_compile(JNIEnv *env, jobject obj, jlong template_handle,
                                                jstring template_string)
{
  LogTemplate *template = (LogTemplate *)template_handle;
  GError *error = NULL;
  const char *template_cstr = (*env)->GetStringUTFChars(env, template_string, NULL);
  gboolean result = log_template_compile(template, template_cstr, &error);
  if (!result)
    {
      msg_error("Can't compile template",
                evt_tag_str("template", template_cstr),
                evt_tag_str("error", error->message));
    }
  (*env)->ReleaseStringUTFChars(env, template_string, template_cstr);
  return result;
}

JNIEXPORT jstring JNICALL
Java_org_syslog_1ng_LogTemplate_format(JNIEnv *env, jobject obj, jlong template_handle, jlong msg_handle,
                                       jlong logtemplate_options_handle, jint tz, jint seqnum)
{
  LogTemplate *template = (LogTemplate *)template_handle;
  LogTemplateOptions *template_options = (LogTemplateOptions *)logtemplate_options_handle;
  LogMessage *msg = (LogMessage *)msg_handle;
  GString *formatted_message = g_string_sized_new(1024);
  jstring result = NULL;
  log_template_format(template, msg, template_options, tz, seqnum, NULL, formatted_message);
  result = (*env)->NewStringUTF(env, formatted_message->str);
  g_string_free(formatted_message, TRUE);
  return result;
}

JNIEXPORT void JNICALL
Java_org_syslog_1ng_LogTemplate_unref(JNIEnv *env, jobject obj, jlong template_handle)
{
  LogTemplate *template = (LogTemplate *)template_handle;
  log_template_unref(template);
}