author | tille <tille> | 2003-05-24 23:34:09 (UTC) |
---|---|---|
committer | tille <tille> | 2003-05-24 23:34:09 (UTC) |
commit | d1c32c127b4dabb716064a790da6be7c24975a92 (patch) (unidiff) | |
tree | aa8a7865d4cccbc696c534d8de3ef3b139777c34 | |
parent | 58947769d80d49faaccac1703da0e66c90158957 (diff) | |
download | opie-d1c32c127b4dabb716064a790da6be7c24975a92.zip opie-d1c32c127b4dabb716064a790da6be7c24975a92.tar.gz opie-d1c32c127b4dabb716064a790da6be7c24975a92.tar.bz2 |
pppd stuff
-rw-r--r-- | noncore/settings/networksettings/ppp/modem.cpp | 229 | ||||
-rw-r--r-- | noncore/settings/networksettings/ppp/modem.h | 6 | ||||
-rw-r--r-- | noncore/settings/networksettings/ppp/pppdata.cpp | 134 | ||||
-rw-r--r-- | noncore/settings/networksettings/ppp/pppdata.h | 35 | ||||
-rw-r--r-- | noncore/settings/networksettings/ppp/pppmodule.cpp | 28 |
5 files changed, 330 insertions, 102 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index cd5d21c..5139482 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <errno.h> | 27 | #include <errno.h> |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <unistd.h> | ||
29 | #include <fcntl.h> | 30 | #include <fcntl.h> |
30 | #include <signal.h> | 31 | #include <signal.h> |
31 | #include <sys/ioctl.h> | 32 | #include <sys/ioctl.h> |
@@ -33,7 +34,18 @@ | |||
33 | #include <regex.h> | 34 | #include <regex.h> |
34 | #include <qregexp.h> | 35 | #include <qregexp.h> |
35 | #include <assert.h> | 36 | #include <assert.h> |
37 | #include <string.h> | ||
36 | 38 | ||
39 | #ifdef HAVE_RESOLV_H | ||
40 | # include <arpa/nameser.h> | ||
41 | # include <resolv.h> | ||
42 | #endif | ||
43 | |||
44 | #ifndef _PATH_RESCONF | ||
45 | #define _PATH_RESCONF "/etc/resolv.conf" | ||
46 | #endif | ||
47 | |||
48 | #define strlcpy strcpy | ||
37 | #include "auth.h" | 49 | #include "auth.h" |
38 | #include "modem.h" | 50 | #include "modem.h" |
39 | #include "pppdata.h" | 51 | #include "pppdata.h" |
@@ -83,6 +95,8 @@ Modem::Modem() | |||
83 | { | 95 | { |
84 | if (Modem::modem != 0) return; //CORRECT? | 96 | if (Modem::modem != 0) return; //CORRECT? |
85 | modemfd = -1; | 97 | modemfd = -1; |
98 | _pppdExitStatus = -1; | ||
99 | pppdPid = -1; | ||
86 | sn = 0L; | 100 | sn = 0L; |
87 | data_mode = false; | 101 | data_mode = false; |
88 | modem_is_locked = false; | 102 | modem_is_locked = false; |
@@ -755,6 +769,22 @@ bool Modem::createAuthFile(Auth method, const char *username, const char *passwo | |||
755 | } | 769 | } |
756 | 770 | ||
757 | 771 | ||
772 | bool Modem::removeAuthFile(Auth method) { | ||
773 | const char *authfile, *oldName; | ||
774 | |||
775 | if(!(authfile = authFile(method))) | ||
776 | return false; | ||
777 | if(!(oldName = authFile(method, Old))) | ||
778 | return false; | ||
779 | |||
780 | if(access(oldName, F_OK) == 0) { | ||
781 | unlink(authfile); | ||
782 | return (rename(oldName, authfile) == 0); | ||
783 | } else | ||
784 | return false; | ||
785 | } | ||
786 | |||
787 | |||
758 | bool Modem::setSecret(int method, const char* name, const char* password) | 788 | bool Modem::setSecret(int method, const char* name, const char* password) |
759 | { | 789 | { |
760 | 790 | ||
@@ -778,32 +808,215 @@ bool Modem::setSecret(int method, const char* name, const char* password) | |||
778 | 808 | ||
779 | } | 809 | } |
780 | 810 | ||
781 | bool Modem::removeSecret(int) | 811 | bool Modem::removeSecret(int method) |
782 | { | 812 | { |
783 | return true; | 813 | Auth auth; |
814 | |||
815 | switch(method) { | ||
816 | case AUTH_PAP: | ||
817 | auth = Modem::PAP; | ||
818 | break; | ||
819 | case AUTH_CHAP: | ||
820 | auth = Modem::CHAP; | ||
821 | break; | ||
822 | default: | ||
823 | return false; | ||
824 | } | ||
825 | return removeAuthFile( auth ); | ||
784 | } | 826 | } |
785 | 827 | ||
786 | void Modem::killPPPDaemon() | 828 | int checkForInterface() |
787 | { | 829 | { |
830 | // I don't know if Linux needs more initialization to get the ioctl to | ||
831 | // work, pppd seems to hint it does. But BSD doesn't, and the following | ||
832 | // code should compile. | ||
833 | #if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__) | ||
834 | int s, ok; | ||
835 | struct ifreq ifr; | ||
836 | // extern char *no_ppp_msg; | ||
837 | |||
838 | if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) | ||
839 | return 1; /* can't tell */ | ||
840 | |||
841 | strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); | ||
842 | ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; | ||
843 | close(s); | ||
844 | |||
845 | if (ok == -1) { | ||
846 | // This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports | ||
847 | // KLDs, the old LKM interface couldn't handle loading devices | ||
848 | // dynamically, and thus can't load ppp support on the fly | ||
849 | #ifdef __FreeBSD__ | ||
850 | // If we failed to load ppp support and don't have it already. | ||
851 | if (kldload("if_ppp") == -1) { | ||
852 | return -1; | ||
853 | } | ||
854 | return 0; | ||
855 | #else | ||
856 | return -1; | ||
857 | #endif | ||
858 | } | ||
859 | return 0; | ||
860 | #else | ||
861 | // We attempt to use the SunOS/SysVr4 method and stat /dev/ppp | ||
862 | struct stat buf; | ||
863 | |||
864 | memset(&buf, 0, sizeof(buf)); | ||
865 | return stat("/dev/ppp", &buf); | ||
866 | #endif | ||
788 | } | 867 | } |
789 | 868 | ||
790 | int Modem::pppdExitStatus() | 869 | bool Modem::execpppd(const char *arguments) { |
791 | { | 870 | char buf[MAX_CMDLEN]; |
792 | return -1; | 871 | char *args[MaxArgs]; |
872 | pid_t pgrpid; | ||
873 | |||
874 | if(modemfd<0) | ||
875 | return false; | ||
876 | |||
877 | _pppdExitStatus = -1; | ||
878 | |||
879 | switch(pppdPid = fork()) | ||
880 | { | ||
881 | case -1: | ||
882 | fprintf(stderr,"In parent: fork() failed\n"); | ||
883 | return false; | ||
884 | break; | ||
885 | |||
886 | case 0: | ||
887 | // let's parse the arguments the user supplied into UNIX suitable form | ||
888 | // that is a list of pointers each pointing to exactly one word | ||
889 | strlcpy(buf, arguments); | ||
890 | parseargs(buf, args); | ||
891 | // become a session leader and let /dev/ttySx | ||
892 | // be the controlling terminal. | ||
893 | pgrpid = setsid(); | ||
894 | #ifdef TIOCSCTTY | ||
895 | if(ioctl(modemfd, TIOCSCTTY, 0)<0) | ||
896 | fprintf(stderr, "ioctl() failed.\n"); | ||
897 | #elif defined (TIOCSPGRP) | ||
898 | if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0) | ||
899 | fprintf(stderr, "ioctl() failed.\n"); | ||
900 | #endif | ||
901 | if(tcsetpgrp(modemfd, pgrpid)<0) | ||
902 | fprintf(stderr, "tcsetpgrp() failed.\n"); | ||
903 | |||
904 | dup2(modemfd, 0); | ||
905 | dup2(modemfd, 1); | ||
906 | |||
907 | switch (checkForInterface()) { | ||
908 | case 1: | ||
909 | fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); | ||
910 | break; | ||
911 | case -1: | ||
912 | fprintf(stderr, "Kernel does not support ppp, oops.\n"); | ||
913 | break; | ||
914 | case 0: | ||
915 | fprintf(stderr, "Kernel supports ppp alright.\n"); | ||
916 | break; | ||
917 | } | ||
918 | |||
919 | execve(pppdPath(), args, 0L); | ||
920 | _exit(0); | ||
921 | break; | ||
922 | |||
923 | default: | ||
924 | qDebug("In parent: pppd pid %d\n",pppdPid); | ||
925 | close(modemfd); | ||
926 | modemfd = -1; | ||
927 | return true; | ||
928 | break; | ||
929 | } | ||
930 | } | ||
931 | |||
932 | |||
933 | bool Modem::killpppd() { | ||
934 | if(pppdPid > 0) { | ||
935 | qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid); | ||
936 | if(kill(pppdPid, SIGTERM) < 0) { | ||
937 | qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid); | ||
938 | if(kill(pppdPid, SIGKILL) < 0) { | ||
939 | qDebug("Error killing %d\n", pppdPid); | ||
940 | return false; | ||
941 | } | ||
942 | } | ||
943 | } | ||
944 | return true; | ||
945 | } | ||
946 | |||
947 | |||
948 | void Modem::parseargs(char* buf, char** args) { | ||
949 | int nargs = 0; | ||
950 | int quotes; | ||
951 | |||
952 | while(nargs < MaxArgs-1 && *buf != '\0') { | ||
953 | |||
954 | quotes = 0; | ||
955 | |||
956 | // Strip whitespace. Use nulls, so that the previous argument is | ||
957 | // terminated automatically. | ||
958 | |||
959 | while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) ) | ||
960 | *buf++ = '\0'; | ||
961 | |||
962 | // detect begin of quoted argument | ||
963 | if (*buf == '"' || *buf == '\'') { | ||
964 | quotes = *buf; | ||
965 | *buf++ = '\0'; | ||
966 | } | ||
967 | |||
968 | // save the argument | ||
969 | if(*buf != '\0') { | ||
970 | *args++ = buf; | ||
971 | nargs++; | ||
972 | } | ||
973 | |||
974 | if (!quotes) | ||
975 | while ((*buf != '\0') && (*buf != '\n') && | ||
976 | (*buf != '\t') && (*buf != ' ')) | ||
977 | buf++; | ||
978 | else { | ||
979 | while ((*buf != '\0') && (*buf != quotes)) | ||
980 | buf++; | ||
981 | *buf++ = '\0'; | ||
982 | } | ||
983 | } | ||
984 | |||
985 | *args = 0L; | ||
793 | } | 986 | } |
794 | 987 | ||
795 | bool Modem::execPPPDaemon(const QString & arguments) | 988 | bool Modem::execPPPDaemon(const QString & arguments) |
796 | { | 989 | { |
990 | if(execpppd(arguments)==0) { | ||
991 | PPPData::data()->setpppdRunning(true); | ||
797 | return true; | 992 | return true; |
993 | } else | ||
994 | return false; | ||
995 | } | ||
996 | |||
997 | void Modem::killPPPDaemon() | ||
998 | { | ||
999 | PPPData::data()->setpppdRunning(false); | ||
1000 | killpppd(); | ||
1001 | } | ||
1002 | |||
1003 | int Modem::pppdExitStatus() | ||
1004 | { | ||
1005 | return _pppdExitStatus; | ||
798 | } | 1006 | } |
799 | 1007 | ||
800 | int Modem::openResolv(int flags) | 1008 | int Modem::openResolv(int flags) |
801 | { | 1009 | { |
802 | return -1; | 1010 | int fd; |
1011 | if ((fd = open(_PATH_RESCONF, flags)) == -1) { | ||
1012 | qDebug("error opening resolv.conf!"); | ||
1013 | fd = open(DEVNULL, O_RDONLY); | ||
1014 | } | ||
1015 | return fd; | ||
803 | } | 1016 | } |
804 | 1017 | ||
805 | bool Modem::setHostname(const QString & name) | 1018 | bool Modem::setHostname(const QString & name) |
806 | { | 1019 | { |
807 | return true; | 1020 | return sethostname(name, name.length()) == 0; |
808 | } | 1021 | } |
809 | 1022 | ||
diff --git a/noncore/settings/networksettings/ppp/modem.h b/noncore/settings/networksettings/ppp/modem.h index 052be4a..b494977 100644 --- a/noncore/settings/networksettings/ppp/modem.h +++ b/noncore/settings/networksettings/ppp/modem.h | |||
@@ -93,6 +93,10 @@ private: | |||
93 | 93 | ||
94 | const char* authFile(Auth method, int version = Original ); | 94 | const char* authFile(Auth method, int version = Original ); |
95 | bool createAuthFile(Auth method,const char *username,const char *password); | 95 | bool createAuthFile(Auth method,const char *username,const char *password); |
96 | bool removeAuthFile(Auth method); | ||
97 | bool execpppd(const char *arguments); | ||
98 | bool killpppd(); | ||
99 | void parseargs(char* buf, char** args); | ||
96 | void escape_to_command_mode(); | 100 | void escape_to_command_mode(); |
97 | int openLockfile(QString,int); | 101 | int openLockfile(QString,int); |
98 | 102 | ||
@@ -100,6 +104,8 @@ private: | |||
100 | QString device; | 104 | QString device; |
101 | QString lockfile; | 105 | QString lockfile; |
102 | int modemfd; | 106 | int modemfd; |
107 | int pppdPid; | ||
108 | int _pppdExitStatus; | ||
103 | QSocketNotifier *sn; | 109 | QSocketNotifier *sn; |
104 | bool data_mode; | 110 | bool data_mode; |
105 | QString errmsg; | 111 | QString errmsg; |
diff --git a/noncore/settings/networksettings/ppp/pppdata.cpp b/noncore/settings/networksettings/ppp/pppdata.cpp index 646facd..bb1c8ed 100644 --- a/noncore/settings/networksettings/ppp/pppdata.cpp +++ b/noncore/settings/networksettings/ppp/pppdata.cpp | |||
@@ -323,27 +323,27 @@ void PPPData::setpppdTimeout(int n) { | |||
323 | 323 | ||
324 | 324 | ||
325 | const QString PPPData::modemDevice() { | 325 | const QString PPPData::modemDevice() { |
326 | return readConfig (MODEM_GRP, MODEMDEV_KEY, devices[DEV_DEFAULT]); | 326 | return readConfig (modemGroup(), MODEMDEV_KEY, devices[DEV_DEFAULT]); |
327 | } | 327 | } |
328 | 328 | ||
329 | 329 | ||
330 | void PPPData::setModemDevice(const QString &n) { | 330 | void PPPData::setModemDevice(const QString &n) { |
331 | writeConfig(MODEM_GRP, MODEMDEV_KEY, n); | 331 | writeConfig(modemGroup(), MODEMDEV_KEY, n); |
332 | } | 332 | } |
333 | 333 | ||
334 | 334 | ||
335 | const QString PPPData::flowcontrol() { | 335 | const QString PPPData::flowcontrol() { |
336 | return readConfig(MODEM_GRP, FLOWCONTROL_KEY, "CRTSCTS"); | 336 | return readConfig(modemGroup(), FLOWCONTROL_KEY, "CRTSCTS"); |
337 | } | 337 | } |
338 | 338 | ||
339 | 339 | ||
340 | void PPPData::setFlowcontrol(const QString &n) { | 340 | void PPPData::setFlowcontrol(const QString &n) { |
341 | writeConfig(MODEM_GRP, FLOWCONTROL_KEY, n); | 341 | writeConfig(modemGroup(), FLOWCONTROL_KEY, n); |
342 | } | 342 | } |
343 | 343 | ||
344 | 344 | ||
345 | const QString PPPData::speed() { | 345 | const QString PPPData::speed() { |
346 | QString s = readConfig(MODEM_GRP, SPEED_KEY, "57600"); | 346 | QString s = readConfig(modemGroup(), SPEED_KEY, "57600"); |
347 | // undo the damage of a bug in former versions. It left an empty Speed= | 347 | // undo the damage of a bug in former versions. It left an empty Speed= |
348 | // entry in kppprc. kppp did set the serial port to 57600 as default but | 348 | // entry in kppprc. kppp did set the serial port to 57600 as default but |
349 | // pppd wouldn't receive the speed via the command line. | 349 | // pppd wouldn't receive the speed via the command line. |
@@ -354,88 +354,88 @@ const QString PPPData::speed() { | |||
354 | 354 | ||
355 | 355 | ||
356 | void PPPData::setSpeed(const QString &n) { | 356 | void PPPData::setSpeed(const QString &n) { |
357 | writeConfig(MODEM_GRP, SPEED_KEY, n); | 357 | writeConfig(modemGroup(), SPEED_KEY, n); |
358 | } | 358 | } |
359 | 359 | ||
360 | 360 | ||
361 | #if 0 | 361 | #if 0 |
362 | void PPPData::setUseCDLine(const int n) { | 362 | void PPPData::setUseCDLine(const int n) { |
363 | writeConfig(MODEM_GRP,USECDLINE_KEY,n); | 363 | writeConfig(modemGroup(),USECDLINE_KEY,n); |
364 | } | 364 | } |
365 | 365 | ||
366 | 366 | ||
367 | int PPPData::UseCDLine() { | 367 | int PPPData::UseCDLine() { |
368 | return readNumConfig(MODEM_GRP,USECDLINE_KEY,0); | 368 | return readNumConfig(modemGroup(),USECDLINE_KEY,0); |
369 | } | 369 | } |
370 | #endif | 370 | #endif |
371 | 371 | ||
372 | const QString PPPData::modemEscapeStr() { | 372 | const QString PPPData::modemEscapeStr() { |
373 | return readConfig(MODEM_GRP,ESCAPESTR_KEY,"+++"); | 373 | return readConfig(modemGroup(),ESCAPESTR_KEY,"+++"); |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | void PPPData::setModemEscapeStr(const QString &n) { | 377 | void PPPData::setModemEscapeStr(const QString &n) { |
378 | writeConfig(MODEM_GRP,ESCAPESTR_KEY,n); | 378 | writeConfig(modemGroup(),ESCAPESTR_KEY,n); |
379 | } | 379 | } |
380 | 380 | ||
381 | 381 | ||
382 | const QString PPPData::modemEscapeResp() { | 382 | const QString PPPData::modemEscapeResp() { |
383 | return readConfig(MODEM_GRP,ESCAPERESP_KEY,"OK"); | 383 | return readConfig(modemGroup(),ESCAPERESP_KEY,"OK"); |
384 | } | 384 | } |
385 | 385 | ||
386 | 386 | ||
387 | void PPPData::setModemEscapeResp(const QString &n) { | 387 | void PPPData::setModemEscapeResp(const QString &n) { |
388 | writeConfig(MODEM_GRP,ESCAPERESP_KEY,n); | 388 | writeConfig(modemGroup(),ESCAPERESP_KEY,n); |
389 | } | 389 | } |
390 | 390 | ||
391 | 391 | ||
392 | int PPPData::modemEscapeGuardTime() { | 392 | int PPPData::modemEscapeGuardTime() { |
393 | return readNumConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,50); | 393 | return readNumConfig(modemGroup(),ESCAPEGUARDTIME_KEY,50); |
394 | } | 394 | } |
395 | 395 | ||
396 | 396 | ||
397 | void PPPData::setModemEscapeGuardTime(int n) { | 397 | void PPPData::setModemEscapeGuardTime(int n) { |
398 | writeConfig(MODEM_GRP,ESCAPEGUARDTIME_KEY,n); | 398 | writeConfig(modemGroup(),ESCAPEGUARDTIME_KEY,n); |
399 | } | 399 | } |
400 | 400 | ||
401 | 401 | ||
402 | bool PPPData::modemLockFile() { | 402 | bool PPPData::modemLockFile() { |
403 | return readNumConfig(MODEM_GRP, LOCKFILE_KEY, 1); | 403 | return readNumConfig(modemGroup(), LOCKFILE_KEY, 1); |
404 | } | 404 | } |
405 | 405 | ||
406 | 406 | ||
407 | void PPPData::setModemLockFile(bool set) { | 407 | void PPPData::setModemLockFile(bool set) { |
408 | writeConfig(MODEM_GRP, LOCKFILE_KEY, set); | 408 | writeConfig(modemGroup(), LOCKFILE_KEY, set); |
409 | } | 409 | } |
410 | 410 | ||
411 | 411 | ||
412 | int PPPData::modemTimeout() { | 412 | int PPPData::modemTimeout() { |
413 | return readNumConfig(MODEM_GRP, TIMEOUT_KEY, MODEM_TIMEOUT); | 413 | return readNumConfig(modemGroup(), TIMEOUT_KEY, MODEM_TIMEOUT); |
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | void PPPData::setModemTimeout(int n) { | 417 | void PPPData::setModemTimeout(int n) { |
418 | writeConfig(MODEM_GRP, TIMEOUT_KEY, n); | 418 | writeConfig(modemGroup(), TIMEOUT_KEY, n); |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
422 | int PPPData::modemToneDuration() { | 422 | int PPPData::modemToneDuration() { |
423 | return readNumConfig(MODEM_GRP, TONEDURATION_KEY,MODEM_TONEDURATION); | 423 | return readNumConfig(modemGroup(), TONEDURATION_KEY,MODEM_TONEDURATION); |
424 | } | 424 | } |
425 | 425 | ||
426 | 426 | ||
427 | void PPPData::setModemToneDuration(int n) { | 427 | void PPPData::setModemToneDuration(int n) { |
428 | writeConfig(MODEM_GRP, TONEDURATION_KEY, n); | 428 | writeConfig(modemGroup(), TONEDURATION_KEY, n); |
429 | } | 429 | } |
430 | 430 | ||
431 | 431 | ||
432 | int PPPData::busyWait() { | 432 | int PPPData::busyWait() { |
433 | return readNumConfig(MODEM_GRP, BUSYWAIT_KEY, BUSY_WAIT); | 433 | return readNumConfig(modemGroup(), BUSYWAIT_KEY, BUSY_WAIT); |
434 | } | 434 | } |
435 | 435 | ||
436 | 436 | ||
437 | void PPPData::setbusyWait(int n) { | 437 | void PPPData::setbusyWait(int n) { |
438 | writeConfig(MODEM_GRP, BUSYWAIT_KEY, n); | 438 | writeConfig(modemGroup(), BUSYWAIT_KEY, n); |
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
@@ -446,151 +446,151 @@ void PPPData::setbusyWait(int n) { | |||
446 | const QString PPPData::modemInitStr(int i) { | 446 | const QString PPPData::modemInitStr(int i) { |
447 | assert(i >= 0 && i < NumInitStrings); | 447 | assert(i >= 0 && i < NumInitStrings); |
448 | if(i == 0) | 448 | if(i == 0) |
449 | return readConfig(MODEM_GRP, INITSTR_KEY, "ATZ"); | 449 | return readConfig(modemGroup(), INITSTR_KEY, "ATZ"); |
450 | else | 450 | else |
451 | return readConfig(MODEM_GRP, INITSTR_KEY + QString::number(i), ""); | 451 | return readConfig(modemGroup(), INITSTR_KEY + QString::number(i), ""); |
452 | } | 452 | } |
453 | 453 | ||
454 | 454 | ||
455 | void PPPData::setModemInitStr(int i, const QString &n) { | 455 | void PPPData::setModemInitStr(int i, const QString &n) { |
456 | assert(i >= 0 && i < NumInitStrings); | 456 | assert(i >= 0 && i < NumInitStrings); |
457 | QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : ""); | 457 | QString k = INITSTR_KEY + (i > 0 ? QString::number(i) : ""); |
458 | writeConfig(MODEM_GRP, k, n); | 458 | writeConfig(modemGroup(), k, n); |
459 | } | 459 | } |
460 | 460 | ||
461 | 461 | ||
462 | const QString PPPData::modemInitResp() { | 462 | const QString PPPData::modemInitResp() { |
463 | return readConfig(MODEM_GRP, INITRESP_KEY, "OK"); | 463 | return readConfig(modemGroup(), INITRESP_KEY, "OK"); |
464 | } | 464 | } |
465 | 465 | ||
466 | 466 | ||
467 | void PPPData::setModemInitResp(const QString &n) { | 467 | void PPPData::setModemInitResp(const QString &n) { |
468 | writeConfig(MODEM_GRP, INITRESP_KEY, n); | 468 | writeConfig(modemGroup(), INITRESP_KEY, n); |
469 | } | 469 | } |
470 | 470 | ||
471 | 471 | ||
472 | int PPPData::modemPreInitDelay() { | 472 | int PPPData::modemPreInitDelay() { |
473 | return readNumConfig(MODEM_GRP, PREINITDELAY_KEY, 50); | 473 | return readNumConfig(modemGroup(), PREINITDELAY_KEY, 50); |
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
477 | void PPPData::setModemPreInitDelay(int n) { | 477 | void PPPData::setModemPreInitDelay(int n) { |
478 | writeConfig(MODEM_GRP, PREINITDELAY_KEY, n); | 478 | writeConfig(modemGroup(), PREINITDELAY_KEY, n); |
479 | } | 479 | } |
480 | 480 | ||
481 | 481 | ||
482 | int PPPData::modemInitDelay() { | 482 | int PPPData::modemInitDelay() { |
483 | return readNumConfig(MODEM_GRP, INITDELAY_KEY, 50); | 483 | return readNumConfig(modemGroup(), INITDELAY_KEY, 50); |
484 | } | 484 | } |
485 | 485 | ||
486 | 486 | ||
487 | void PPPData::setModemInitDelay(int n) { | 487 | void PPPData::setModemInitDelay(int n) { |
488 | writeConfig(MODEM_GRP, INITDELAY_KEY, n); | 488 | writeConfig(modemGroup(), INITDELAY_KEY, n); |
489 | } | 489 | } |
490 | 490 | ||
491 | QString PPPData::modemNoDialToneDetectionStr() { | 491 | QString PPPData::modemNoDialToneDetectionStr() { |
492 | return readConfig(MODEM_GRP, NODTDETECT_KEY, "ATX3"); | 492 | return readConfig(modemGroup(), NODTDETECT_KEY, "ATX3"); |
493 | } | 493 | } |
494 | 494 | ||
495 | void PPPData::setModemNoDialToneDetectionStr(const QString &n) { | 495 | void PPPData::setModemNoDialToneDetectionStr(const QString &n) { |
496 | writeConfig(MODEM_GRP, NODTDETECT_KEY, n); | 496 | writeConfig(modemGroup(), NODTDETECT_KEY, n); |
497 | } | 497 | } |
498 | 498 | ||
499 | const QString PPPData::modemDialStr() { | 499 | const QString PPPData::modemDialStr() { |
500 | return readConfig(MODEM_GRP, DIALSTR_KEY, "ATDT"); | 500 | return readConfig(modemGroup(), DIALSTR_KEY, "ATDT"); |
501 | } | 501 | } |
502 | 502 | ||
503 | 503 | ||
504 | void PPPData::setModemDialStr(const QString &n) { | 504 | void PPPData::setModemDialStr(const QString &n) { |
505 | writeConfig(MODEM_GRP, DIALSTR_KEY, n); | 505 | writeConfig(modemGroup(), DIALSTR_KEY, n); |
506 | } | 506 | } |
507 | 507 | ||
508 | 508 | ||
509 | const QString PPPData::modemConnectResp() { | 509 | const QString PPPData::modemConnectResp() { |
510 | return readConfig(MODEM_GRP, CONNECTRESP_KEY, "CONNECT"); | 510 | return readConfig(modemGroup(), CONNECTRESP_KEY, "CONNECT"); |
511 | } | 511 | } |
512 | 512 | ||
513 | 513 | ||
514 | void PPPData::setModemConnectResp(const QString &n) { | 514 | void PPPData::setModemConnectResp(const QString &n) { |
515 | writeConfig(MODEM_GRP, CONNECTRESP_KEY, n); | 515 | writeConfig(modemGroup(), CONNECTRESP_KEY, n); |
516 | } | 516 | } |
517 | 517 | ||
518 | 518 | ||
519 | const QString PPPData::modemBusyResp() { | 519 | const QString PPPData::modemBusyResp() { |
520 | return readConfig(MODEM_GRP, BUSYRESP_KEY, "BUSY"); | 520 | return readConfig(modemGroup(), BUSYRESP_KEY, "BUSY"); |
521 | } | 521 | } |
522 | 522 | ||
523 | 523 | ||
524 | void PPPData::setModemBusyResp(const QString &n) { | 524 | void PPPData::setModemBusyResp(const QString &n) { |
525 | writeConfig(MODEM_GRP, BUSYRESP_KEY, n); | 525 | writeConfig(modemGroup(), BUSYRESP_KEY, n); |
526 | } | 526 | } |
527 | 527 | ||
528 | 528 | ||
529 | const QString PPPData::modemNoCarrierResp() { | 529 | const QString PPPData::modemNoCarrierResp() { |
530 | return readConfig(MODEM_GRP, NOCARRIERRESP_KEY, "NO CARRIER"); | 530 | return readConfig(modemGroup(), NOCARRIERRESP_KEY, "NO CARRIER"); |
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | void PPPData::setModemNoCarrierResp(const QString &n) { | 534 | void PPPData::setModemNoCarrierResp(const QString &n) { |
535 | writeConfig(MODEM_GRP, NOCARRIERRESP_KEY, n); | 535 | writeConfig(modemGroup(), NOCARRIERRESP_KEY, n); |
536 | } | 536 | } |
537 | 537 | ||
538 | 538 | ||
539 | const QString PPPData::modemNoDialtoneResp() { | 539 | const QString PPPData::modemNoDialtoneResp() { |
540 | return readConfig(MODEM_GRP, NODIALTONERESP_KEY, "NO DIALTONE"); | 540 | return readConfig(modemGroup(), NODIALTONERESP_KEY, "NO DIALTONE"); |
541 | } | 541 | } |
542 | 542 | ||
543 | 543 | ||
544 | void PPPData::setModemNoDialtoneResp(const QString &n) { | 544 | void PPPData::setModemNoDialtoneResp(const QString &n) { |
545 | writeConfig(MODEM_GRP, NODIALTONERESP_KEY, n); | 545 | writeConfig(modemGroup(), NODIALTONERESP_KEY, n); |
546 | } | 546 | } |
547 | 547 | ||
548 | 548 | ||
549 | const QString PPPData::modemHangupStr() { | 549 | const QString PPPData::modemHangupStr() { |
550 | return readConfig(MODEM_GRP, HANGUPSTR_KEY, "+++ATH"); | 550 | return readConfig(modemGroup(), HANGUPSTR_KEY, "+++ATH"); |
551 | } | 551 | } |
552 | 552 | ||
553 | void PPPData::setModemHangupStr(const QString &n) { | 553 | void PPPData::setModemHangupStr(const QString &n) { |
554 | writeConfig(MODEM_GRP, HANGUPSTR_KEY, n); | 554 | writeConfig(modemGroup(), HANGUPSTR_KEY, n); |
555 | } | 555 | } |
556 | 556 | ||
557 | 557 | ||
558 | const QString PPPData::modemHangupResp() { | 558 | const QString PPPData::modemHangupResp() { |
559 | return readConfig(MODEM_GRP, HANGUPRESP_KEY, "OK"); | 559 | return readConfig(modemGroup(), HANGUPRESP_KEY, "OK"); |
560 | } | 560 | } |
561 | 561 | ||
562 | void PPPData::setModemHangupResp(const QString &n) { | 562 | void PPPData::setModemHangupResp(const QString &n) { |
563 | writeConfig(MODEM_GRP, HANGUPRESP_KEY, n); | 563 | writeConfig(modemGroup(), HANGUPRESP_KEY, n); |
564 | } | 564 | } |
565 | 565 | ||
566 | 566 | ||
567 | const QString PPPData::modemAnswerStr() { | 567 | const QString PPPData::modemAnswerStr() { |
568 | return readConfig(MODEM_GRP, ANSWERSTR_KEY, "ATA"); | 568 | return readConfig(modemGroup(), ANSWERSTR_KEY, "ATA"); |
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | QString PPPData::volumeOff() { | 572 | QString PPPData::volumeOff() { |
573 | return readConfig(MODEM_GRP, VOLUME_OFF, "M0L0"); | 573 | return readConfig(modemGroup(), VOLUME_OFF, "M0L0"); |
574 | } | 574 | } |
575 | 575 | ||
576 | 576 | ||
577 | void PPPData::setVolumeOff(const QString &s) { | 577 | void PPPData::setVolumeOff(const QString &s) { |
578 | writeConfig(MODEM_GRP, VOLUME_OFF, s); | 578 | writeConfig(modemGroup(), VOLUME_OFF, s); |
579 | } | 579 | } |
580 | 580 | ||
581 | 581 | ||
582 | QString PPPData::volumeMedium() { | 582 | QString PPPData::volumeMedium() { |
583 | return readConfig(MODEM_GRP, VOLUME_MEDIUM, "M1L1"); | 583 | return readConfig(modemGroup(), VOLUME_MEDIUM, "M1L1"); |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | void PPPData::setVolumeMedium(const QString &s) { | 587 | void PPPData::setVolumeMedium(const QString &s) { |
588 | writeConfig(MODEM_GRP, VOLUME_MEDIUM, s); | 588 | writeConfig(modemGroup(), VOLUME_MEDIUM, s); |
589 | } | 589 | } |
590 | 590 | ||
591 | 591 | ||
592 | QString PPPData::volumeHigh() { | 592 | QString PPPData::volumeHigh() { |
593 | QString tmp = readConfig(MODEM_GRP, VOLUME_HIGH, "M1L3"); | 593 | QString tmp = readConfig(modemGroup(), VOLUME_HIGH, "M1L3"); |
594 | if(tmp == "M1L4") | 594 | if(tmp == "M1L4") |
595 | tmp = "M1L3"; | 595 | tmp = "M1L3"; |
596 | return tmp; | 596 | return tmp; |
@@ -598,7 +598,7 @@ QString PPPData::volumeHigh() { | |||
598 | 598 | ||
599 | 599 | ||
600 | void PPPData::setVolumeHigh(const QString &s) { | 600 | void PPPData::setVolumeHigh(const QString &s) { |
601 | writeConfig(MODEM_GRP, VOLUME_HIGH, s); | 601 | writeConfig(modemGroup(), VOLUME_HIGH, s); |
602 | } | 602 | } |
603 | 603 | ||
604 | 604 | ||
@@ -624,54 +624,54 @@ QString PPPData::volumeInitString() { | |||
624 | 624 | ||
625 | 625 | ||
626 | int PPPData::volume() { | 626 | int PPPData::volume() { |
627 | return readNumConfig(MODEM_GRP, VOLUME_KEY, 1); | 627 | return readNumConfig(modemGroup(), VOLUME_KEY, 1); |
628 | } | 628 | } |
629 | 629 | ||
630 | 630 | ||
631 | void PPPData::setVolume(int i) { | 631 | void PPPData::setVolume(int i) { |
632 | writeConfig(MODEM_GRP, VOLUME_KEY, i); | 632 | writeConfig(modemGroup(), VOLUME_KEY, i); |
633 | } | 633 | } |
634 | 634 | ||
635 | int PPPData::waitForDialTone() { | 635 | int PPPData::waitForDialTone() { |
636 | return readNumConfig(MODEM_GRP, DIALTONEWAIT_KEY, 1); | 636 | return readNumConfig(modemGroup(), DIALTONEWAIT_KEY, 1); |
637 | } | 637 | } |
638 | 638 | ||
639 | void PPPData::setWaitForDialTone(int i) { | 639 | void PPPData::setWaitForDialTone(int i) { |
640 | writeConfig(MODEM_GRP, DIALTONEWAIT_KEY, i); | 640 | writeConfig(modemGroup(), DIALTONEWAIT_KEY, i); |
641 | } | 641 | } |
642 | 642 | ||
643 | void PPPData::setModemAnswerStr(const QString &n) { | 643 | void PPPData::setModemAnswerStr(const QString &n) { |
644 | writeConfig(MODEM_GRP, ANSWERSTR_KEY, n); | 644 | writeConfig(modemGroup(), ANSWERSTR_KEY, n); |
645 | } | 645 | } |
646 | 646 | ||
647 | 647 | ||
648 | const QString PPPData::modemRingResp() { | 648 | const QString PPPData::modemRingResp() { |
649 | return readConfig(MODEM_GRP, RINGRESP_KEY, "RING"); | 649 | return readConfig(modemGroup(), RINGRESP_KEY, "RING"); |
650 | } | 650 | } |
651 | 651 | ||
652 | 652 | ||
653 | void PPPData::setModemRingResp(const QString &n) { | 653 | void PPPData::setModemRingResp(const QString &n) { |
654 | writeConfig(MODEM_GRP, RINGRESP_KEY, n); | 654 | writeConfig(modemGroup(), RINGRESP_KEY, n); |
655 | } | 655 | } |
656 | 656 | ||
657 | 657 | ||
658 | const QString PPPData::modemAnswerResp() { | 658 | const QString PPPData::modemAnswerResp() { |
659 | return readConfig(MODEM_GRP, ANSWERRESP_KEY, "CONNECT"); | 659 | return readConfig(modemGroup(), ANSWERRESP_KEY, "CONNECT"); |
660 | } | 660 | } |
661 | 661 | ||
662 | 662 | ||
663 | void PPPData::setModemAnswerResp(const QString &n) { | 663 | void PPPData::setModemAnswerResp(const QString &n) { |
664 | writeConfig(MODEM_GRP, ANSWERRESP_KEY, n); | 664 | writeConfig(modemGroup(), ANSWERRESP_KEY, n); |
665 | } | 665 | } |
666 | 666 | ||
667 | 667 | ||
668 | const QString PPPData::enter() { | 668 | const QString PPPData::enter() { |
669 | return readConfig(MODEM_GRP, ENTER_KEY, "CR"); | 669 | return readConfig(modemGroup(), ENTER_KEY, "CR"); |
670 | } | 670 | } |
671 | 671 | ||
672 | 672 | ||
673 | void PPPData::setEnter(const QString &n) { | 673 | void PPPData::setEnter(const QString &n) { |
674 | writeConfig(MODEM_GRP, ENTER_KEY, n); | 674 | writeConfig(modemGroup(), ENTER_KEY, n); |
675 | } | 675 | } |
676 | 676 | ||
677 | 677 | ||
@@ -1209,6 +1209,10 @@ void PPPData::setpppdError(int err) { | |||
1209 | pppderror = err; | 1209 | pppderror = err; |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | QString PPPData::modemGroup() | ||
1213 | { | ||
1214 | return MODEM_GRP; | ||
1215 | } | ||
1212 | 1216 | ||
1213 | // // | 1217 | // // |
1214 | // // window position | 1218 | // // window position |
diff --git a/noncore/settings/networksettings/ppp/pppdata.h b/noncore/settings/networksettings/ppp/pppdata.h index 57ce2fd..c4d7bc3 100644 --- a/noncore/settings/networksettings/ppp/pppdata.h +++ b/noncore/settings/networksettings/ppp/pppdata.h | |||
@@ -159,30 +159,31 @@ class Config; | |||
159 | 159 | ||
160 | class PPPData { | 160 | class PPPData { |
161 | public: | 161 | public: |
162 | PPPData(); | 162 | PPPData(); |
163 | ~PPPData() {}; | 163 | ~PPPData() {}; |
164 | static PPPData* data(); | 164 | static PPPData* data(); |
165 | 165 | ||
166 | enum { NumInitStrings = 2 }; | 166 | enum { NumInitStrings = 2 }; |
167 | 167 | ||
168 | // general functions | 168 | // general functions |
169 | bool open(); | 169 | bool open(); |
170 | void save(); | 170 | void save(); |
171 | void cancel(); | 171 | void cancel(); |
172 | // int access() const; // read/write access | ||
173 | 172 | ||
174 | // function to read/write date to configuration file | 173 | |
175 | QString readConfig(const QString &, const QString &, const QString &); | 174 | // function to read/write date to configuration file |
176 | int readNumConfig(const QString &, const QString &, int); | 175 | QString readConfig(const QString &, const QString &, const QString &); |
177 | bool readListConfig(const QString &, const QString &, | 176 | int readNumConfig(const QString &, const QString &, int); |
177 | bool readListConfig(const QString &, const QString &, | ||
178 | QStringList &, char sep = ','); | 178 | QStringList &, char sep = ','); |
179 | void writeConfig(const QString &, const QString &, const QString &); | 179 | void writeConfig(const QString &, const QString &, const QString &); |
180 | void writeConfig(const QString &, const QString &, int); | 180 | void writeConfig(const QString &, const QString &, int); |
181 | void writeListConfig(const QString &, const QString &, | 181 | void writeListConfig(const QString &, const QString &, |
182 | QStringList &, char sep = ','); | 182 | QStringList &, char sep = ','); |
183 | 183 | ||
184 | // return the current account group | 184 | // return the current account group |
185 | QString currentGroup() { return cgroup; } | 185 | QString currentGroup() { return cgroup; } |
186 | QString modemGroup(); | ||
186 | 187 | ||
187 | // functions to set/get general kppp info | 188 | // functions to set/get general kppp info |
188 | QString password() const; | 189 | QString password() const; |
diff --git a/noncore/settings/networksettings/ppp/pppmodule.cpp b/noncore/settings/networksettings/ppp/pppmodule.cpp index da17e26..e13f8c8 100644 --- a/noncore/settings/networksettings/ppp/pppmodule.cpp +++ b/noncore/settings/networksettings/ppp/pppmodule.cpp | |||
@@ -8,7 +8,12 @@ | |||
8 | /** | 8 | /** |
9 | * Constructor, find all of the possible interfaces | 9 | * Constructor, find all of the possible interfaces |
10 | */ | 10 | */ |
11 | PPPModule::PPPModule() : Module() { | 11 | PPPModule::PPPModule() : Module() |
12 | { | ||
13 | Interface *iface; | ||
14 | iface = new Interface( 0, "device" ); | ||
15 | iface->setHardwareName( "account" ); | ||
16 | list.append( iface ); | ||
12 | } | 17 | } |
13 | 18 | ||
14 | /** | 19 | /** |
@@ -42,12 +47,7 @@ QString PPPModule::getPixmapName(Interface* ){ | |||
42 | * @return bool true if i is owned by this module, false otherwise. | 47 | * @return bool true if i is owned by this module, false otherwise. |
43 | */ | 48 | */ |
44 | bool PPPModule::isOwner(Interface *i){ | 49 | bool PPPModule::isOwner(Interface *i){ |
45 | if(!i->getInterfaceName().upper().contains("PPP")) | 50 | return list.find( i ) != -1; |
46 | return false; | ||
47 | |||
48 | i->setHardwareName("PPP"); | ||
49 | list.append(i); | ||
50 | return true; | ||
51 | } | 51 | } |
52 | 52 | ||
53 | /** | 53 | /** |
@@ -56,8 +56,8 @@ bool PPPModule::isOwner(Interface *i){ | |||
56 | */ | 56 | */ |
57 | QWidget *PPPModule::configure(Interface *i){ | 57 | QWidget *PPPModule::configure(Interface *i){ |
58 | qDebug("return ModemWidget"); | 58 | qDebug("return ModemWidget"); |
59 | PPPConfigWidget *pppconfig = new PPPConfigWidget( 0, "PPPConfig", false, Qt::WDestructiveClose ); | 59 | PPPConfigWidget *pppconfig = new PPPConfigWidget( 0, "PPPConfig", false, |
60 | // pppconfig->setProfile(profile); | 60 | Qt::WDestructiveClose ); |
61 | return pppconfig; | 61 | return pppconfig; |
62 | } | 62 | } |
63 | 63 | ||
@@ -97,8 +97,12 @@ Interface *PPPModule::addNewInterface(const QString &newInterface){ | |||
97 | imp.showMaximized(); | 97 | imp.showMaximized(); |
98 | if(imp.exec() == QDialog::Accepted ){ | 98 | if(imp.exec() == QDialog::Accepted ){ |
99 | qDebug("ACCEPTED"); | 99 | qDebug("ACCEPTED"); |
100 | return new Interface( 0, newInterface ); | ||
101 | PPPData::data()->save(); | 100 | PPPData::data()->save(); |
101 | Interface *iface; | ||
102 | iface = new Interface( 0, PPPData::data()->modemDevice() ); | ||
103 | iface->setHardwareName( PPPData::data()->accname() ); | ||
104 | list.append( iface ); | ||
105 | return iface; | ||
102 | } | 106 | } |
103 | return NULL; | 107 | return NULL; |
104 | } | 108 | } |
@@ -114,8 +118,8 @@ bool PPPModule::remove(Interface*){ | |||
114 | 118 | ||
115 | void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces) | 119 | void PPPModule::possibleNewInterfaces(QMap<QString, QString> &newIfaces) |
116 | { | 120 | { |
117 | qDebug("here"); | 121 | newIfaces.insert(QObject::tr("PPP") , |
118 | newIfaces.insert(QObject::tr("PPP") ,QObject::tr("generic ppp device")); | 122 | QObject::tr("generic ppp device")); |
119 | } | 123 | } |
120 | 124 | ||
121 | 125 | ||