wmshutdown: Destroy dialog window before shutting down. This is especially useful...
[dockapps.git] / yawmppp / src / isprc.c
blobae8c9bb6bc018b0aa4717118fb24101d0c6015a7
1 /*
3 YAWMPPP - PPP dock app/helper for WindowMaker
4 Copyright (C) 2000:
6 Authors: Felipe Bergo (bergo@seul.org)
8 contains code from the wmppp application by
9 Martijn Pieterse (pieterse@xs4all.nl)
10 Antoine Nulle (warp@xs4all.nl)
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program 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
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include "isprc.h"
33 int
34 GetISPInfo(char *rcname,struct YAWMPPP_ISP_INFO *wii,int max)
36 FILE *f;
37 int num_isps;
38 char temp[512],work[512];
39 char *q;
40 char *tokens=" :\n\t";
41 char *tokens2="\n";
43 memset(&wii[0],0,sizeof(struct YAWMPPP_ISP_INFO));
45 f=fopen(rcname,"r");
46 if (!f) return 0;
48 num_isps=0;
50 /* level 0 */
51 while( fgets(temp,128,f) ) {
52 strcpy(work,temp);
53 q=work;
54 q=strtok(q,tokens);
55 if (!q) continue;
56 if (!strcmp(q,"ISP.BEGIN")) {
57 if (num_isps>=max) continue;
59 /* enter ISP.BEGIN block */
60 memset(&wii[num_isps],0,sizeof(struct YAWMPPP_ISP_INFO));
62 wii[num_isps].ppp.override=0;
63 wii[num_isps].ppp.noipdefault=1;
64 wii[num_isps].ppp.noauth=1;
65 wii[num_isps].ppp.passive=0;
66 wii[num_isps].ppp.defaultroute=1;
67 wii[num_isps].ppp.chap=AUTH_DONTCARE;
68 wii[num_isps].ppp.pap=AUTH_DONTCARE;
70 while( fgets(temp,128,f) ) {
71 strcpy(work,temp);
72 q=work;
73 q=strtok(q,tokens);
75 if (!strcmp(q,KEY_LONGNAME)) {
76 q=strtok(NULL,tokens2);
77 if (q) strncpy(wii[num_isps].LongName,q,128);
78 continue;
80 if (!strcmp(q,KEY_SHORTNAME)) {
81 q=strtok(NULL,tokens2);
82 if (q) strncpy(wii[num_isps].ShortName,q,16);
83 continue;
85 if (!strcmp(q,KEY_STARTACTION)) {
86 q=strtok(NULL,tokens2);
87 if (q) strncpy(wii[num_isps].StartAction,q,512);
88 continue;
90 if (!strcmp(q,KEY_STOPACTION)) {
91 q=strtok(NULL,tokens2);
92 if (q) strncpy(wii[num_isps].StopAction,q,512);
93 continue;
95 if (!strcmp(q,KEY_IFDOWNACTION)) {
96 q=strtok(NULL,tokens2);
97 if (q) strncpy(wii[num_isps].IfDownAction,q,512);
98 continue;
100 if (!strcmp(q,KEY_SPEEDACTION)) {
101 q=strtok(NULL,tokens2);
102 if (q) strncpy(wii[num_isps].SpeedAction,q,512);
103 continue;
105 if (!strcmp(q,KEY_PPPSTUFF)) {
106 q=strtok(NULL,tokens2);
107 if (q) strncpy(wii[num_isps].PPPLine,q,512);
108 continue;
110 if (!strcmp(q,KEY_CHATSTUFF)) {
111 q=strtok(NULL,tokens2);
112 if (q) strncpy(wii[num_isps].ChatFile,q,512);
113 continue;
115 if (!strcmp(q,KEY_USER)) {
116 q=strtok(NULL,tokens2);
117 if (q) strncpy(wii[num_isps].User,q,32);
118 continue;
120 if (!strcmp(q,KEY_PHONE)) {
121 q=strtok(NULL,tokens2);
122 if (q) strncpy(wii[num_isps].Phone,q,32);
123 continue;
125 /* ppp options per ISP */
126 if (!strcmp(q,KEY_PPP_OVER)) {
127 q=strtok(NULL,tokens2);
128 if (q) wii[num_isps].ppp.override=atoi(q);
129 continue;
131 if (!strcmp(q,KEY_PPP_DEFAULTROUTE)) {
132 q=strtok(NULL,tokens2);
133 if (q) wii[num_isps].ppp.defaultroute=atoi(q);
134 continue;
136 if (!strcmp(q,KEY_PPP_PASSIVE)) {
137 q=strtok(NULL,tokens2);
138 if (q) wii[num_isps].ppp.passive=atoi(q);
139 continue;
141 if (!strcmp(q,KEY_PPP_NOAUTH)) {
142 q=strtok(NULL,tokens2);
143 if (q) wii[num_isps].ppp.noauth=atoi(q);
144 continue;
146 if (!strcmp(q,KEY_PPP_NOIPDEFAULT)) {
147 q=strtok(NULL,tokens2);
148 if (q) wii[num_isps].ppp.noipdefault=atoi(q);
149 continue;
151 if (!strcmp(q,KEY_PPP_CHAP)) {
152 q=strtok(NULL,tokens2);
153 if (q) wii[num_isps].ppp.chap=atoi(q);
154 continue;
156 if (!strcmp(q,KEY_PPP_PAP)) {
157 q=strtok(NULL,tokens2);
158 if (q) wii[num_isps].ppp.pap=atoi(q);
159 continue;
161 if (!strcmp(q,KEY_NOLOGIN)) {
162 q=strtok(NULL,tokens2);
163 if (q) wii[num_isps].nologin=atoi(q);
164 continue;
166 if (!strcmp(q,"ISP.END")) {
167 num_isps++;
168 break;
173 fclose(f);
174 return(num_isps);