File: util.c

package info (click to toggle)
uronode 2.15-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,112 kB
  • sloc: ansic: 6,354; sh: 289; makefile: 102
file content (122 lines) | stat: -rw-r--r-- 2,707 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <time.h>
#include <sys/file.h>

#include <sys/socket.h>
#include <netax25/ax25.h>
#include <netrose/rose.h>
#include <netax25/axlib.h>

#include "node.h"
#include "sysinfo.h"
#include "procinfo.h"

static char buf[256];
//char *HostName;
//char *Prompt;

void node_msg(const char *fmt, ...)
{
  va_list args;
	
  va_start(args, fmt);
  vsprintf(buf, fmt, args);
  va_end(args);
  axio_printf(NodeIo,"%s\n", buf);
}
/*
  void node_prompt(const char *fmt, ...)
  {
  va_list args;
  va_start(args, fmt);
  vsprintf(buf, fmt, args);
  va_end(args);
  if (User.ul_type == AF_NETROM) {
  axio_printf(NodeIo,"%s} ", NodeId);
  }
  if ((User.ul_type == AF_INET) || (User.ul_type == AF_INET6) && (check_perms(PERM_ANSI, 0L) != -1)) {
  axio_printf(NodeIo,"\n\e[01;31m%s\e[0m@\e[01;34m%s\e[0m:/uronode$ ",User.call, HostName);
  } 
  if ((User.ul_type == AF_INET) && (check_perms(PERM_ANSI, 0L) == -1)) {
  axio_printf(NodeIo,"\n%s@%s:/uronode$ ", User.call, HostName);
  }
  if (User.ul_type == AF_AX25) {
  axio_printf(NodeIo,"%s",Prompt);
  }
  if ((User.ul_type ==AF_INET6)  && (check_perms(PERM_ANSI, 0L) == -1)) {
  axio_printf(NodeIo, "\nSystemD - %s@%s: ",User.call, Hostname);
  }
  if ((User.ul_type ==AF_INET6)  && (check_perms(PERM_ANSI, 0L) != -1)) {
  axio_printf(NodeIo, "\n\e[01;31mSystemD \e[0m- \e[01;34m%s@\e[0m%s: ",User.call, Hostname);
  }
  }
*/
void node_perror(char *str, int err)
{
  int oldmode;

  oldmode = axio_eolmode(NodeIo, EOLMODE_TEXT);
  buf[0] = 0;
  if (str)
    strcpy(buf, str);
  if (str && err != -1)
    strcat(buf, ": ");
  if (err != -1)
    strcat(buf, strerror(err));
  axio_printf(NodeIo,"\nERROR; %s\n", buf);
  axio_eolmode(NodeIo, oldmode);
  axio_flush(NodeIo);
  node_log(LOGLVL_ERROR, buf);
}

char *print_node(const char *alias, const char *call)
{
  static char node[17];

  sprintf(node, "%s%s%s",
	  !strcmp(alias, "*") ? "##TEMP:" : alias,
	  !strcmp(alias, "*") ? "" : ":",
//	  !strcmp(call, "*") ? "" : call);
	  call);
  return node;
}

void node_log(int loglevel, const char *fmt, ...)
{
  static int opened = 0;
  va_list args;
  int pri;

  if (LogLevel < loglevel)
    return;
  if (!opened) {
    openlog("uronode", LOG_PID, LOG_LOCAL7);
    opened = 1;
  }
  switch (loglevel) {
  case LOGLVL_ERROR:
    pri = LOG_ERR;
    break;
  case LOGLVL_LOGIN:
    pri = LOG_NOTICE;
    break;
  case LOGLVL_GW:
    pri = LOG_INFO;
    break;
  default:
    pri = LOG_INFO;
    break;
  }
  va_start(args, fmt);
  vsnprintf(buf, sizeof(buf), fmt, args);
  buf[sizeof(buf) - 1] = 0;
  va_end(args);	
  syslog(pri, "%s", buf);

}