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 */
1482 service
= FilePart((STRPTR
)control_args
[ARG_SERVICE
]);
1483 SetServerService(server
, service
);
1486 host
= (STRPTR
)control_args
[ARG_SERVICE
] + 2;
1487 SetServerHost(server
, host
);
1489 SetServerUser(server
, (STRPTR
)control_args
[ARG_USERNAME
]);
1490 SetServerGroup(server
, (STRPTR
)control_args
[ARG_WORKGROUP
]);
1491 SetServerPass(server
, (STRPTR
)control_args
[ARG_PASSWORD
]);
1494 if (control_rdargs
!= NULL
)
1496 FreeArgs(control_rdargs
);
1497 FreeDosObject(DOS_RDARGS
, control_rdargs
);
1500 if (mount_rdargs
!= NULL
)
1502 FreeArgs(mount_rdargs
);
1503 FreeDosObject(DOS_RDARGS
, mount_rdargs
);
1510 void InitNetworkPrefs(CONST_STRPTR directory
, BOOL use
, BOOL save
)
1512 SetDefaultNetworkPrefsValues();
1513 SetDefaultWirelessPrefsValues();
1514 SetDefaultMobilePrefsValues();
1516 ReadNetworkPrefs(directory
);
1517 ReadWirelessPrefs(WIRELESS_PATH_ENV
);
1518 ReadMobilePrefs(MOBILEBB_PATH_ENV
);
1524 return; /* save equals to use */
1533 // check if 'str' contains only characters from 'accept'
1534 BOOL
IsLegal(STRPTR str
, STRPTR accept
)
1538 if ((str
== NULL
) || (accept
== NULL
) || (str
[0] == '\0'))
1544 for (i
= 0; i
< len
; i
++)
1546 if (strchr(accept
, str
[i
]) == NULL
)
1557 struct Interface
* GetInterface(LONG index
)
1559 return &prefs
.interface
[index
];
1562 STRPTR
GetName(struct Interface
*iface
)
1567 BOOL
GetIfDHCP(struct Interface
*iface
)
1569 return iface
->ifDHCP
;
1572 STRPTR
GetIP(struct Interface
*iface
)
1577 STRPTR
GetMask(struct Interface
*iface
)
1582 STRPTR
GetDevice(struct Interface
*iface
)
1584 return iface
->device
;
1587 LONG
GetUnit(struct Interface
*iface
)
1592 BOOL
GetUp(struct Interface
*iface
)
1597 STRPTR
GetGate(void)
1602 STRPTR
GetDNS(LONG m
)
1604 return prefs
.DNS
[m
];
1607 STRPTR
GetHostname(void)
1612 STRPTR
GetDomain(void)
1614 return prefs
.domain
;
1617 LONG
GetInterfaceCount(void)
1619 return prefs
.interfacecount
;
1622 BOOL
GetAutostart(void)
1624 return prefs
.autostart
;
1637 struct Interface
*iface
, STRPTR name
, BOOL dhcp
, STRPTR IP
, STRPTR mask
,
1638 STRPTR device
, LONG unit
, BOOL up
1641 SetName(iface
, name
);
1642 SetIfDHCP(iface
, dhcp
);
1644 SetMask(iface
, mask
);
1645 SetDevice(iface
, device
);
1646 SetUnit(iface
, unit
);
1650 void SetName(struct Interface
*iface
, STRPTR w
)
1652 if (!IsLegal(w
, NAMECHARS
))
1656 strlcpy(iface
->name
, w
, NAMEBUFLEN
);
1659 void SetIfDHCP(struct Interface
*iface
, BOOL w
)
1664 void SetIP(struct Interface
*iface
, STRPTR w
)
1666 if (!IsLegal(w
, IPCHARS
))
1670 strlcpy(iface
->IP
, w
, IPBUFLEN
);
1673 void SetMask(struct Interface
*iface
, STRPTR w
)
1675 if (!IsLegal(w
, IPCHARS
))
1679 strlcpy(iface
->mask
, w
, IPBUFLEN
);
1682 void SetDevice(struct Interface
*iface
, STRPTR w
)
1684 if (w
== NULL
|| w
[0] == '\0')
1688 strlcpy(iface
->device
, w
, NAMEBUFLEN
);
1691 void SetUnit(struct Interface
*iface
, LONG w
)
1696 void SetUp(struct Interface
*iface
, BOOL w
)
1701 void SetGate(STRPTR w
)
1703 if (!IsLegal(w
, IPCHARS
))
1707 strlcpy(prefs
.gate
, w
, IPBUFLEN
);
1710 void SetDNS(LONG m
, STRPTR w
)
1712 if (!IsLegal(w
, IPCHARS
))
1716 strlcpy(prefs
.DNS
[m
], w
, IPBUFLEN
);
1719 void SetHostname(STRPTR w
)
1721 if (!IsLegal(w
, NAMECHARS
))
1725 strlcpy(prefs
.host
, w
, NAMEBUFLEN
);
1728 void SetDomain(STRPTR w
)
1730 if (!IsLegal(w
, NAMECHARS
))
1734 strlcpy(prefs
.domain
, w
, NAMEBUFLEN
);
1737 void SetInterfaceCount(LONG w
)
1739 prefs
.interfacecount
= w
;
1742 void SetAutostart(BOOL w
)
1744 prefs
.autostart
= w
;
1747 void SetDHCP(BOOL w
)
1752 void InitHost(struct Host
*host
)
1754 SetHostNames(host
, "");
1755 SetHostAddress(host
, "");
1758 void InitNetwork(struct Network
*net
)
1760 SetNetworkName(net
, "");
1761 SetKey(net
, "", FALSE
);
1763 SetAdHoc(net
, FALSE
);
1766 void InitServer(struct Server
*server
, char *workgroup
)
1768 if ((workgroup
== NULL
) && ((workgroup
= GetDomain()) == NULL
))
1769 workgroup
= "workgroup";
1771 SetServerDevice(server
, DEFAULTSERVERDEV
);
1772 SetServerHost(server
, "");
1773 SetServerGroup(server
, workgroup
);
1774 SetServerService(server
, "share");
1775 SetServerUser(server
, "guest");
1776 SetServerPass(server
, "");
1777 SetServerActive(server
, TRUE
);
1783 struct Host
*GetHost(LONG index
)
1785 return &prefs
.hosts
[index
];
1788 STRPTR
GetHostNames(struct Host
*host
)
1793 STRPTR
GetHostAddress(struct Host
*host
)
1795 return host
->address
;
1798 LONG
GetHostCount(void)
1800 return prefs
.hostCount
;
1803 struct Network
*GetNetwork(LONG index
)
1805 return &prefs
.networks
[index
];
1808 STRPTR
GetNetworkName(struct Network
*net
)
1813 UWORD
GetEncType(struct Network
*net
)
1815 return net
->encType
;
1818 STRPTR
GetKey(struct Network
*net
)
1823 BOOL
GetHidden(struct Network
*net
)
1828 BOOL
GetAdHoc(struct Network
*net
)
1833 LONG
GetNetworkCount(void)
1835 return prefs
.networkCount
;
1838 STRPTR
GetWirelessDevice(void)
1840 return prefs
.wirelessDevice
;
1843 LONG
GetWirelessUnit(void)
1845 return prefs
.wirelessUnit
;
1848 BOOL
GetMobile_Autostart(void)
1850 return prefs
.mobile
.autostart
;
1853 STRPTR
GetMobile_atcommand(ULONG i
)
1855 if (i
< MAXATCOMMANDS
)
1856 return prefs
.mobile
.atcommand
[i
];
1860 LONG
GetMobile_atcommandcount(void)
1864 for (i
= 0; i
< MAXATCOMMANDS
; i
++)
1866 if (prefs
.mobile
.atcommand
[i
][0] != 0) count
++;
1871 STRPTR
GetMobile_devicename(void)
1873 return prefs
.mobile
.devicename
;
1876 STRPTR
GetMobile_username(void)
1878 return prefs
.mobile
.username
;
1881 STRPTR
GetMobile_password(void)
1883 return prefs
.mobile
.password
;
1886 LONG
GetMobile_unit(void)
1888 return prefs
.mobile
.unit
;
1891 LONG
GetMobile_timeout(void)
1893 return prefs
.mobile
.timeout
;
1896 struct Server
*GetServer(LONG index
)
1898 return &prefs
.servers
[index
];
1901 STRPTR
GetServerDevice(struct Server
*server
)
1903 return server
->device
;
1906 STRPTR
GetServerHost(struct Server
*server
)
1908 return server
->host
;
1911 STRPTR
GetServerService(struct Server
*server
)
1913 return server
->service
;
1916 STRPTR
GetServerUser(struct Server
*server
)
1918 return server
->user
;
1921 STRPTR
GetServerGroup(struct Server
*server
)
1923 return server
->group
;
1926 STRPTR
GetServerPass(struct Server
*server
)
1928 return server
->pass
;
1931 BOOL
GetServerActive(struct Server
*server
)
1933 return server
->active
;
1936 LONG
GetServerCount(void)
1938 return prefs
.serverCount
;
1945 struct Host
*host
, STRPTR name
, STRPTR address
1948 SetHostNames(host
, name
);
1949 SetHostAddress(host
, address
);
1952 void SetHostNames(struct Host
*host
, STRPTR w
)
1954 strlcpy(host
->names
, w
, NAMEBUFLEN
);
1957 void AddHostName(struct Host
*host
, STRPTR w
)
1959 if (host
->names
[0] != '\0')
1960 strlcat(host
->names
, " ", NAMEBUFLEN
);
1961 strlcat(host
->names
, w
, NAMEBUFLEN
);
1964 void SetHostAddress(struct Host
*host
, STRPTR w
)
1966 strlcpy(host
->address
, w
, IPBUFLEN
);
1969 void SetHostCount(LONG w
)
1971 prefs
.hostCount
= w
;
1976 struct Network
*net
, STRPTR name
, UWORD encType
, STRPTR key
,
1977 BOOL keyIsHex
, BOOL hidden
, BOOL adHoc
1980 SetNetworkName(net
, name
);
1981 SetEncType(net
, encType
);
1982 SetKey(net
, key
, keyIsHex
);
1983 SetHidden(net
, hidden
);
1984 SetAdHoc(net
, adHoc
);
1987 void SetNetworkName(struct Network
*net
, STRPTR w
)
1989 strlcpy(net
->name
, w
, SSIDBUFLEN
);
1992 void SetEncType(struct Network
*net
, UWORD w
)
1997 void SetKey(struct Network
*net
, STRPTR w
, BOOL keyIsHex
)
1999 strlcpy(net
->key
, w
, KEYBUFLEN
);
2000 net
->keyIsHex
= keyIsHex
;
2003 void SetHidden(struct Network
*net
, BOOL w
)
2008 void SetAdHoc(struct Network
*net
, BOOL w
)
2013 void SetNetworkCount(LONG w
)
2015 prefs
.networkCount
= w
;
2018 void SetWirelessDevice(STRPTR w
)
2020 prefs
.wirelessDevice
= w
;
2023 void SetWirelessUnit(LONG w
)
2025 prefs
.wirelessUnit
= w
;
2028 void SetMobile_Autostart(BOOL w
)
2030 prefs
.mobile
.autostart
= w
;
2033 void SetMobile_atcommand(ULONG i
,STRPTR w
)
2035 if (strlen(w
) < NAMEBUFLEN
&& i
>= 0 && i
< MAXATCOMMANDS
)
2036 strcpy(prefs
.mobile
.atcommand
[i
], w
);
2039 void SetMobile_devicename(STRPTR w
)
2041 if (strlen(w
) < NAMEBUFLEN
)
2042 strcpy(prefs
.mobile
.devicename
, w
);
2045 void SetMobile_username(STRPTR w
)
2047 if (strlen(w
) < NAMEBUFLEN
)
2048 strcpy(prefs
.mobile
.username
, w
);
2051 void SetMobile_password(STRPTR w
)
2053 if (strlen(w
) < NAMEBUFLEN
)
2054 strcpy(prefs
.mobile
.password
, w
);
2057 void SetMobile_unit(LONG w
)
2059 prefs
.mobile
.unit
= w
;
2062 void SetMobile_timeout(LONG w
)
2064 prefs
.mobile
.timeout
= w
;
2069 struct Server
*server
, STRPTR device
, STRPTR host
, STRPTR service
,
2070 STRPTR user
, STRPTR group
, STRPTR pass
, BOOL active
2073 SetServerDevice(server
, device
);
2074 SetServerHost(server
, host
);
2075 SetServerService(server
, service
);
2076 SetServerUser(server
, user
);
2077 SetServerGroup(server
, group
);
2078 SetServerPass(server
, pass
);
2079 SetServerActive(server
, active
);
2082 void SetServerDevice(struct Server
*server
, STRPTR w
)
2084 strlcpy(server
->device
, w
, SMBBUFLEN
);
2087 void SetServerHost(struct Server
*server
, STRPTR w
)
2089 strlcpy(server
->host
, w
, NAMEBUFLEN
);
2092 void SetServerService(struct Server
*server
, STRPTR w
)
2094 strlcpy(server
->service
, w
, SMBBUFLEN
);
2097 void SetServerUser(struct Server
*server
, STRPTR w
)
2099 strlcpy(server
->user
, w
, SMBBUFLEN
);
2102 void SetServerGroup(struct Server
*server
, STRPTR w
)
2104 strlcpy(server
->group
, w
, SMBBUFLEN
);
2107 void SetServerPass(struct Server
*server
, STRPTR w
)
2109 strlcpy(server
->pass
, w
, SMBBUFLEN
);
2112 void SetServerActive(struct Server
*server
, BOOL w
)
2117 void SetServerCount(LONG w
)
2119 prefs
.serverCount
= w
;