mm_msg.c revision d1d2228c6cf3ec632d28262810ab7902932a5d33
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <mms_list.h>
#include <mms_parser.h>
#include <libpq-fe.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <fcntl.h>
#include <libintl.h>
#include <locale.h>
#include <ctype.h>
#include <mms_trace.h>
#include <mms_strapp.h>
#include <msg_sub.h>
#include <mms_cat.h>
#include "mm_db.h"
#include "mm.h"
#include "mm_util.h"
#include "mm_commands.h"
#include "mm_sql.h"
#include "mm_sql_impl.h"
#define MESS_EMERG_STR "emergency"
#define MESS_ALERT_STR "alert"
#define MESS_CRIT_STR "critical"
#define MESS_ERROR_STR "error"
#define MESS_WARN_STR "warning"
#define MESS_NOTICE_STR "notice"
#define MESS_INFO_STR "information"
#define MESS_DEBUG_STR "debug"
#define MESS_DEVP_STR "developer"
#define MESS_OPER_STR "operator"
#define MESS_ADMIN_STR "administrator"
#define MESS_LOG_STR "log"
typedef struct {
char *msg_client;
char *msg_instance;
char *msg_host;
int slog_fd;
char slog_fname[PATH_MAX];
int slog_sync;
int slog_count;
/* message */
/* system log file */
static void mm_slog_close(void);
static void mm_slog_flush(void);
/* utility */
static mm_msg_data_t mm_msg_data;
int
{
mms_cat_open();
if (mm_slog_open(db)) {
return (1);
}
return (0);
}
void
mm_message_close(void)
{
}
int
{
/*
* Handle device manager change tracing private command
*/
return (MM_ACCEPT_NEEDED);
return (MM_NO_DISPATCH);
}
if (mm_has_depend(cmd)) {
return (MM_DEPEND_DONE);
}
return (MM_CMD_DONE);
}
return (MM_CMD_ERROR);
}
return (MM_CMD_ERROR);
}
int
{
char *buf;
/*
* Add change tracing private command to command queue
*/
"\"TraceLevel\",\"TraceFileSize\" from \"LM\" where "
return (1);
}
return (1);
}
"set[\"LMMessageLevel\" \"%s\" "
"\"TraceLevel\" \"%s\" "
"\"TraceFileSize\" \"%s\"];",
task,
"\"TraceLevel\",\"TraceFileSize\" from \"DM\" where "
return (1);
}
return (1);
}
"set[\"DMMessageLevel\" \"%s\" "
"\"TraceLevel\" \"%s\" "
"\"TraceFileSize\" \"%s\"];",
task,
}
return (0);
}
static int
{
int rc = 0;
/* find client work area */
/* only connected clients have work areas */
/* send private command to change tracing */
break;
}
}
}
return (rc);
}
int
{
char *query;
int row;
char *client;
char *inst;
char *level;
char *fsize;
int num;
/*
* Change mm or device manager tracing
*/
/* clear path matching */
/* sql command */
"mm_msg_set_tracing: "
"out of mem creating source list");
return (1);
}
query = "select distinct \"LM\".\"LibraryName\","
"\"LM\".\"LMName\" from ";
"mm_msg_set_tracing: "
"db error creating helper functions");
return (1);
}
return (1);
}
/* see if any lms are configed */
"from \"LM\" limit 1;") != MM_DB_DATA) {
return (1);
}
/* no lms configured or specified */
return (0);
}
/* lm not found */
return (1);
}
row,
inst);
return (1);
}
}
/* clear path matching */
/* sql command */
"mm_msg_set_tracing: "
"out of mem creating source list");
return (1);
}
query = "select distinct \"DM\".\"DriveName\","
"\"DM\".\"DMName\" from ";
"mm_msg_set_tracing: "
"db error creating helper functions");
return (1);
}
return (1);
}
/* see if any dms are configed */
"from \"DM\" limit 1;") != MM_DB_DATA) {
return (1);
}
/* no dms configed or specified */
return (0);
}
/* dm not found */
return (1);
}
row,
inst);
return (1);
}
}
"\"TraceLevel\",\"TraceFileSize\" from \"SYSTEM\";")
!= MM_DB_DATA) {
return (1);
}
return (1);
}
if (mms_trace_set_fsize(fsize)) {
return (1);
}
if (mms_trace_str_filter(level)) {
"invalid mms_trace filter %s", level);
return (1);
}
} else {
return (1);
}
return (0);
return (1);
}
int
{
/*
* Device manager message command
*/
/* message command */
return (MM_CMD_ERROR);
}
/* add message to system log file */
return (MM_CMD_ERROR);
}
/* add message to message fifo */
return (MM_CMD_ERROR);
}
return (MM_CMD_DONE);
return (MM_CMD_ERROR);
return (MM_CMD_ERROR);
}
static int
{
/*
* Tell caller if command contains message-clause
*/
return (1); /* command has message-clause */
}
return (0);
}
int
{
int rc;
/*
* Handle message in non-message command
*/
return (0); /* already handled this command's message */
}
return (0); /* ignore messages in mmp commands */
}
if (mm_msg_avail(cmd) == 0)
return (0); /* command does not have a message */
return (0); /* failed to parse command message */
/* command response */
switch (response.response_type) {
case MM_RESPONSE_ERROR:
break;
case MM_RESPONSE_ACCEPTED:
case MM_RESPONSE_UNACCEPTABLE:
case MM_RESPONSE_SUCCESS:
case MM_RESPONSE_CANCELLED:
default:
break;
}
} else {
/* not command response */
}
}
return (rc);
}
int
int messageid, ...)
{
int rc;
}
return (rc);
}
int
mm_msg_exists(int message_id)
{
char *fmt;
return (0);
}
return (1);
}
int
{
char *p;
char *fmt;
/*
* Parse and localize command's message-clause
*/
/* message-clause */
/* locale-text-clause */
MMS_PN_CLAUSE, &count)) {
NOT_FOUND();
NOT_FOUND();
}
/* lookup localized message */
/* no catalog message found so use default if it exists */
}
fmt = "\0";
}
}
/* copy localized message */
/* arg-clause */
MMS_PN_CLAUSE, NULL)) {
/* save arguments list */
/* substitue each text argument with value */
NOT_FOUND();
}
return (1);
}
}
}
return (0);
return (1);
return (1);
}
static int
{
int sys_msg_limit;
int sys_msg_count;
char *localized;
/*
* Add message to mm's message fifo
*/
"\"SystemMessageLimit\",\"SystemMessageCount\" from "
"\"SYSTEM\";") != MM_DB_DATA) {
return (1);
}
return (1);
}
return (0);
}
if (sys_msg_limit == 0) {
return (0);
}
} else {
}
msg_localized)) == NULL) {
return (1);
}
if (sys_msg_count < sys_msg_limit) {
"(\"MessageID\","
"\"MessageSenderType\","
"\"MessageSenderName\","
"\"MessageSenderInstance\","
"\"MessageConnectionID\","
"\"MessageLevel\","
"\"MessageManufacturer\","
"\"MessageModel\","
"\"MessageNumber\","
"\"MessageText\","
"\"MessageTimeCreated\","
"\"MessageHost\") "
"values ('%s','%s','%s','%s',%s,"
"'%s','%s','%s','%d','%s','%s','%s');",
cid,
return (1);
}
"\"SystemMessageCount\" = '%d';",
return (1);
}
return (1);
}
} else {
"\"MessageID\" = '%s',"
"\"MessageSenderType\" = '%s',"
"\"MessageSenderName\" = '%s',"
"\"MessageSenderInstance\" = '%s',"
"\"MessageConnectionID\" = %s,"
"\"MessageLevel\" = '%s',"
"\"MessageManufacturer\" = '%s',"
"\"MessageModel\" = '%s',"
"\"MessageNumber\" = '%d',"
"\"MessageText\" = '%s',"
"\"MessageTimeCreated\" = '%s',"
"\"MessageHost\" = '%s' "
"where \"MessageID\" = (select \"MessageID\" from "
"\"MESSAGE\" order by \"MessageTimeCreated\" limit 1);",
cid,
return (1);
}
return (1);
}
}
return (0);
}
int
{
int limit;
int count;
int actual_count;
/*
* Change message fifo size.
*/
"\"SystemMessageCount\" from \"SYSTEM\";") != MM_DB_DATA) {
return (1);
}
"from \"MESSAGE\";") != MM_DB_DATA) {
return (1);
}
if (count != actual_count) {
}
/* remove excess messages from message fifo */
/* remove oldest message */
"where \"MessageID\" = (select \"MessageID\" "
"from \"MESSAGE\" "
"order by \"MessageTimeCreated\" "
"limit 1);") != MM_DB_OK) {
return (1);
}
return (1);
}
count--;
}
if (count < 0) {
count = 0;
}
return (1);
}
return (0);
}
/*
* System Log File
*/
static int
{
"\"SYSTEM\";") != MM_DB_DATA) {
return (1);
}
return (1);
}
if (mm_slog_set_sync(db)) {
return (1);
}
if (mm_slog_set_level(db)) {
return (1);
}
if (mm_slog_set_size(db)) {
return (1);
}
if (mm_msg_data.slog_fd < 0) {
return (1);
}
return (1);
}
return (0);
}
static void
mm_slog_close(void)
{
}
static void
mm_slog_flush(void)
{
}
static int
{
char *buf;
int len;
char *localized;
/*
* Write message to system log file.
*/
return (1); /* invalid severity */
}
return (0); /* not logging this severity */
}
return (1); /* mms_escape sequence removal failed */
}
if ((buf = mms_strnew(
"%s %s %.2s %s %s %s %d %s\n",
return (1);
}
}
/* flush system log file to disk */
mm_msg_data.slog_count = 0;
}
return (0);
}
int
{
int rc;
return (rc);
}
int
{
"\"SYSTEM\";") != MM_DB_DATA) {
return (1);
}
return (1);
}
return (0);
}
int
{
char *level;
"\"SYSTEM\";") != MM_DB_DATA) {
return (1);
}
return (1);
}
return (0);
}
int
{
int rc;
char *size;
"\"SYSTEM\";") != MM_DB_DATA) {
return (1);
}
return (1);
}
}
return (rc);
}
/*
* Get message-clause strings
*/
void
int messageid, ...)
{
char *buf;
char *text;
eclass);
ecode);
/*
* Get final-command response error with message-clause
*/
}
}
return;
}
static mm_msg_sev_t
mm_msg_str2sev(char *serverity)
{
/* convert mms severity string to enum. */
rc = MESS_EMERG;
rc = MESS_ALERT;
rc = MESS_ERROR;
rc = MESS_NOTICE;
rc = MESS_DEBUG;
} else {
}
return (rc);
}
/* Convert mms severity enum to string. */
char *
{
char *rc;
if (severity == MESS_EMERG) {
rc = MESS_EMERG_STR;
} else if (severity == MESS_ALERT) {
rc = MESS_ALERT_STR;
rc = MESS_CRIT_STR;
} else if (severity == MESS_ERROR) {
rc = MESS_ERROR_STR;
rc = MESS_WARN_STR;
} else if (severity == MESS_NOTICE) {
rc = MESS_INFO_STR;
} else if (severity == MESS_DEBUG) {
rc = MESS_DEBUG_STR;
} else {
rc = MESS_DEVP_STR;
}
return (rc);
}
/* Convert message cmd who enum to string. */
static char *
{
char *rc;
rc = MESS_OPER_STR;
} else if (who == MESS_ADMIN) {
rc = MESS_ADMIN_STR;
} else {
rc = MESS_LOG_STR;
}
return (rc);
}
static mm_msg_who_t
mm_msg_str2who(char *who)
{
rc = MESS_ADMIN;
} else {
}
return (rc);
}
/* Convert mms protocol language enum to message component string. */
char *
{
char *rc;
if (lang == MM_LANG_DMP) {
rc = MESS_DM_STR;
} else if (lang == MM_LANG_LMP) {
rc = MESS_LM_STR;
} else {
rc = MESS_AI_STR;
}
return (rc);
}
static void
{
int rc = 1;
char date[100];
int i;
char *p;
/*
* Get timestamp with 3 digit millisecond
*/
"timestamp(3)) as ts;") != MM_DB_DATA) {
rc = 1;
rc = 1;
} else {
/* pad milliseconds with zeros */
for (i = 1; i <= 3; i++) {
if (!isdigit(*(p+i))) {
*(p+i) = '0';
}
}
} else {
/* zero milliseconds */
}
rc = 0;
}
}
if (rc) {
/* failed to get time from db so use system time */
}
}