Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_log_deprecated.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * AFW XACML - Basic Log Implementation.
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 
15 #define _AFW_LOGIMPL
16 #include "afw_log_deprecated.h"
17 
18 static void log_release(
20 );
21 
22 static void log_message_v(
24  apr_pool_t *temp_pool,
25  const afw_utf8_z_t *prefix,
26  const afw_utf8_z_t *fmt,
27  va_list args
28 );
29 
30 static void log_error_v(
32  apr_pool_t *temp_pool,
33  const afw_utf8_z_t *prefix,
34  const afw_utf8_z_t *fmt,
35  va_list args);
36 
37 static void log_trace_v(
39  apr_pool_t *temp_pool,
40  const afw_utf8_z_t *prefix,
41  const afw_utf8_z_t *fmt,
42  va_list args);
43 
44 static const afw_log_deprecated_inf_t afw_log_deprecated_inf = {
45  &log_release,
46  &log_message_v,
47  &log_error_v,
48  &log_trace_v
49 };
50 
53  apr_pool_t *log_pool;
54  apr_file_t *log_file;
55  const char *encoding;
57 
60 /* Create a log. */
63  apr_pool_t *temp_pool,
64  apr_pool_t *module_pool,
65  apr_file_t *log_file,
66  const char *encoding)
67 {
68  afw_log_deprecated_internal_t *self = NULL;
69  apr_pool_t *log_pool;
70 
71  /* Create subpool for log. */
72  if (apr_pool_create(&log_pool,module_pool) != APR_SUCCESS) {
73  apr_file_printf(log_file, AFW_MESSAGE_PREFIX
74  "apr_pool_create() failed in afw_create_log_deprecated().");
75  return NULL;
76  };
77 
78  /* Get storage and initialize afw_log_deprecated_t struct. */
79  self = (afw_log_deprecated_internal_t *)apr_pcalloc(log_pool, sizeof(afw_log_deprecated_internal_t));
80  self->c.inf = &afw_log_deprecated_inf;
81  self->log_pool = log_pool;
82  self->log_file = log_file;
83  self->encoding = apr_pstrdup(log_pool, encoding);
84 
85  /* Return with rc=0. */
86  return (afw_log_deprecated_t *)self;
87 }
88 
89 /* Release a log. */
90 void log_release(afw_log_deprecated_t *log)
91 {
93 
94  /* Destroy log_pool and clear pointer. */
95  apr_pool_destroy(self->log_pool);
96 }
97 
98 void log_message_v(
100  apr_pool_t *temp_pool,
101  const afw_utf8_z_t *prefix,
102  const afw_utf8_z_t *fmt,
103  va_list args)
104 {
106  apr_file_puts(apr_pvsprintf(temp_pool, (const char *)fmt, args), self->log_file);
107  apr_file_putc('\n', self->log_file);
108 }
109 
110 void log_error_v(
112  apr_pool_t *temp_pool,
113  const afw_utf8_z_t *prefix,
114  const afw_utf8_z_t *fmt,
115  va_list args)
116 {
118  apr_file_puts(apr_pvsprintf(temp_pool, (const char *)fmt, args), self->log_file);
119  apr_file_putc('\n', self->log_file);
120 }
121 
122 void log_trace_v(
124  apr_pool_t *temp_pool,
125  const afw_utf8_z_t *prefix,
126  const afw_utf8_z_t *fmt,
127  va_list args)
128 {
130  apr_file_puts(apr_pvsprintf(temp_pool, (const char *)fmt, args), self->log_file);
131  apr_file_putc('\n', self->log_file);
132 }
AFW_DEFINE(const afw_object_t *)
Header file for afw_log_deprecated.c.
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
#define AFW_MESSAGE_PREFIX
Macro to produce prefix for AFW messages.
Definition: afw_common.h:636
afw_create_log_deprecated(apr_pool_t *temp_pool, apr_pool_t *module_pool, apr_file_t *log_file, const char *encoding)
Create a basic log.
afw_log_deprecated_t interface.
Public afw_log_deprecated_t object.