/[radius]/radius/lib/printutmp.c
ViewVC logotype

Diff of /radius/lib/printutmp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by gray, Wed Jan 8 15:23:08 2003 UTC revision 1.8 by gray, Wed Apr 30 08:38:29 2003 UTC
# Line 1  Line 1 
1  /* This file is part of GNU RADIUS.  /* This file is part of GNU Radius.
2     Copyright (C) 2002, Free Software Foundation     Copyright (C) 2000,2001,2002,2003 Sergey Poznyakoff
3        
4     This program is free software; you can redistribute it and/or modify     GNU Radius is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.     (at your option) any later version.
8        
9     This program is distributed in the hope that it will be useful,     GNU Radius is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.     GNU General Public License for more details.
13        
14     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software     along with GNU Radius; if not, write to the Free Software Foundation,
16     Foundation, Inc., 59 Temple Place - Suite 330, Boston,     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
    MA 02111-1307, USA. */  
17    
18  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
19  # include <config.h>  # include <config.h>
# Line 92  static char *key_empty(format_key_t *key Line 91  static char *key_empty(format_key_t *key
91  static int key_nodomain(format_key_t *key);  static int key_nodomain(format_key_t *key);
92    
93  void  void
94  format_key_free(key)  format_key_free(format_key_t *key)
         format_key_t *key;  
95  {  {
96          format_key_t *next;          format_key_t *next;
97          while (key) {          while (key) {
# Line 106  format_key_free(key) Line 104  format_key_free(key)
104  }  }
105    
106  char *  char *
107  format_key_lookup(key, name)  format_key_lookup(format_key_t *key, char *name)
         format_key_t *key;  
         char *name;  
108  {  {
109          for (; key; key = key->next) {          for (; key; key = key->next) {
110                  if (strcmp(key->name, name) == 0)                  if (strcmp(key->name, name) == 0)
# Line 118  format_key_lookup(key, name) Line 114  format_key_lookup(key, name)
114  }  }
115    
116  void  void
117  form_free(form)  form_free(format_data_t *form)
         format_data_t *form;  
118  {  {
119          format_data_t *next;          format_data_t *next;
120    
# Line 144  form_free(form) Line 139  form_free(form)
139  }  }
140    
141  static int  static int
142  key_align(key)  key_align(format_key_t *key)
         format_key_t *key;  
143  {  {
144          char *p = format_key_lookup(key, "right");          char *p = format_key_lookup(key, "right");
145          return p ? ALIGN_RIGHT : ALIGN_LEFT;          return p ? ALIGN_RIGHT : ALIGN_LEFT;
146  }  }
147    
148  static char *  static char *
149  key_date_format(key)  key_date_format(format_key_t *key)
         format_key_t *key;  
150  {  {
151          char *p = format_key_lookup(key, "format");          char *p = format_key_lookup(key, "format");
152          return p ? p : printutmp_date_format;          return p ? p : printutmp_date_format;
153  }  }
154    
155  static char *  static char *
156  key_empty(key)  key_empty(format_key_t *key)
         format_key_t *key;  
157  {  {
158          char *p = format_key_lookup(key, "empty");          char *p = format_key_lookup(key, "empty");
159          return p ? p : printutmp_empty_string;          return p ? p : printutmp_empty_string;
160  }  }
161    
162  static int  static int
163  key_nodomain(key)  key_nodomain(format_key_t *key)
         format_key_t *key;  
164  {  {
165          char *p = format_key_lookup(key, "nodomain");          char *p = format_key_lookup(key, "nodomain");
166          return p ? 1 : printutmp_ip_nodomain;          return p ? 1 : printutmp_ip_nodomain;
167  }  }
168    
169  int  int
170  output_string(string, width, align)  output_string(char *string, int width, int align)
         char *string;  
         int width;  
         int align;  
171  {  {
172          if (width == 0)          if (width == 0)
173                  width = printf("%s", string);                  width = printf("%s", string);
# Line 191  output_string(string, width, align) Line 179  output_string(string, width, align)
179  }  }
180    
181  int  int
182  output_string_key(string, width, key)  output_string_key(char *string, int width, format_key_t *key)
         char *string;  
         int width;  
         format_key_t *key;  
183  {  {
184          if (strlen(string) == 0)          if (strlen(string) == 0)
185                  string = key_empty(key);                  string = key_empty(key);
# Line 203  output_string_key(string, width, key) Line 188  output_string_key(string, width, key)
188    
189    
190  int  int
191  output_tab(column, tabstop)  output_tab(int column, int tabstop)
         int column;  
         int tabstop;  
192  {  {
193          int goal = (((column + TAB_SIZE - 1) / TAB_SIZE) + tabstop) * TAB_SIZE;          int goal = (((column + TAB_SIZE - 1) / TAB_SIZE) + tabstop) * TAB_SIZE;
194          for (;column < goal; column++)          for (;column < goal; column++)
# Line 214  output_tab(column, tabstop) Line 197  output_tab(column, tabstop)
197  }  }
198    
199  char *  char *
200  get_hostname(ipaddr, nodomain, buf, size)  get_hostname(UINT4 ipaddr, int nodomain, char *buf, size_t size)
         UINT4 ipaddr;  
         int nodomain;  
         char *buf;  
         size_t size;  
201  {  {
202          if (ipaddr == 0 || ipaddr == (UINT4)-1 || ipaddr == (UINT4)-2)          if (ipaddr == 0 || ipaddr == (UINT4)-1 || ipaddr == (UINT4)-2)
203                  return "";                  return "";
# Line 239  get_hostname(ipaddr, nodomain, buf, size Line 218  get_hostname(ipaddr, nodomain, buf, size
218  }  }
219    
220  int  int
221  output_hostname(ip, width, key)  output_hostname(UINT4 ip, int width, format_key_t *key)
         UINT4 ip;  
         int width;  
         format_key_t *key;  
222  {  {
223          char buf[80];          char buf[80];
224          return output_string_key(get_hostname(ip, key_nodomain(key),          return output_string_key(get_hostname(ip, key_nodomain(key),
# Line 251  output_hostname(ip, width, key) Line 227  output_hostname(ip, width, key)
227    
228  /*FIXME: ignores key */  /*FIXME: ignores key */
229  int  int
230  output_time(t, width, key)  output_time(time_t t, int width, format_key_t *key)
         time_t t;  
         int width;  
         format_key_t *key;  
231  {  {
232          int d,h,m,s;          int d,h,m,s;
233                    
# Line 277  output_time(t, width, key) Line 250  output_time(t, width, key)
250    
251  /*ARGSUSED*/  /*ARGSUSED*/
252  int  int
253  login_fh(outbytes, width, key, up)  login_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
254  {  {
255          return output_string_key(up->login, width, key);          return output_string_key(up->login, width, key);
256  }  }
257    
258  /*ARGSUSED*/  /*ARGSUSED*/
259  int  int
260  orig_login_fh(outbytes, width, key, up)  orig_login_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
261  {  {
262          return output_string_key(up->orig_login, width, key);          return output_string_key(up->orig_login, width, key);
263  }  }
264    
265  /*ARGSUSED*/  /*ARGSUSED*/
266  int  int
267  gecos_fh(outbytes, width, key, up)  gecos_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
268  {  {
269          struct passwd pw, *pwd;          struct passwd pw, *pwd;
270          char *s;          char *s;
# Line 320  gecos_fh(outbytes, width, key, up) Line 281  gecos_fh(outbytes, width, key, up)
281    
282  /*ARGSUSED*/  /*ARGSUSED*/
283  int  int
284  nas_port_fh(outbytes, width, key, up)  nas_port_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
285  {  {
286          char buf[6];          char buf[6];
287                    
# Line 334  nas_port_fh(outbytes, width, key, up) Line 291  nas_port_fh(outbytes, width, key, up)
291    
292  /*ARGSUSED*/  /*ARGSUSED*/
293  int  int
294  session_id_fh(outbytes, width, key, up)  session_id_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
295  {  {
296          return output_string_key(up->session_id, width, key);          return output_string_key(up->session_id, width, key);
297  }  }
298    
299  /*ARGSUSED*/  /*ARGSUSED*/
300  int  int
301  nas_address_fh(outbytes, width, key, up)  nas_address_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
302  {  {
303          if (printutmp_use_naslist) {          if (printutmp_use_naslist) {
304                  NAS *nas;                  NAS *nas;
# Line 365  nas_address_fh(outbytes, width, key, up) Line 314  nas_address_fh(outbytes, width, key, up)
314    
315  /*ARGSUSED*/  /*ARGSUSED*/
316  int  int
317  framed_address_fh(outbytes, width, key, up)  framed_address_fh(int outbytes, int width, format_key_t *key,
318          int outbytes;                    struct radutmp *up)
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
319  {  {
320          return output_hostname(up->framed_address, width, key);          return output_hostname(up->framed_address, width, key);
321  }  }
322    
323  /*ARGSUSED*/  /*ARGSUSED*/
324  int  int
325  protocol_fh(outbytes, width, key, up)  protocol_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
326  {  {
327          DICT_VALUE *dval = value_lookup(up->proto, "Framed-Protocol");          DICT_VALUE *dval = value_lookup(up->proto, "Framed-Protocol");
328          char buf[80];          char buf[80];
# Line 397  protocol_fh(outbytes, width, key, up) Line 339  protocol_fh(outbytes, width, key, up)
339    
340  /*ARGSUSED*/  /*ARGSUSED*/
341  int  int
342  time_fh(outbytes, width, key, up)  time_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
343  {  {
344          char buf[80];          char buf[80];
345                    
# Line 411  time_fh(outbytes, width, key, up) Line 349  time_fh(outbytes, width, key, up)
349    
350  /*ARGSUSED*/  /*ARGSUSED*/
351  int  int
352  duration_fh(outbytes, width, key, up)  duration_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
353  {  {
354          return output_time((up->type == P_IDLE) ?          return output_time((up->type == P_IDLE) ?
355                             up->duration : time(NULL) - up->time,                             up->duration : time(NULL) - up->time,
# Line 424  duration_fh(outbytes, width, key, up) Line 358  duration_fh(outbytes, width, key, up)
358    
359  /*ARGSUSED*/  /*ARGSUSED*/
360  int  int
361  delay_fh(outbytes, width, key, up)  delay_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
362  {  {
363          return output_time(up->delay, width, key);          return output_time(up->delay, width, key);
364  }  }
365    
366  /*ARGSUSED*/  /*ARGSUSED*/
367  int  int
368  port_type_fh(outbytes, width, key, up)  port_type_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
369  {  {
370          DICT_VALUE *dval = value_lookup(up->porttype, "NAS-Port-Type");          DICT_VALUE *dval = value_lookup(up->porttype, "NAS-Port-Type");
371          char buf[80];          char buf[80];
# Line 456  port_type_fh(outbytes, width, key, up) Line 382  port_type_fh(outbytes, width, key, up)
382    
383  /*ARGSUSED*/  /*ARGSUSED*/
384  int  int
385  clid_fh(outbytes, width, key, up)  clid_fh(int outbytes, int width, format_key_t *key, struct radutmp *up)
         int outbytes;  
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
386  {  {
387          return output_string_key(up->caller_id, width, key);          return output_string_key(up->caller_id, width, key);
388  }  }
389    
390  /*ARGSUSED*/  /*ARGSUSED*/
391  int  int
392  realm_address_fh(outbytes, width, key, up)  realm_address_fh(int outbytes, int width, format_key_t *key,
393          int outbytes;                   struct radutmp *up)
         int width;  
         format_key_t *key;  
         struct radutmp *up;  
394  {  {
395          if (up->realm_address == 0)          if (up->realm_address == 0)
396                  return output_string_key("", width, key);                  return output_string_key("", width, key);
# Line 505  static struct { Line 424  static struct {
424  };  };
425    
426  static radutent_fh_t  static radutent_fh_t
427  _lookup(name)  _lookup(char *name)
         char *name;  
428  {  {
429          int i;          int i;
430          for (i = 0; handlers[i].name; i++)          for (i = 0; handlers[i].name; i++)
# Line 516  _lookup(name) Line 434  _lookup(name)
434  }  }
435    
436  static char *  static char *
437  parse_string0(fmt, form, cond, closure)  parse_string0(char *fmt, format_data_t *form, int (*cond)(), void *closure)
         char *fmt;  
         format_data_t *form;  
         int (*cond)();  
         void *closure;  
438  {  {
439          char *p;          char *p;
440                    
# Line 531  parse_string0(fmt, form, cond, closure) Line 445  parse_string0(fmt, form, cond, closure)
445                          case 'a':                          case 'a':
446                                  c = '\a';                                  c = '\a';
447                                  break;                                  break;
448                                    
449                          case 'b':                          case 'b':
450                                  c = '\b';                                  c = '\b';
451                                  break;                                  break;
452                                    
453                          case 'e':                          case 'e':
454                                  c = '\033';                                  c = '\033';
455                                  break;                                  break;
456                                    
457                          case 'f':                          case 'f':
458                                  c = '\f';                                  c = '\f';
459                                  break;                                  break;
460                                    
461                          case 'n':                          case 'n':
462                                  c = '\n';                                  c = '\n';
463                                  break;                                  break;
464                                    
465                          case 't':                          case 't':
466                                  c = '\t';                                  c = '\t';
467                                  break;                                  break;
468                                    
469                          case 'r':                          case 'r':
470                                  c = '\r';                                  c = '\r';
471                                  break;                                  break;
472                                    
473                          case 'v':                          case 'v':
474                                  c = '\v';                                  c = '\v';
475                                  break;                                  break;
476                                    
477                          default:                          default:
478                                  c = *p;                                  c = *p;
479                          }                          }
# Line 566  parse_string0(fmt, form, cond, closure) Line 488  parse_string0(fmt, form, cond, closure)
488  }  }
489    
490  static int  static int
491  _is_closing_quote(closure, p)  _is_closing_quote(void *closure, char *p)
         void *closure;  
         char *p;  
492  {  {
493          return *(char*)closure == *p;          return *(char*)closure == *p;
494  }  }
495    
496  static int  static int
497  parse_quote(fmtp, form)  parse_quote(char **fmtp, format_data_t *form)
         char **fmtp;  
         format_data_t *form;  
498  {  {
499          char *p;          char *p;
500          p = parse_string0(*fmtp + 1, form, _is_closing_quote, *fmtp);            p = parse_string0(*fmtp + 1, form, _is_closing_quote, *fmtp);  
# Line 592  parse_quote(fmtp, form) Line 510  parse_quote(fmtp, form)
510    
511  /*ARGSUSED*/  /*ARGSUSED*/
512  static int  static int
513  _is_delim(closure, p)  _is_delim(void *closure, char *p)
         void *closure;  
         char *p;  
514  {  {
515          return *p == '(';          return *p == '(';
516  }  }
517    
518  static int  static int
519  parse_string(fmtp, form)  parse_string(char **fmtp, format_data_t *form)
         char **fmtp;  
         format_data_t *form;  
520  {  {
521          char *p;          char *p;
522          p = parse_string0(*fmtp, form, _is_delim, NULL);          p = parse_string0(*fmtp, form, _is_delim, NULL);
# Line 611  parse_string(fmtp, form) Line 525  parse_string(fmtp, form)
525  }  }
526    
527  static char *  static char *
528  get_token(fmtp)  get_token(char **fmtp)
         char **fmtp;  
529  {  {
530          char *p;          char *p;
531    
# Line 632  get_token(fmtp) Line 545  get_token(fmtp)
545  }  }
546    
547  static int  static int
548  parse_form(fmtp, form)  parse_form(char **fmtp, format_data_t *form)
         char **fmtp;  
         format_data_t *form;  
549  {  {
550          char *formname, *p;          char *formname, *p;
551          format_key_t *key_head, *key_tail;          format_key_t *key_head, *key_tail;
# Line 722  parse_form(fmtp, form) Line 633  parse_form(fmtp, form)
633  }  }
634    
635  format_data_t *  format_data_t *
636  radutent_compile_form(fmt)  radutent_compile_form(char *fmt)
         char *fmt;  
637  {  {
638          format_data_t *form_head = NULL, *form_tail;          format_data_t *form_head = NULL, *form_tail;
639                    
# Line 758  radutent_compile_form(fmt) Line 668  radutent_compile_form(fmt)
668  }  }
669    
670  int  int
671  radutent_print(form, up, newline)  radutent_print(format_data_t *form, struct radutmp *up, int newline)
         format_data_t *form;  
         struct radutmp *up;  
         int newline;  
672  {  {
673          int i;          int i;
674          int outbytes = 0;          int outbytes = 0;
# Line 798  radutent_print(form, up, newline) Line 705  radutent_print(form, up, newline)
705  }  }
706    
707  void  void
708  printutmp_header(form)  printutmp_header(format_data_t *form)
         format_data_t *form;  
709  {  {
710          int i, outbytes = 0;          int i, outbytes = 0;
711          format_data_t *p;          format_data_t *p;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26