| 1 |
/* |
| 2 |
Copyright (C) 1996-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
|
| 21 |
#include <intalkd.h> |
| 22 |
|
| 23 |
#define D(c) #c |
| 24 |
#define NITEMS(a) (sizeof (a) / sizeof ((a)[0])) |
| 25 |
|
| 26 |
static const char *message_types[] = { |
| 27 |
D (LEAVE_INVITE), |
| 28 |
D (LOOK_UP), |
| 29 |
D (DELETE), |
| 30 |
D (ANNOUNCE) |
| 31 |
}; |
| 32 |
|
| 33 |
static const char *answers[] = { |
| 34 |
D (SUCCESS), |
| 35 |
D (NOT_HERE), |
| 36 |
D (FAILED), |
| 37 |
D (MACHINE_UNKNOWN), |
| 38 |
D (PERMISSION_DENIED), |
| 39 |
D (UNKNOWN_REQUEST), |
| 40 |
D (BADVERSION), |
| 41 |
D (BADADDR), |
| 42 |
D (BADCTLADDR) |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
static const char * |
| 47 |
_xlat_num (int num, const char *array[], int size) |
| 48 |
{ |
| 49 |
static char buf[64]; |
| 50 |
|
| 51 |
if (num >= size) |
| 52 |
{ |
| 53 |
snprintf (buf, sizeof buf, "%d", num); |
| 54 |
return buf; |
| 55 |
} |
| 56 |
else |
| 57 |
return array[num]; |
| 58 |
} |
| 59 |
|
| 60 |
int |
| 61 |
print_request (const char *cp, CTL_MSG *mp) |
| 62 |
{ |
| 63 |
syslog (LOG_DEBUG, "%s: %s: id %d, l_user %s, r_user %s, r_tty %s", |
| 64 |
cp, _xlat_num (mp->type, message_types, NITEMS (message_types)), |
| 65 |
mp->id_num, mp->l_name, mp->r_name, mp->r_tty); |
| 66 |
return 0; |
| 67 |
} |
| 68 |
|
| 69 |
int |
| 70 |
print_response (const char *cp, CTL_RESPONSE *rp) |
| 71 |
{ |
| 72 |
syslog (LOG_DEBUG, "%s: %s: %s, id %d", |
| 73 |
cp, |
| 74 |
_xlat_num (rp->type, message_types, NITEMS (message_types)), |
| 75 |
_xlat_num (rp->answer, answers, NITEMS (answers)), |
| 76 |
ntohl (rp->id_num)); |
| 77 |
return 0; |
| 78 |
} |