2 Copyright © 2009-2014, The AROS Development Team. All rights reserved.
7 #include <proto/exec.h>
11 #include "prefsdata.h"
13 #include <aros/debug.h>
15 #define EX_BUF_SIZE 256
51 static const TEXT mount_template
[] =
58 "SECTORSIZE=BLOCKSIZE/K,"
60 "SECTORSPERTRACK=BLOCKSPERTRACK/K,"
104 static const TEXT control_template
[] =
105 "DOMAIN=WORKGROUP/K,"
109 "CASE=CASESENSITIVE/S,"
112 "CLIENT=CLIENTNAME/K,"
113 "SERVER=SERVERNAME/K,"
114 "DEVICE=DEVICENAME/K,"
115 "VOLUME=VOLUMENAME/K,"
116 "CACHE=CACHESIZE/N/K,"
117 "DEBUGLEVEL=DEBUG/N/K,"
118 "TZ=TIMEZONEOFFSET/N/K,"
120 "TRANSLATE=TRANSLATIONFILE/K,"
123 static struct TCPPrefs prefs
;
127 STRPTR tokenizerLine
;
129 FILE * tokenizedFile
;
134 /* List of devices that require NOTRACKING option */
135 static STRPTR notrackingdevices
[] = {"prm-rtl8029.device", NULL
};
137 static BOOL
ReadServer(struct Server
*server
, BPTR file
, LONG size
);
138 static CONST_STRPTR
GetActiveServers();
140 void OpenTokenFile(struct Tokenizer
* tok
, STRPTR FileName
)
142 tok
->tokenizedFile
= fopen(FileName
, "r");
145 if (!tok
->tokenizedFile
)
149 tok
->tokenizerLine
= malloc(8192);
155 void CloseTokenFile(struct Tokenizer
* tok
)
157 if (tok
->tokenizedFile
)
159 fclose(tok
->tokenizedFile
);
160 free(tok
->tokenizerLine
);
166 void GetNextToken(struct Tokenizer
* tok
, STRPTR tk
)
168 tok
->newline
= FALSE
;
169 if (tok
->token
!= NULL
)
171 tok
->token
= strtok(NULL
, tk
);
173 GetNextToken(tok
, tk
);
178 if (!feof(tok
->tokenizedFile
))
180 tok
->tokenizerLine
[0] = 0;
181 fgets(tok
->tokenizerLine
, 8192, tok
->tokenizedFile
);
182 if (tok
->tokenizerLine
== NULL
)
185 GetNextToken(tok
, tk
);
188 tok
->token
= strtok(tok
->tokenizerLine
, tk
);
195 void SetDefaultNetworkPrefsValues()
198 for (i
= 0; i
< MAXINTERFACES
; i
++)
200 InitInterface(GetInterface(i
));
202 SetInterfaceCount(0);
203 SetDomain(DEFAULTDOMAIN
);
204 SetHostname(DEFAULTHOST
);
205 SetGate(DEFAULTGATE
);
206 SetDNS(0, DEFAULTDNS
);
207 SetDNS(1, DEFAULTDNS
);
212 for (i
= 0; i
< MAXHOSTS
; i
++)
214 InitHost(GetHost(i
));
219 void SetDefaultWirelessPrefsValues()
222 for (i
= 0; i
< MAXNETWORKS
; i
++)
224 InitNetwork(GetNetwork(i
));
228 SetWirelessDevice(NULL
);
231 void SetDefaultMobilePrefsValues()
234 for (i
= 0; i
< MAXATCOMMANDS
; i
++)
236 prefs
.mobile
.atcommand
[i
][0] = 0;
238 SetMobile_atcommand(0,"AT+CGDCONT=1,\"IP\",\"insert.your.apn.here\"");
239 SetMobile_atcommand(1,"ATDT*99***1#");
240 SetMobile_timeout( 10 );
241 SetMobile_Autostart(FALSE
);
242 SetMobile_devicename( "usbmodem.device" );
244 SetMobile_username("");
245 SetMobile_password("");
248 void InitInterface(struct Interface
*iface
)
250 SetName(iface
, DEFAULTNAME
);
251 SetIfDHCP(iface
, TRUE
);
252 SetIP(iface
, DEFAULTIP
);
253 SetMask(iface
, DEFAULTMASK
);
254 SetDevice(iface
, DEFAULTDEVICE
);
259 /* Returns TRUE if directory has been created or already existed */
260 BOOL
RecursiveCreateDir(CONST_STRPTR dirpath
)
262 /* Will create directory even if top level directory does not exist */
265 ULONG lastdirseparator
= 0;
266 ULONG dirpathlen
= strlen(dirpath
);
267 STRPTR tmpdirpath
= AllocVec(dirpathlen
+ 2, MEMF_CLEAR
| MEMF_PUBLIC
);
269 CopyMem(dirpath
, tmpdirpath
, dirpathlen
);
271 /* Recurvice directory creation */
274 if (lastdirseparator
>= dirpathlen
) break;
276 for (; lastdirseparator
< dirpathlen
; lastdirseparator
++)
277 if (tmpdirpath
[lastdirseparator
] == '/') break;
279 tmpdirpath
[lastdirseparator
] = '\0'; /* cut */
281 /* Unlock any lock from previous interation. Last iteration lock will be returned. */
288 /* Check if directory exists */
289 lock
= Lock(tmpdirpath
, SHARED_LOCK
);
292 lock
= CreateDir(tmpdirpath
);
294 break; /* Error with creation */
297 tmpdirpath
[lastdirseparator
] = '/'; /* restore */
313 /* Returns TRUE if selected device needs to use NOTRACKING option */
314 BOOL
GetNoTracking(struct Interface
*iface
)
316 STRPTR devicename
= NULL
;
318 TEXT devicepath
[strlen(GetDevice(iface
)) + 1];
319 strcpy(devicepath
, GetDevice(iface
));
322 while ((devicename
= notrackingdevices
[pos
++]) != NULL
)
324 /* Comparison is done on upper case string so it is case insensitive */
326 if (strstr(devicepath
, devicename
) != NULL
)
333 /* Puts part 1 into empty buffer */
334 VOID
CombinePath1P(STRPTR dstbuffer
, ULONG dstbufferlen
, CONST_STRPTR part1
)
336 dstbuffer
[0] = '\0'; /* Make sure buffer is treated as empty */
337 AddPart(dstbuffer
, part1
, dstbufferlen
);
340 /* Combines part1 with part2 into an empty buffer */
341 VOID
CombinePath2P(STRPTR dstbuffer
, ULONG dstbufferlen
, CONST_STRPTR part1
, CONST_STRPTR part2
)
343 CombinePath1P(dstbuffer
, dstbufferlen
, part1
);
344 AddPart(dstbuffer
, part2
, dstbufferlen
);
347 /* Combines part1 with part2 with part3 into an empty buffer */
348 VOID
CombinePath3P(STRPTR dstbuffer
, ULONG dstbufferlen
, CONST_STRPTR part1
, CONST_STRPTR part2
, CONST_STRPTR part3
)
350 CombinePath2P(dstbuffer
, dstbufferlen
, part1
, part2
);
351 AddPart(dstbuffer
, part3
, dstbufferlen
);
354 BOOL
WriteNetworkPrefs(CONST_STRPTR destdir
)
358 struct Interface
*iface
;
360 ULONG filenamelen
= strlen(destdir
) + 4 + 20;
361 TEXT filename
[filenamelen
];
362 ULONG destdbdirlen
= strlen(destdir
) + 3 + 1;
363 TEXT destdbdir
[destdbdirlen
];
364 LONG interfacecount
= GetInterfaceCount();
365 LONG hostcount
= GetHostCount();
367 CombinePath2P(destdbdir
, destdbdirlen
, destdir
, "db");
369 /* Create necessary directories */
370 if (!RecursiveCreateDir(destdir
)) return FALSE
;
371 if (!RecursiveCreateDir(destdbdir
)) return FALSE
;
373 /* Write configuration files */
374 CombinePath2P(filename
, filenamelen
, destdbdir
, "general.config");
375 ConfFile
= fopen(filename
, "w");
376 if (!ConfFile
) return FALSE
;
377 fprintf(ConfFile
, "USELOOPBACK=YES\n");
378 fprintf(ConfFile
, "DEBUGSANA=NO\n");
379 fprintf(ConfFile
, "USENS=SECOND\n");
380 fprintf(ConfFile
, "GATEWAY=NO\n");
381 fprintf(ConfFile
, "HOSTNAME=%s.%s\n", GetHostname(), GetDomain());
382 fprintf(ConfFile
, "LOG FILTERFILE=5\n");
383 fprintf(ConfFile
, "GUI PANEL=MUI\n");
384 fprintf(ConfFile
, "OPENGUI=YES\n");
387 CombinePath2P(filename
, filenamelen
, destdbdir
, "interfaces");
388 ConfFile
= fopen(filename
, "w");
389 if (!ConfFile
) return FALSE
;
390 for (i
= 0; i
< interfacecount
; i
++)
392 iface
= GetInterface(i
);
395 ConfFile
, "%s DEV=%s UNIT=%d %s IP=%s NETMASK=%s %s\n",
396 GetName(iface
), GetDevice(iface
), (int)GetUnit(iface
),
397 (GetNoTracking(iface
) ? (CONST_STRPTR
)"NOTRACKING" : (CONST_STRPTR
)""),
399 (strstr(GetDevice(iface
), "ppp.device") == NULL
?
400 (CONST_STRPTR
)"DHCP" : (CONST_STRPTR
)"0.0.0.0") :
403 (GetUp(iface
) ? (CONST_STRPTR
)"UP" : (CONST_STRPTR
)"")
405 if (strstr(GetDevice(iface
), "atheros5000.device") != NULL
406 || strstr(GetDevice(iface
), "prism2.device") != NULL
407 || strstr(GetDevice(iface
), "realtek8180.device") != NULL
)
409 SetWirelessDevice(GetDevice(iface
));
410 SetWirelessUnit(GetUnit(iface
));
412 else if (strstr(GetDevice(iface
), "ppp.device") != NULL
)
413 SetMobile_Autostart(TRUE
);
417 CombinePath2P(filename
, filenamelen
, destdbdir
, "netdb-myhost");
418 ConfFile
= fopen(filename
, "w");
419 if (!ConfFile
) return FALSE
;
421 for (i
= 0; i
< interfacecount
; i
++)
423 iface
= GetInterface(i
);
424 if (!GetIfDHCP(iface
))
428 ConfFile
, "HOST %s %s.%s %s\n",
429 GetIP(iface
), GetHostname(), GetDomain(), GetHostname()
436 // FIXME: old version wrote Gateway even when DHCP was enabled
437 fprintf(ConfFile
, "HOST %s gateway\n", GetGate());
438 fprintf(ConfFile
, "; Domain names\n");
439 fprintf(ConfFile
, "; Name servers\n");
440 fprintf(ConfFile
, "NAMESERVER %s\n", GetDNS(0));
441 fprintf(ConfFile
, "NAMESERVER %s\n", GetDNS(1));
445 CombinePath2P(filename
, filenamelen
, destdbdir
, "static-routes");
446 ConfFile
= fopen(filename
, "w");
447 if (!ConfFile
) return FALSE
;
450 // FIXME: old version wrote Gateway even when DHCP was enabled
451 fprintf(ConfFile
, "DEFAULT GATEWAY %s\n", GetGate());
455 /* Write variables */
456 CombinePath2P(filename
, filenamelen
, destdir
, "Config");
457 ConfFile
= fopen(filename
, "w");
458 if (!ConfFile
) return FALSE
;
459 fprintf(ConfFile
, "%s/db", PREFS_PATH_ENV
);
462 CombinePath2P(filename
, filenamelen
, destdir
, "AutoRun");
463 ConfFile
= fopen(filename
, "w");
464 if (!ConfFile
) return FALSE
;
465 fprintf(ConfFile
, "%s", (GetAutostart()) ? "True" : "False");
468 CombinePath2P(filename
, filenamelen
, destdir
, "MobileAutorun");
469 ConfFile
= fopen(filename
, "w");
470 if (!ConfFile
) return FALSE
;
471 fprintf(ConfFile
, "%s", (GetMobile_Autostart()) ? "True" : "False");
474 CombinePath2P(filename
, filenamelen
, destdir
, "WirelessAutoRun");
475 ConfFile
= fopen(filename
, "w");
476 if (!ConfFile
) return FALSE
;
477 fprintf(ConfFile
, "%s", (GetWirelessDevice() != NULL
) ? "True" : "False");
480 if (GetWirelessDevice() != NULL
)
482 CombinePath2P(filename
, filenamelen
, destdir
, "WirelessDevice");
483 ConfFile
= fopen(filename
, "w");
484 if (!ConfFile
) return FALSE
;
485 fprintf(ConfFile
, "%s UNIT %ld", GetWirelessDevice(),
486 (long int)GetWirelessUnit());
490 CombinePath2P(filename
, filenamelen
, destdbdir
, "hosts");
491 ConfFile
= fopen(filename
, "w");
492 if (!ConfFile
) return FALSE
;
493 for (i
= 0; i
< hostcount
; i
++)
499 GetHostAddress(host
), GetHostNames(host
)
507 BOOL
WriteWirelessPrefs(CONST_STRPTR destdir
)
512 ULONG filenamelen
= strlen(destdir
) + 4 + 20;
513 TEXT filename
[filenamelen
];
515 /* Write wireless config */
516 CombinePath2P(filename
, filenamelen
, destdir
, "Wireless.prefs");
517 if (prefs
.networkCount
> 0)
519 ConfFile
= fopen(filename
, "w");
520 if (!ConfFile
) return FALSE
;
522 for (i
= 0; i
< prefs
.networkCount
; i
++)
524 net
= &prefs
.networks
[i
];
525 fprintf(ConfFile
, "network={\n");
526 if (net
->name
[0] != '\0')
527 fprintf(ConfFile
, "\tssid=\"%s\"\n", net
->name
);
528 switch (net
->encType
)
532 fprintf(ConfFile
, "\tpsk=%s\n", net
->key
);
534 fprintf(ConfFile
, "\tpsk=\"%s\"\n", net
->key
);
535 fprintf(ConfFile
, "\tkey_mgmt=WPA-PSK\n");
539 fprintf(ConfFile
, "\twep_key0=%s\n", net
->key
);
541 fprintf(ConfFile
, "\twep_key0=\"%s\"\n", net
->key
);
542 fprintf(ConfFile
, "\twep_tx_keyidx=0\n");
544 fprintf(ConfFile
, "\tkey_mgmt=NONE\n");
547 fprintf(ConfFile
, "\tscan_ssid=1\n");
549 fprintf(ConfFile
, "\tmode=1\n");
550 fprintf(ConfFile
, "}\n\n");
556 DeleteFile(filename
);
562 BOOL
WriteMobilePrefs(CONST_STRPTR destdir
)
566 ULONG filenamelen
= strlen(destdir
) + 4 + 30;
567 TEXT filename
[filenamelen
];
569 CombinePath2P(filename
, filenamelen
, destdir
, "MobileBroadband.prefs");
570 ConfFile
= fopen(filename
, "w");
571 if (!ConfFile
) return FALSE
;
573 if (strlen(GetMobile_devicename()) > 0)
574 fprintf(ConfFile
, "DEVICE %s\n", GetMobile_devicename());
575 fprintf(ConfFile
, "UNIT %d\n" , (int)GetMobile_unit() );
576 if (strlen(GetMobile_username()) > 0)
577 fprintf(ConfFile
, "USERNAME %s\n", GetMobile_username());
578 if (strlen(GetMobile_password()) > 0)
579 fprintf(ConfFile
, "PASSWORD %s\n", GetMobile_password());
581 for (i
= 0; i
< MAXATCOMMANDS
; i
++)
583 if (strlen( GetMobile_atcommand(i
) ) > 0)
584 fprintf(ConfFile
, "SEND %s\n", GetMobile_atcommand(i
));
593 BOOL
WriteServers(CONST_STRPTR destdir
, CONST_STRPTR envdir
)
595 FILE *mount_file
, *env_file
;
597 struct Server
*server
;
598 ULONG filenamelen
= strlen(destdir
) + 4 + 20;
599 TEXT filename
[filenamelen
];
601 CombinePath2P(filename
, filenamelen
, envdir
, "ServerAutoMounts");
602 env_file
= fopen(filename
, "w");
603 if (!env_file
) return FALSE
;
605 for (i
= 0; i
< prefs
.serverCount
; i
++)
607 server
= &prefs
.servers
[i
];
608 CombinePath2P(filename
, filenamelen
, destdir
, server
->device
);
609 mount_file
= fopen(filename
, "w");
616 fprintf(mount_file
, "EHandler = " SERVER_HANDLER
"\nActivate = 1\n");
617 fprintf(mount_file
, "Control = \"");
618 if (server
->user
[0] != '\0')
619 fprintf(mount_file
, "USER=*\"%s*\" ", server
->user
);
620 if (server
->group
[0] != '\0')
621 fprintf(mount_file
, "WORKGROUP=*\"%s*\" ", server
->group
);
622 if (server
->pass
[0] != '\0')
623 fprintf(mount_file
, "PASSWORD=*\"%s*\" ", server
->pass
);
624 fprintf(mount_file
, "SERVICE=*\"//%s/%s*\"\"\n", server
->host
,
629 fprintf(env_file
, "%s: ", server
->device
);
639 BOOL
CopyFile(CONST_STRPTR srcfile
, CONST_STRPTR dstfile
)
641 BPTR from
= BNULL
, to
= BNULL
;
642 TEXT buffer
[BUFSIZE
];
644 if ((from
= Open(srcfile
, MODE_OLDFILE
)))
646 if ((to
= Open(dstfile
, MODE_NEWFILE
)))
652 if ((s
= Read(from
, buffer
, BUFSIZE
)) == -1)
659 if (Write(to
, buffer
, s
) == -1)
665 } while (s
== BUFSIZE
);
678 CONST_STRPTR
GetDefaultStackLocation()
680 /* Use static variable so that it is initialized only once (and can be returned) */
681 static TEXT path
[1024] = {0};
683 /* Load path if needed - this will happen only once */
686 GetVar(AROSTCP_PACKAGE_VARIABLE
, path
, 1024, LV_VAR
);
692 BOOL
IsStackRunning()
694 return FindTask("bsdsocket.library") != NULL
;
702 if (IsStackRunning())
704 struct Task
* arostcptask
= FindTask("bsdsocket.library");
705 if (arostcptask
!= NULL
)
706 Signal(arostcptask
, SIGBREAKF_CTRL_C
);
709 /* Check if shutdown successful */
711 while (IsStackRunning())
713 if (trycount
> 4) return FALSE
;
720 CONST_STRPTR srcdir
= GetDefaultStackLocation();
721 ULONG arostcppathlen
= strlen(srcdir
) + 3 + 20;
722 TEXT arostcppath
[arostcppathlen
];
723 struct TagItem tags
[] =
725 { SYS_Input
, (IPTR
)NULL
},
726 { SYS_Output
, (IPTR
)NULL
},
727 { SYS_Error
, (IPTR
)NULL
},
728 { SYS_Asynch
, (IPTR
)TRUE
},
732 CombinePath3P(arostcppath
, arostcppathlen
, srcdir
, "C", "AROSTCP");
734 SystemTagList(arostcppath
, tags
);
737 /* Check if startup successful */
739 while (!IsStackRunning())
741 if (trycount
> 9) return FALSE
;
756 struct Task
*task
= FindTask("C:WirelessManager");
758 Signal(task
, SIGBREAKF_CTRL_C
);
761 /* Check if shutdown successful */
763 while (FindTask("C:WirelessManager") != NULL
)
765 if (trycount
> 4) return FALSE
;
781 struct TagItem tags
[] =
783 { SYS_Input
, (IPTR
)NULL
},
784 { SYS_Output
, (IPTR
)NULL
},
785 { SYS_Error
, (IPTR
)NULL
},
786 { SYS_Asynch
, (IPTR
)TRUE
},
790 snprintf(command
, 80, "C:WirelessManager \"%s\" UNIT %ld\n",
791 GetWirelessDevice(), (long int)GetWirelessUnit());
792 SystemTagList(command
, tags
);
795 /* Check if startup successful */
797 while (FindTask("C:WirelessManager") == NULL
)
799 if (trycount
> 9) return FALSE
;
814 struct Task
*task
= FindTask("C:ModemManager");
816 Signal(task
, SIGBREAKF_CTRL_C
);
819 /* Check if shutdown successful */
821 while (FindTask("C:ModemManager") != NULL
)
823 if (trycount
> 4) return FALSE
;
838 struct TagItem tags
[] =
840 { SYS_Input
, (IPTR
)NULL
},
841 { SYS_Output
, (IPTR
)NULL
},
842 { SYS_Error
, (IPTR
)NULL
},
843 { SYS_Asynch
, (IPTR
)TRUE
},
847 SystemTagList("C:ModemManager", tags
);
850 /* Check if startup successful */
852 while (FindTask("C:ModemManager") == NULL
)
854 if (trycount
> 9) return FALSE
;
863 static CONST_STRPTR
GetActiveServers()
865 /* Use static variable so that it is initialized only once (and can be returned) */
866 static TEXT servers
[256] = {0};
868 /* Load variable if needed - this will happen only once */
869 if (servers
[0] == '\0')
871 GetVar(AUTOMOUNT_VARIABLE
, servers
, 256, LV_VAR
);
881 dir
= Lock(SERVER_PATH_ENV
, SHARED_LOCK
);
886 if (GetServerCount() > 0)
888 struct TagItem tags
[] =
890 { SYS_Input
, (IPTR
)NULL
},
891 { SYS_Output
, (IPTR
)NULL
},
892 { SYS_Error
, (IPTR
)NULL
},
893 { SYS_Asynch
, (IPTR
)TRUE
},
894 { NP_CurrentDir
, (IPTR
)dir
},
898 SystemTagList("C:Mount ${AROSTCP/ServerAutoMounts}\n", tags
);
905 /* This is not a general use function! It assumes destinations directory exists */
906 BOOL
AddFileFromDefaultStackLocation(CONST_STRPTR filename
, CONST_STRPTR dstdir
)
909 CONST_STRPTR srcdir
= GetDefaultStackLocation();
910 ULONG srcfilelen
= strlen(srcdir
) + 4 + strlen(filename
) + 1;
911 TEXT srcfile
[srcfilelen
];
912 ULONG dstfilelen
= strlen(dstdir
) + 4 + strlen(filename
) + 1;
913 TEXT dstfile
[dstfilelen
];
914 BPTR dstlock
= BNULL
;
916 CombinePath3P(srcfile
, srcfilelen
, srcdir
, "db", filename
);
917 CombinePath3P(dstfile
, dstfilelen
, dstdir
, "db", filename
);
919 /* Check if the destination file already exists. If yes, do not copy */
920 dstlock
= Lock(dstfile
, SHARED_LOCK
);
921 if (dstlock
!= BNULL
)
927 return CopyFile(srcfile
, dstfile
);
930 /* Copies files not created by prefs but needed to start stack */
931 BOOL
CopyDefaultConfiguration(CONST_STRPTR destdir
)
933 ULONG destdbdirlen
= strlen(destdir
) + 3 + 1;
934 TEXT destdbdir
[destdbdirlen
];
935 CombinePath2P(destdbdir
, destdbdirlen
, destdir
, "db");
937 /* Create necessary directories */
938 if (!RecursiveCreateDir(destdir
)) return FALSE
;
939 if (!RecursiveCreateDir(destdbdir
)) return FALSE
;
942 if (!AddFileFromDefaultStackLocation("inet.access", destdir
)) return FALSE
;
943 if (!AddFileFromDefaultStackLocation("netdb", destdir
)) return FALSE
;
944 if (!AddFileFromDefaultStackLocation("networks", destdir
)) return FALSE
;
945 if (!AddFileFromDefaultStackLocation("protocols", destdir
)) return FALSE
;
946 if (!AddFileFromDefaultStackLocation("services", destdir
)) return FALSE
;
951 enum ErrorCode
SaveNetworkPrefs()
953 if (!CopyDefaultConfiguration(PREFS_PATH_ENVARC
)) return NOT_COPIED_FILES_ENVARC
;
954 if (!WriteNetworkPrefs(PREFS_PATH_ENVARC
)) return NOT_SAVED_PREFS_ENVARC
;
955 if (!WriteWirelessPrefs(WIRELESS_PATH_ENVARC
)) return NOT_SAVED_PREFS_ENVARC
;
956 if (!WriteMobilePrefs(MOBILEBB_PATH_ENVARC
)) return NOT_SAVED_PREFS_ENVARC
;
957 if (!WriteServers(SERVER_PATH_STORAGE
, PREFS_PATH_ENVARC
))
958 return NOT_SAVED_PREFS_ENVARC
;
960 return UseNetworkPrefs();
963 enum ErrorCode
UseNetworkPrefs()
965 if (!CopyDefaultConfiguration(PREFS_PATH_ENV
)) return NOT_COPIED_FILES_ENV
;
966 if (!WriteNetworkPrefs(PREFS_PATH_ENV
)) return NOT_SAVED_PREFS_ENV
;
967 if (!WriteWirelessPrefs(WIRELESS_PATH_ENV
)) return NOT_SAVED_PREFS_ENV
;
968 if (!WriteMobilePrefs(MOBILEBB_PATH_ENV
)) return NOT_SAVED_PREFS_ENV
;
969 if (!RecursiveCreateDir(SERVER_PATH_ENV
)) return NOT_SAVED_PREFS_ENV
;
970 if (!WriteServers(SERVER_PATH_ENV
, PREFS_PATH_ENV
))
971 return NOT_SAVED_PREFS_ENV
;
974 if (GetWirelessDevice() != NULL
)
975 if (!StartWireless()) return NOT_RESTARTED_WIRELESS
;
976 if (!RestartStack()) return NOT_RESTARTED_STACK
;
978 if (GetMobile_Autostart())
979 if (!StartMobile()) return NOT_RESTARTED_MOBILE
;
985 /* Directory points to top of config, so to AAA/AROSTCP not to AAA/AROSTCP/db */
986 void ReadNetworkPrefs(CONST_STRPTR directory
)
988 ULONG filenamelen
= strlen(directory
) + 4 + 20;
989 TEXT filename
[filenamelen
];
990 BOOL comment
= FALSE
;
992 struct Tokenizer tok
;
993 LONG interfacecount
, hostcount
;
994 struct Interface
*iface
= NULL
;
995 struct Host
*host
= NULL
;
997 /* This function will not fail. It will load as much data as possible. Rest will be default values */
1001 CombinePath3P(filename
, filenamelen
, directory
, "db", "general.config");
1002 OpenTokenFile(&tok
, filename
);
1006 { // read tokens from the beginning of line
1009 if (strcmp(tok
.token
, "HOSTNAME") == 0)
1011 GetNextToken(&tok
, "=\n");
1012 tstring
= strchr(tok
.token
, '.');
1013 SetDomain(tstring
+ 1);
1015 SetHostname(tok
.token
);
1019 GetNextToken(&tok
, "=\n");
1021 CloseTokenFile(&tok
);
1023 CombinePath3P(filename
, filenamelen
, directory
, "db", "interfaces");
1024 OpenTokenFile(&tok
, filename
);
1026 SetInterfaceCount(0);
1029 while (!tok
.fend
&& (interfacecount
< MAXINTERFACES
))
1031 GetNextToken(&tok
, " \n");
1034 if (tok
.newline
) comment
= FALSE
;
1035 if (strncmp(tok
.token
, "#", 1) == 0) comment
= TRUE
;
1041 iface
= GetInterface(interfacecount
);
1042 SetName(iface
, tok
.token
);
1044 SetInterfaceCount(interfacecount
);
1046 else if (strncmp(tok
.token
, "DEV=", 4) == 0)
1048 tstring
= strchr(tok
.token
, '=');
1049 SetDevice(iface
, tstring
+ 1);
1051 else if (strncmp(tok
.token
, "UNIT=", 5) == 0)
1053 tstring
= strchr(tok
.token
, '=');
1054 SetUnit(iface
, atol(tstring
+ 1));
1056 else if (strncmp(tok
.token
, "IP=", 3) == 0)
1058 tstring
= strchr(tok
.token
, '=');
1059 if (strncmp(tstring
+ 1, "DHCP", 4) == 0
1060 || strstr(GetDevice(iface
), "ppp.device") != NULL
)
1062 SetIfDHCP(iface
, TRUE
);
1063 SetIP(iface
, DEFAULTIP
);
1067 SetIP(iface
, tstring
+ 1);
1068 SetIfDHCP(iface
, FALSE
);
1071 else if (strncmp(tok
.token
, "NETMASK=", 8) == 0)
1073 tstring
= strchr(tok
.token
, '=');
1074 SetMask(iface
, tstring
+ 1);
1076 else if (strncmp(tok
.token
, "UP", 2) == 0)
1083 CloseTokenFile(&tok
);
1085 CombinePath3P(filename
, filenamelen
, directory
, "db", "netdb-myhost");
1086 OpenTokenFile(&tok
, filename
);
1090 GetNextToken(&tok
, " \n");
1093 // Host and Domain are already read from general.config
1094 if (strncmp(tok
.token
, "NAMESERVER", 10) == 0)
1096 GetNextToken(&tok
, " \n");
1097 SetDNS(dnsc
, tok
.token
);
1099 if (dnsc
> 1) dnsc
= 1;
1103 // Assume DHCP if there is no nameserver
1108 CloseTokenFile(&tok
);
1110 CombinePath3P(filename
, filenamelen
, directory
, "db", "static-routes");
1111 OpenTokenFile(&tok
, filename
);
1114 GetNextToken(&tok
, " \n");
1117 if (strncmp(tok
.token
, "DEFAULT", 7) == 0)
1119 GetNextToken(&tok
, " \n");
1120 if (strncmp(tok
.token
, "GATEWAY", 7) == 0)
1122 GetNextToken(&tok
, " \n");
1128 CloseTokenFile(&tok
);
1130 CombinePath2P(filename
, filenamelen
, directory
, "Autorun");
1131 OpenTokenFile(&tok
, filename
);
1134 GetNextToken(&tok
, " \n");
1137 if (strncmp(tok
.token
, "True", 4) == 0)
1144 SetAutostart(FALSE
);
1149 CloseTokenFile(&tok
);
1151 CombinePath3P(filename
, filenamelen
, directory
, "db", "hosts");
1152 OpenTokenFile(&tok
, filename
);
1157 while (!tok
.fend
&& (hostcount
< MAXHOSTS
))
1159 GetNextToken(&tok
, " \n");
1162 if (tok
.newline
) comment
= FALSE
;
1163 if (strncmp(tok
.token
, "#", 1) == 0) comment
= TRUE
;
1169 host
= GetHost(hostcount
);
1170 SetHostAddress(host
, tok
.token
);
1172 SetHostCount(hostcount
);
1176 AddHostName(host
, tok
.token
);
1181 CloseTokenFile(&tok
);
1184 void ReadWirelessPrefs(CONST_STRPTR directory
)
1186 ULONG filenamelen
= strlen(directory
) + 4 + 20;
1187 TEXT filename
[filenamelen
];
1188 BOOL comment
= FALSE
;
1190 struct Tokenizer tok
;
1192 struct Network
*net
= NULL
;
1195 CombinePath2P(filename
, filenamelen
, directory
, "Wireless.prefs");
1196 OpenTokenFile(&tok
, filename
);
1201 while (!tok
.fend
&& (networkCount
< MAXNETWORKS
))
1203 GetNextToken(&tok
, "\n\t");
1206 if (tok
.newline
) comment
= FALSE
;
1207 if (strncmp(tok
.token
, "#", 1) == 0) comment
= TRUE
;
1211 if (strncmp(tok
.token
, "network=", 8) == 0)
1213 net
= GetNetwork(networkCount
);
1215 net
->hidden
= FALSE
;
1217 SetNetworkCount(networkCount
);
1219 else if (strncmp(tok
.token
, "ssid=", 5) == 0)
1221 tstring
= strchr(tok
.token
, '=') + 2;
1222 *strchr(tstring
, '\"') = '\0';
1223 SetNetworkName(net
, tstring
);
1225 else if (strncmp(tok
.token
, "psk=", 4) == 0
1226 || strncmp(tok
.token
, "wep_key0=", 9) == 0)
1228 tstring
= strchr(tok
.token
, '=') + 1;
1229 if (*tstring
== '\"')
1233 *strchr(tstring
, '\"') = '\0';
1237 SetKey(net
, tstring
, keyIsHex
);
1238 SetEncType(net
, (*tok
.token
== 'p') ? 2 : 1);
1240 else if (strncmp(tok
.token
, "scan_ssid=", 10) == 0)
1242 tstring
= strchr(tok
.token
, '=') + 1;
1243 SetHidden(net
, *tstring
== '1');
1245 else if (strncmp(tok
.token
, "mode=", 5) == 0)
1247 tstring
= strchr(tok
.token
, '=') + 1;
1248 SetAdHoc(net
, *tstring
== '1');
1253 CloseTokenFile(&tok
);
1257 void ReadMobilePrefs(CONST_STRPTR directory
)
1259 ULONG filenamelen
= strlen(directory
) + 4 + 30;
1260 TEXT filename
[filenamelen
];
1261 struct Tokenizer tok
;
1264 CombinePath2P(filename
, filenamelen
, directory
, "MobileBroadband.prefs");
1265 OpenTokenFile(&tok
, filename
);
1268 GetNextToken(&tok
, " \n");
1271 if ( tok
.newline
&& tok
.token
[0] == '#' ) continue;
1275 if (strcasecmp( tok
.token
, "SEND" ) == 0)
1277 GetNextToken(&tok
, "\n");
1278 if ( tok
.token
&& ! tok
.newline
)
1280 SetMobile_atcommand( command
++ , tok
.token
);
1283 else if (strcasecmp( tok
.token
, "DEVICE" ) == 0)
1285 GetNextToken(&tok
, " \n");
1286 if ( tok
.token
&& ! tok
.newline
)
1288 SetMobile_devicename( tok
.token
);
1291 else if (strcasecmp( tok
.token
, "USERNAME" ) == 0)
1293 GetNextToken(&tok
, " \n");
1294 if ( tok
.token
&& ! tok
.newline
)
1296 SetMobile_username( tok
.token
);
1299 else if (strcasecmp( tok
.token
, "PASSWORD" ) == 0)
1301 GetNextToken(&tok
, " \n");
1302 if ( tok
.token
&& ! tok
.newline
)
1304 SetMobile_password( tok
.token
);
1307 else if (strcasecmp( tok
.token
, "UNIT" ) == 0)
1309 GetNextToken(&tok
, " \n");
1310 if ( tok
.token
&& ! tok
.newline
)
1312 SetMobile_unit( atoi( tok
.token
) );
1318 CloseTokenFile(&tok
);
1325 APTR ex_buffer
= NULL
;
1326 struct ExAllControl
*ex_control
= NULL
;
1327 struct ExAllData
*entry
;
1328 BOOL success
= TRUE
, more
= TRUE
;
1330 struct Server
*server
;
1332 dir
= Lock(SERVER_PATH_ENV
, SHARED_LOCK
);
1335 dir
= Lock(SERVER_PATH_STORAGE
, SHARED_LOCK
);
1340 D(bug("[Network Prefs/ReadServers] scan directory " SERVER_PATH_STORAGE
"\n"));
1345 D(bug("[Network Prefs/ReadServers] scan directory " SERVER_PATH_ENV
"\n"));
1350 ex_buffer
= AllocVec(EX_BUF_SIZE
, MEMF_PUBLIC
);
1351 if (ex_buffer
== NULL
)
1354 ex_control
= AllocDosObject(DOS_EXALLCONTROL
, NULL
);
1355 if (ex_control
== NULL
)
1361 ex_control
->eac_LastKey
= 0;
1362 while (more
&& i
< MAXSERVERS
)
1364 more
= ExAll(dir
, ex_buffer
, EX_BUF_SIZE
, ED_SIZE
, ex_control
);
1366 if (!more
&& (IoErr() != ERROR_NO_MORE_ENTRIES
))
1368 if (ex_control
->eac_Entries
== 0)
1372 while (entry
!= NULL
)
1374 if (entry
->ed_Type
< 0)
1376 dir
= CurrentDir(dir
);
1377 D(bug("[Network Prefs/ReadServers] filename %s\n", entry
->ed_Name
));
1378 file
= Open(entry
->ed_Name
, MODE_OLDFILE
);
1381 server
= &prefs
.servers
[i
];
1382 if (ReadServer(server
, file
, entry
->ed_Size
))
1385 SetServerDevice(server
, entry
->ed_Name
);
1386 if (strstr(GetActiveServers(), entry
->ed_Name
)
1388 SetServerActive(server
, TRUE
);
1392 dir
= CurrentDir(dir
);
1394 entry
= entry
->ed_Next
;
1397 prefs
.serverCount
= i
;
1400 if (ex_control
!= NULL
)
1402 FreeDosObject(DOS_EXALLCONTROL
, ex_control
);
1411 /* Read and parse a server mount file */
1412 static BOOL
ReadServer(struct Server
*server
, BPTR file
, LONG size
)
1414 BOOL success
= TRUE
;
1415 UBYTE
*mount_buffer
;
1416 IPTR mount_args
[NUM_MOUNTARGS
] = {0}, control_args
[NUM_CONTROLARGS
] = {0};
1417 struct RDArgs
*mount_rdargs
= NULL
, *control_rdargs
= NULL
;
1419 STRPTR host
, service
;
1421 /* Allocate buffer for entire mount file */
1422 mount_buffer
= AllocVec(size
+100, MEMF_ANY
|MEMF_CLEAR
);
1423 if (mount_buffer
== NULL
)
1426 /* Read mount file into buffer */
1429 if (FRead(file
, mount_buffer
, size
, 1) != 1)
1435 for (i
= 0; i
< size
; i
++)
1436 if (mount_buffer
[i
] == '\n')
1437 mount_buffer
[i
] = ' ';
1439 mount_rdargs
= AllocDosObject(DOS_RDARGS
, NULL
);
1440 control_rdargs
= AllocDosObject(DOS_RDARGS
, NULL
);
1441 if (mount_rdargs
== NULL
|| control_rdargs
== NULL
)
1445 /* Parse mount parameters */
1448 mount_rdargs
->RDA_Source
.CS_Buffer
= mount_buffer
;
1449 mount_rdargs
->RDA_Source
.CS_Length
= size
+1;
1450 mount_rdargs
->RDA_Flags
= RDAF_NOPROMPT
;
1452 ReadArgs(mount_template
, (IPTR
*)&mount_args
, mount_rdargs
);
1453 if (mount_rdargs
== NULL
)
1457 /* Check if this is a server mount */
1460 if ((char *)mount_args
[ARG_EHANDLER
] == NULL
)
1462 else if (strcasecmp((char *)mount_args
[ARG_EHANDLER
],
1463 SERVER_HANDLER
) != 0)
1467 /* Parse control parameters */
1470 control_rdargs
->RDA_Source
.CS_Buffer
= (UBYTE
*)mount_args
[ARG_CONTROL
];
1471 control_rdargs
->RDA_Source
.CS_Length
=
1472 strlen((STRPTR
)mount_args
[ARG_CONTROL
]);
1474 ReadArgs(control_template
, (IPTR
*)&control_args
, control_rdargs
);
1475 if (control_rdargs
== NULL
)
1479 /* Extract needed control parameters */
1483 service
= FilePart((STRPTR
)control_args
[ARG_SERVICE
]);
1484 SetServerService(server
, service
);
1487 host
= (STRPTR
)control_args
[ARG_SERVICE
] + 2;
1488 SetServerHost(server
, host
);
1490 p
= (STRPTR
)control_args
[ARG_USERNAME
];
1491 SetServerUser(server
, (p
!= NULL
? p
: (STRPTR
)""));
1492 p
= (STRPTR
)control_args
[ARG_WORKGROUP
];
1493 SetServerGroup(server
, (p
!= NULL
? p
: (STRPTR
)""));
1494 p
= (STRPTR
)control_args
[ARG_PASSWORD
];
1495 SetServerPass(server
, (p
!= NULL
? p
: (STRPTR
)""));
1498 if (control_rdargs
!= NULL
)
1500 FreeArgs(control_rdargs
);
1501 FreeDosObject(DOS_RDARGS
, control_rdargs
);
1504 if (mount_rdargs
!= NULL
)
1506 FreeArgs(mount_rdargs
);
1507 FreeDosObject(DOS_RDARGS
, mount_rdargs
);
1514 void InitNetworkPrefs(CONST_STRPTR directory
, BOOL use
, BOOL save
)
1516 SetDefaultNetworkPrefsValues();
1517 SetDefaultWirelessPrefsValues();
1518 SetDefaultMobilePrefsValues();
1520 ReadNetworkPrefs(directory
);
1521 ReadWirelessPrefs(WIRELESS_PATH_ENV
);
1522 ReadMobilePrefs(MOBILEBB_PATH_ENV
);
1528 return; /* save equals to use */
1537 // check if 'str' contains only characters from 'accept'
1538 BOOL
IsLegal(STRPTR str
, STRPTR accept
)
1542 if ((str
== NULL
) || (accept
== NULL
) || (str
[0] == '\0'))
1548 for (i
= 0; i
< len
; i
++)
1550 if (strchr(accept
, str
[i
]) == NULL
)
1561 struct Interface
* GetInterface(LONG index
)
1563 return &prefs
.interface
[index
];
1566 STRPTR
GetName(struct Interface
*iface
)
1571 BOOL
GetIfDHCP(struct Interface
*iface
)
1573 return iface
->ifDHCP
;
1576 STRPTR
GetIP(struct Interface
*iface
)
1581 STRPTR
GetMask(struct Interface
*iface
)
1586 STRPTR
GetDevice(struct Interface
*iface
)
1588 return iface
->device
;
1591 LONG
GetUnit(struct Interface
*iface
)
1596 BOOL
GetUp(struct Interface
*iface
)
1601 STRPTR
GetGate(void)
1606 STRPTR
GetDNS(LONG m
)
1608 return prefs
.DNS
[m
];
1611 STRPTR
GetHostname(void)
1616 STRPTR
GetDomain(void)
1618 return prefs
.domain
;
1621 LONG
GetInterfaceCount(void)
1623 return prefs
.interfacecount
;
1626 BOOL
GetAutostart(void)
1628 return prefs
.autostart
;
1641 struct Interface
*iface
, STRPTR name
, BOOL dhcp
, STRPTR IP
, STRPTR mask
,
1642 STRPTR device
, LONG unit
, BOOL up
1645 SetName(iface
, name
);
1646 SetIfDHCP(iface
, dhcp
);
1648 SetMask(iface
, mask
);
1649 SetDevice(iface
, device
);
1650 SetUnit(iface
, unit
);
1654 void SetName(struct Interface
*iface
, STRPTR w
)
1656 if (!IsLegal(w
, NAMECHARS
))
1660 strlcpy(iface
->name
, w
, NAMEBUFLEN
);
1663 void SetIfDHCP(struct Interface
*iface
, BOOL w
)
1668 void SetIP(struct Interface
*iface
, STRPTR w
)
1670 if (!IsLegal(w
, IPCHARS
))
1674 strlcpy(iface
->IP
, w
, IPBUFLEN
);
1677 void SetMask(struct Interface
*iface
, STRPTR w
)
1679 if (!IsLegal(w
, IPCHARS
))
1683 strlcpy(iface
->mask
, w
, IPBUFLEN
);
1686 void SetDevice(struct Interface
*iface
, STRPTR w
)
1688 if (w
== NULL
|| w
[0] == '\0')
1692 strlcpy(iface
->device
, w
, NAMEBUFLEN
);
1695 void SetUnit(struct Interface
*iface
, LONG w
)
1700 void SetUp(struct Interface
*iface
, BOOL w
)
1705 void SetGate(STRPTR w
)
1707 if (!IsLegal(w
, IPCHARS
))
1711 strlcpy(prefs
.gate
, w
, IPBUFLEN
);
1714 void SetDNS(LONG m
, STRPTR w
)
1716 if (!IsLegal(w
, IPCHARS
))
1720 strlcpy(prefs
.DNS
[m
], w
, IPBUFLEN
);
1723 void SetHostname(STRPTR w
)
1725 if (!IsLegal(w
, NAMECHARS
))
1729 strlcpy(prefs
.host
, w
, NAMEBUFLEN
);
1732 void SetDomain(STRPTR w
)
1734 if (!IsLegal(w
, NAMECHARS
))
1738 strlcpy(prefs
.domain
, w
, NAMEBUFLEN
);
1741 void SetInterfaceCount(LONG w
)
1743 prefs
.interfacecount
= w
;
1746 void SetAutostart(BOOL w
)
1748 prefs
.autostart
= w
;
1751 void SetDHCP(BOOL w
)
1756 void InitHost(struct Host
*host
)
1758 SetHostNames(host
, "");
1759 SetHostAddress(host
, "");
1762 void InitNetwork(struct Network
*net
)
1764 SetNetworkName(net
, "");
1765 SetKey(net
, "", FALSE
);
1767 SetAdHoc(net
, FALSE
);
1770 void InitServer(struct Server
*server
, char *workgroup
)
1772 if ((workgroup
== NULL
) && ((workgroup
= GetDomain()) == NULL
))
1773 workgroup
= "workgroup";
1775 SetServerDevice(server
, DEFAULTSERVERDEV
);
1776 SetServerHost(server
, "");
1777 SetServerGroup(server
, workgroup
);
1778 SetServerService(server
, "share");
1779 SetServerUser(server
, "guest");
1780 SetServerPass(server
, "");
1781 SetServerActive(server
, TRUE
);
1787 struct Host
*GetHost(LONG index
)
1789 return &prefs
.hosts
[index
];
1792 STRPTR
GetHostNames(struct Host
*host
)
1797 STRPTR
GetHostAddress(struct Host
*host
)
1799 return host
->address
;
1802 LONG
GetHostCount(void)
1804 return prefs
.hostCount
;
1807 struct Network
*GetNetwork(LONG index
)
1809 return &prefs
.networks
[index
];
1812 STRPTR
GetNetworkName(struct Network
*net
)
1817 UWORD
GetEncType(struct Network
*net
)
1819 return net
->encType
;
1822 STRPTR
GetKey(struct Network
*net
)
1827 BOOL
GetHidden(struct Network
*net
)
1832 BOOL
GetAdHoc(struct Network
*net
)
1837 LONG
GetNetworkCount(void)
1839 return prefs
.networkCount
;
1842 STRPTR
GetWirelessDevice(void)
1844 return prefs
.wirelessDevice
;
1847 LONG
GetWirelessUnit(void)
1849 return prefs
.wirelessUnit
;
1852 BOOL
GetMobile_Autostart(void)
1854 return prefs
.mobile
.autostart
;
1857 STRPTR
GetMobile_atcommand(ULONG i
)
1859 if (i
< MAXATCOMMANDS
)
1860 return prefs
.mobile
.atcommand
[i
];
1864 LONG
GetMobile_atcommandcount(void)
1868 for (i
= 0; i
< MAXATCOMMANDS
; i
++)
1870 if (prefs
.mobile
.atcommand
[i
][0] != 0) count
++;
1875 STRPTR
GetMobile_devicename(void)
1877 return prefs
.mobile
.devicename
;
1880 STRPTR
GetMobile_username(void)
1882 return prefs
.mobile
.username
;
1885 STRPTR
GetMobile_password(void)
1887 return prefs
.mobile
.password
;
1890 LONG
GetMobile_unit(void)
1892 return prefs
.mobile
.unit
;
1895 LONG
GetMobile_timeout(void)
1897 return prefs
.mobile
.timeout
;
1900 struct Server
*GetServer(LONG index
)
1902 return &prefs
.servers
[index
];
1905 STRPTR
GetServerDevice(struct Server
*server
)
1907 return server
->device
;
1910 STRPTR
GetServerHost(struct Server
*server
)
1912 return server
->host
;
1915 STRPTR
GetServerService(struct Server
*server
)
1917 return server
->service
;
1920 STRPTR
GetServerUser(struct Server
*server
)
1922 return server
->user
;
1925 STRPTR
GetServerGroup(struct Server
*server
)
1927 return server
->group
;
1930 STRPTR
GetServerPass(struct Server
*server
)
1932 return server
->pass
;
1935 BOOL
GetServerActive(struct Server
*server
)
1937 return server
->active
;
1940 LONG
GetServerCount(void)
1942 return prefs
.serverCount
;
1949 struct Host
*host
, STRPTR name
, STRPTR address
1952 SetHostNames(host
, name
);
1953 SetHostAddress(host
, address
);
1956 void SetHostNames(struct Host
*host
, STRPTR w
)
1958 strlcpy(host
->names
, w
, NAMEBUFLEN
);
1961 void AddHostName(struct Host
*host
, STRPTR w
)
1963 if (host
->names
[0] != '\0')
1964 strlcat(host
->names
, " ", NAMEBUFLEN
);
1965 strlcat(host
->names
, w
, NAMEBUFLEN
);
1968 void SetHostAddress(struct Host
*host
, STRPTR w
)
1970 strlcpy(host
->address
, w
, IPBUFLEN
);
1973 void SetHostCount(LONG w
)
1975 prefs
.hostCount
= w
;
1980 struct Network
*net
, STRPTR name
, UWORD encType
, STRPTR key
,
1981 BOOL keyIsHex
, BOOL hidden
, BOOL adHoc
1984 SetNetworkName(net
, name
);
1985 SetEncType(net
, encType
);
1986 SetKey(net
, key
, keyIsHex
);
1987 SetHidden(net
, hidden
);
1988 SetAdHoc(net
, adHoc
);
1991 void SetNetworkName(struct Network
*net
, STRPTR w
)
1993 strlcpy(net
->name
, w
, SSIDBUFLEN
);
1996 void SetEncType(struct Network
*net
, UWORD w
)
2001 void SetKey(struct Network
*net
, STRPTR w
, BOOL keyIsHex
)
2003 strlcpy(net
->key
, w
, KEYBUFLEN
);
2004 net
->keyIsHex
= keyIsHex
;
2007 void SetHidden(struct Network
*net
, BOOL w
)
2012 void SetAdHoc(struct Network
*net
, BOOL w
)
2017 void SetNetworkCount(LONG w
)
2019 prefs
.networkCount
= w
;
2022 void SetWirelessDevice(STRPTR w
)
2024 prefs
.wirelessDevice
= w
;
2027 void SetWirelessUnit(LONG w
)
2029 prefs
.wirelessUnit
= w
;
2032 void SetMobile_Autostart(BOOL w
)
2034 prefs
.mobile
.autostart
= w
;
2037 void SetMobile_atcommand(ULONG i
,STRPTR w
)
2039 if (strlen(w
) < NAMEBUFLEN
&& i
>= 0 && i
< MAXATCOMMANDS
)
2040 strcpy(prefs
.mobile
.atcommand
[i
], w
);
2043 void SetMobile_devicename(STRPTR w
)
2045 if (strlen(w
) < NAMEBUFLEN
)
2046 strcpy(prefs
.mobile
.devicename
, w
);
2049 void SetMobile_username(STRPTR w
)
2051 if (strlen(w
) < NAMEBUFLEN
)
2052 strcpy(prefs
.mobile
.username
, w
);
2055 void SetMobile_password(STRPTR w
)
2057 if (strlen(w
) < NAMEBUFLEN
)
2058 strcpy(prefs
.mobile
.password
, w
);
2061 void SetMobile_unit(LONG w
)
2063 prefs
.mobile
.unit
= w
;
2066 void SetMobile_timeout(LONG w
)
2068 prefs
.mobile
.timeout
= w
;
2073 struct Server
*server
, STRPTR device
, STRPTR host
, STRPTR service
,
2074 STRPTR user
, STRPTR group
, STRPTR pass
, BOOL active
2077 SetServerDevice(server
, device
);
2078 SetServerHost(server
, host
);
2079 SetServerService(server
, service
);
2080 SetServerUser(server
, user
);
2081 SetServerGroup(server
, group
);
2082 SetServerPass(server
, pass
);
2083 SetServerActive(server
, active
);
2086 void SetServerDevice(struct Server
*server
, STRPTR w
)
2088 strlcpy(server
->device
, w
, SMBBUFLEN
);
2091 void SetServerHost(struct Server
*server
, STRPTR w
)
2093 strlcpy(server
->host
, w
, NAMEBUFLEN
);
2096 void SetServerService(struct Server
*server
, STRPTR w
)
2098 strlcpy(server
->service
, w
, SMBBUFLEN
);
2101 void SetServerUser(struct Server
*server
, STRPTR w
)
2103 strlcpy(server
->user
, w
, SMBBUFLEN
);
2106 void SetServerGroup(struct Server
*server
, STRPTR w
)
2108 strlcpy(server
->group
, w
, SMBBUFLEN
);
2111 void SetServerPass(struct Server
*server
, STRPTR w
)
2113 strlcpy(server
->pass
, w
, SMBBUFLEN
);
2116 void SetServerActive(struct Server
*server
, BOOL w
)
2121 void SetServerCount(LONG w
)
2123 prefs
.serverCount
= w
;