1 /******************************************************************************
2 * FIDOCONFIG --- library for fidonet configs
3 ******************************************************************************
4 * linked.c : Show linked areas for link.
5 *
6 * Copyright (C) Husky developers team
7 *
8 *
9 * This file is part of FIDOCONFIG library (part of the Husky FIDOnet
10 * software project)
11 *
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published
14 * by the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * FIDOCONFIG library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with FIDOCONFIG library; see the file COPYING. If not, write
24 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA
25 *
26 * See also http://www.gnu.org
27 *****************************************************************************
28 * $Id$
29 */
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <huskylib/huskylib.h>
34 #include "fidoconf.h"
35 #include "arealist.h"
36 #include "common.h"
37
38 #ifndef VERSION_H
39 #define VERSION_H
40
41 #include "version.h"
42 #include "../cvsdate.h"
43
44 #endif
45
46 s_fidoconfig *cfg;
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
subscribeCheck(s_area area,s_link * link)52 int subscribeCheck(s_area area, s_link *link)
53 {
54 int found = 0;
55 if (isLinkOfArea(link, &area)) return 0;
56
57 if (area.group) {
58 if (cfg->numPublicGroup)
59 found = grpInArray(area.group,cfg->PublicGroup,cfg->numPublicGroup);
60 if (!found && link->numAccessGrp)
61 found = grpInArray(area.group,link->AccessGrp,link->numAccessGrp);
62 } else found = 1;
63
64 if (!found){
65 return 2;
66 }
67 if (area.levelwrite > link->level && area.levelread > link->level){
68 return 2;
69 }
70 return 1;
71 }
72
linked(s_link * link)73 int linked(s_link *link) {
74 unsigned int i, n, rc;
75
76 if (!link) return -1;
77
78 for (i=n=0; i<cfg->echoAreaCount; i++) {
79 rc=subscribeCheck(cfg->echoAreas[i], link);
80 if (rc==0) {
81 if(!n)
82 printf("\n%s areas on %s:\n\n",((link->Pause & ECHOAREA) == ECHOAREA) ? "Passive" : "Active", aka2str(link->hisAka));
83 printf(" %s\n", cfg->echoAreas[i].areaName);
84 n++;
85 }
86 }
87 if( n ) printf("\n%u areas linked\n\n", n);
88 else printf("%s not linked to any area\n", aka2str(link->hisAka));
89
90 return 0;
91 }
92
main(int argc,char ** argv)93 int main(int argc, char **argv) {
94
95 { char *temp;
96 printf("%s\n\n", temp=GenVersionStr( "linked", FC_VER_MAJOR, FC_VER_MINOR,
97 FC_VER_PATCH, FC_VER_BRANCH, cvs_date ));
98 nfree(temp);
99 }
100
101 cfg = readConfig(NULL);
102 if (argc <2) {
103 printf("\tShow linked areas for link\n\n");
104 printf(" Usage: linked <Address> [<Address> ... ]\n");
105 } else
106 for(; --argc; ) {
107 if(linked(getLink(cfg, argv[argc] ))) {
108 hs_addr paddr;
109 memset(&paddr, 0, sizeof(hs_addr));
110 if( !(parseFtnAddrZS(argv[argc], &paddr) & FTNADDR_ERROR) ) {
111 printf("link %s not found in config file\n", argv[argc]);
112 } else printf("illegal parameter no.%d (\"%s\"): not an FTN address\n", argc, argv[argc]);
113 } else if ( argc>1 ) printf( "-------------------------------------\n" );
114 };
115 return 0;
116 }
117
118 #ifdef __cplusplus
119 };
120 #endif
121