Changeset 7220366a in rtems
- Timestamp:
- Apr 3, 2004, 4:40:09 PM (17 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- 10ae124c
- Parents:
- 0c9eaef
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/ChangeLog
r0c9eaef r7220366a 1 2004-04-03 Wilfried Busalski <w.busalski@lancier-monitoring.de> 2 3 PR 599/pppd 4 * libnetworking/pppd/chat.c: Fre memory that is allocated to fix leak. 5 1 6 2004-04-02 Ralf Corsepius <ralf_corsepius@rtems.org> 2 7 -
c/src/libnetworking/pppd/chat.c
r0c9eaef r7220366a 82 82 * 83 83 */ 84 85 /* $Id$ */ 86 87 /* 88 Fixes and some Changes by Wilfried Busalski Lancier-Monitoring GmbH Germany 89 wilfried.busalski@muenster.de 90 91 Fixes: put_string() Free memory allocated by clean() 92 get_string() Free memory allocated by clean() 93 chat_main() Will Distroy's no more the chat-script 94 getnextcommand() sepatator changed to '@' 95 */ 84 96 85 97 #include <stdio.h> … … 210 222 } 211 223 212 char *getnextcommand(char **string) 213 { 214 char *buf=*string,*res; 215 res=strchr(buf,'|'); 216 if (res==NULL) 224 char *getnextcommand(char *string,char *buff) 225 { 226 char *token; 227 int len; 228 229 token=strchr(string,'@'); 230 if (token==NULL){ 217 231 return NULL; 218 *res='\0'; 219 *string=res+1; 220 return buf; 232 } 233 len=token-string; 234 if(len > 78 ){ 235 len=78; 236 } 237 memcpy(buff,string,len); 238 buff[len]=0; 239 return(token+1); 221 240 } 222 241 223 242 int chatmain(int fd, int mode, char *pScript) 224 243 { 225 char *arg; 244 char arg[80]; 245 char *script; 226 246 227 247 /* initialize exit code */ … … 229 249 ttyfd = fd; 230 250 251 script=pScript; 252 231 253 if ( debug ) { 232 dbglog("chat_main: %s\n", pScript);254 dbglog("chat_main: %s\n", script); 233 255 } 234 256 235 257 /* get first expect string */ 236 arg = getnextcommand(&pScript);237 while (( arg!= NULL ) && ( exit_code == 0 )) {258 script = getnextcommand(script,arg); 259 while (( script != NULL ) && ( exit_code == 0 )) { 238 260 /* process the expect string */ 239 261 chat_expect(arg); 240 262 if ( exit_code == 0 ) { 241 263 /* get the next send string */ 242 arg = getnextcommand(&pScript);243 if ( arg!= NULL ) {264 script = getnextcommand(script,arg); 265 if ( script != NULL ) { 244 266 /* process the send string */ 245 267 chat_send(arg); 246 268 247 269 /* get the next expect string */ 248 arg = getnextcommand(&pScript);270 script = getnextcommand(script,arg); 249 271 } 250 272 } … … 496 518 497 519 if (strcmp(s, "HANGUP") == 0) { 498 ++hup_next;520 ++hup_next; 499 521 return; 500 522 } 501 523 502 524 if (strcmp(s, "ABORT") == 0) { 503 ++abort_next;504 return;525 ++abort_next; 526 return; 505 527 } 506 528 507 529 if (strcmp(s, "CLR_ABORT") == 0) { 508 ++clear_abort_next;509 return;530 ++clear_abort_next; 531 return; 510 532 } 511 533 512 534 if (strcmp(s, "REPORT") == 0) { 513 ++report_next;514 return;535 ++report_next; 536 return; 515 537 } 516 538 517 539 if (strcmp(s, "CLR_REPORT") == 0) { 518 ++clear_report_next;519 return;540 ++clear_report_next; 541 return; 520 542 } 521 543 522 544 if (strcmp(s, "TIMEOUT") == 0) { 523 ++timeout_next;524 return;545 ++timeout_next; 546 return; 525 547 } 526 548 527 549 if (strcmp(s, "ECHO") == 0) { 528 ++echo_next;529 return;550 ++echo_next; 551 return; 530 552 } 531 553 532 554 if (strcmp(s, "SAY") == 0) { 533 ++say_next;534 return;555 ++say_next; 556 return; 535 557 } 536 558 … … 599 621 600 622 if (say_next) { 601 say_next = 0;602 s = clean(s, 1);603 write(2, s, strlen(s));623 say_next = 0; 624 s = clean(s, 1); 625 write(2, s, strlen(s)); 604 626 free(s); 605 return;627 return; 606 628 } 607 629 … … 618 640 619 641 if (abort_next) { 620 char *s1;642 char *s1; 621 643 622 abort_next = 0; 623 if ( n_aborts < MAX_ABORTS ) { 624 s1 = clean(s, 0); 625 if (( strlen(s1) <= strlen(s) ) && 626 ( strlen(s1) < sizeof(fail_buffer))) { 627 628 abort_string[n_aborts++] = s1; 629 } 630 } 631 return; 644 abort_next = 0; 645 if ( n_aborts < MAX_ABORTS ) { 646 s1 = clean(s, 0); 647 if (( strlen(s1) <= strlen(s) ) && ( strlen(s1) < sizeof(fail_buffer))) { 648 abort_string[n_aborts++] = s1; 649 } 650 free(s1); 651 } 652 return; 632 653 } 633 654 634 655 if (clear_abort_next) { 635 clear_abort_next = 0;636 return;656 clear_abort_next = 0; 657 return; 637 658 } 638 659 639 660 if (report_next) { 640 report_next = 0;641 return;661 report_next = 0; 662 return; 642 663 } 643 664 644 665 if (clear_report_next) { 645 clear_report_next = 0;646 return;666 clear_report_next = 0; 667 return; 647 668 } 648 669 649 670 if (timeout_next) { 650 timeout_next = 0;651 timeout = atoi(s);671 timeout_next = 0; 672 timeout = atoi(s); 652 673 653 if (timeout <= 0) 654 timeout = DEFAULT_CHAT_TIMEOUT; 655 656 return; 657 } 658 659 if (strcmp(s, "EOT") == 0) 660 s = "^D\\c"; 661 else if (strcmp(s, "BREAK") == 0) 662 s = "\\K\\c"; 663 664 if (!put_string(s)) { 665 exit_code = 2; 666 } 674 if (timeout <= 0){ 675 timeout = DEFAULT_CHAT_TIMEOUT; 676 } 677 return; 678 } 679 680 if (strcmp(s, "EOT") == 0){ 681 s = "^D\\c"; 682 } 683 else{ 684 if (strcmp(s, "BREAK") == 0){ 685 s = "\\K\\c"; 686 } 687 688 if (!put_string(s)) { 689 exit_code = 2; 690 } 691 } 667 692 } 668 693 … … 691 716 char ch = c; 692 717 693 write(ttyfd, &ch, 1); 694 695 return 0; 718 return(write(ttyfd, &ch, 1)); 696 719 } 697 720 … … 699 722 int c; 700 723 { 701 if (put_char(c) < 0) {702 return (0);724 if (put_char(c) < 1) { 725 return (0); 703 726 } 704 727 return (1); … … 708 731 register char *s; 709 732 { 733 char *out,*free_ptr=0; 734 710 735 quiet = 0; 711 s = clean(s, 1); 712 while (*s) { 713 register char c = *s++; 714 715 if (c != '\\') { 716 if (!write_char (c)) 717 return 0; 718 continue; 719 } 720 721 c = *s++; 722 switch (c) { 723 case 'd': 724 sleep(1); 725 break; 726 727 case 'K': 728 break_sequence(); 729 break; 730 731 case 'p': 736 out = free_ptr = clean(s, 1); 737 while (*out) { 738 register char c = *out++; 739 740 if (c != '\\') { 741 if (!write_char (c)){ 742 free(free_ptr); 743 return 0; 744 } 745 continue; 746 } 747 748 c = *out++; 749 750 switch (c) { 751 case 'd': 752 sleep(1); 753 break; 754 755 case 'K': 756 break_sequence(); 757 break; 758 759 case 'p': 732 760 #if 0 /* FIXME!!! */ 733 usleep(10000); /* 1/100th of a second (arg is microseconds) */761 usleep(10000); /* 1/100th of a second (arg is microseconds) */ 734 762 #else 735 sleep(1);763 sleep(1); 736 764 #endif 737 break; 738 739 default: 740 if (!write_char (c)) 741 return 0; 742 break; 743 } 744 } 765 break; 766 767 default: 768 if (!write_char (c)){ 769 free(free_ptr); 770 return 0; 771 } 772 break; 773 } 774 } 775 free(free_ptr); 745 776 746 777 return (1); … … 750 781 * 'Wait for' this string to appear on this file descriptor. 751 782 */ 752 static int get_string( string)753 register char * string;783 static int get_string(in_string) 784 register char *in_string; 754 785 { 755 786 int c, len, minlen; 756 787 register char *s = temp2, *end = s + STR_LEN; 757 788 char *logged = temp2; 789 char *string=0; 758 790 struct termios tios; 759 791 … … 765 797 tcsetattr(ttyfd, TCSANOW, &tios); 766 798 767 string = clean( string, 0);799 string = clean(in_string, 0); 768 800 len = strlen(string); 769 801 minlen = (len > sizeof(fail_buffer)? len: sizeof(fail_buffer)) - 1; 770 802 771 803 if (len > STR_LEN) { 772 exit_code = 1; 773 return 0; 804 exit_code = 1; 805 free(string); 806 return 0; 774 807 } 775 808 … … 781 814 int n, abort_len; 782 815 783 *s++ = c; 784 *s=0; 816 if(c == '\n' || c == '\r'){ 817 s = temp2; 818 *s=0; 819 } 820 else{ 821 *s++ = c; 822 *s=0; 823 } 785 824 786 825 if (s - temp2 >= len && 787 826 c == string[len - 1] && 788 827 strncmp(s - len, string, len) == 0) { 828 free(string); 789 829 return (1); 790 830 } … … 796 836 exit_code = n + 4; 797 837 strcpy(fail_reason = fail_buffer, abort_string[n]); 838 free(string); 798 839 return (0); 799 840 } … … 812 853 813 854 exit_code = 3; 855 free(string); 814 856 return (0); 815 857 } 858 -
cpukit/pppd/chat.c
r0c9eaef r7220366a 82 82 * 83 83 */ 84 85 /* $Id$ */ 86 87 /* 88 Fixes and some Changes by Wilfried Busalski Lancier-Monitoring GmbH Germany 89 wilfried.busalski@muenster.de 90 91 Fixes: put_string() Free memory allocated by clean() 92 get_string() Free memory allocated by clean() 93 chat_main() Will Distroy's no more the chat-script 94 getnextcommand() sepatator changed to '@' 95 */ 84 96 85 97 #include <stdio.h> … … 210 222 } 211 223 212 char *getnextcommand(char **string) 213 { 214 char *buf=*string,*res; 215 res=strchr(buf,'|'); 216 if (res==NULL) 224 char *getnextcommand(char *string,char *buff) 225 { 226 char *token; 227 int len; 228 229 token=strchr(string,'@'); 230 if (token==NULL){ 217 231 return NULL; 218 *res='\0'; 219 *string=res+1; 220 return buf; 232 } 233 len=token-string; 234 if(len > 78 ){ 235 len=78; 236 } 237 memcpy(buff,string,len); 238 buff[len]=0; 239 return(token+1); 221 240 } 222 241 223 242 int chatmain(int fd, int mode, char *pScript) 224 243 { 225 char *arg; 244 char arg[80]; 245 char *script; 226 246 227 247 /* initialize exit code */ … … 229 249 ttyfd = fd; 230 250 251 script=pScript; 252 231 253 if ( debug ) { 232 dbglog("chat_main: %s\n", pScript);254 dbglog("chat_main: %s\n", script); 233 255 } 234 256 235 257 /* get first expect string */ 236 arg = getnextcommand(&pScript);237 while (( arg!= NULL ) && ( exit_code == 0 )) {258 script = getnextcommand(script,arg); 259 while (( script != NULL ) && ( exit_code == 0 )) { 238 260 /* process the expect string */ 239 261 chat_expect(arg); 240 262 if ( exit_code == 0 ) { 241 263 /* get the next send string */ 242 arg = getnextcommand(&pScript);243 if ( arg!= NULL ) {264 script = getnextcommand(script,arg); 265 if ( script != NULL ) { 244 266 /* process the send string */ 245 267 chat_send(arg); 246 268 247 269 /* get the next expect string */ 248 arg = getnextcommand(&pScript);270 script = getnextcommand(script,arg); 249 271 } 250 272 } … … 496 518 497 519 if (strcmp(s, "HANGUP") == 0) { 498 ++hup_next;520 ++hup_next; 499 521 return; 500 522 } 501 523 502 524 if (strcmp(s, "ABORT") == 0) { 503 ++abort_next;504 return;525 ++abort_next; 526 return; 505 527 } 506 528 507 529 if (strcmp(s, "CLR_ABORT") == 0) { 508 ++clear_abort_next;509 return;530 ++clear_abort_next; 531 return; 510 532 } 511 533 512 534 if (strcmp(s, "REPORT") == 0) { 513 ++report_next;514 return;535 ++report_next; 536 return; 515 537 } 516 538 517 539 if (strcmp(s, "CLR_REPORT") == 0) { 518 ++clear_report_next;519 return;540 ++clear_report_next; 541 return; 520 542 } 521 543 522 544 if (strcmp(s, "TIMEOUT") == 0) { 523 ++timeout_next;524 return;545 ++timeout_next; 546 return; 525 547 } 526 548 527 549 if (strcmp(s, "ECHO") == 0) { 528 ++echo_next;529 return;550 ++echo_next; 551 return; 530 552 } 531 553 532 554 if (strcmp(s, "SAY") == 0) { 533 ++say_next;534 return;555 ++say_next; 556 return; 535 557 } 536 558 … … 599 621 600 622 if (say_next) { 601 say_next = 0;602 s = clean(s, 1);603 write(2, s, strlen(s));623 say_next = 0; 624 s = clean(s, 1); 625 write(2, s, strlen(s)); 604 626 free(s); 605 return;627 return; 606 628 } 607 629 … … 618 640 619 641 if (abort_next) { 620 char *s1;642 char *s1; 621 643 622 abort_next = 0; 623 if ( n_aborts < MAX_ABORTS ) { 624 s1 = clean(s, 0); 625 if (( strlen(s1) <= strlen(s) ) && 626 ( strlen(s1) < sizeof(fail_buffer))) { 627 628 abort_string[n_aborts++] = s1; 629 } 630 } 631 return; 644 abort_next = 0; 645 if ( n_aborts < MAX_ABORTS ) { 646 s1 = clean(s, 0); 647 if (( strlen(s1) <= strlen(s) ) && ( strlen(s1) < sizeof(fail_buffer))) { 648 abort_string[n_aborts++] = s1; 649 } 650 free(s1); 651 } 652 return; 632 653 } 633 654 634 655 if (clear_abort_next) { 635 clear_abort_next = 0;636 return;656 clear_abort_next = 0; 657 return; 637 658 } 638 659 639 660 if (report_next) { 640 report_next = 0;641 return;661 report_next = 0; 662 return; 642 663 } 643 664 644 665 if (clear_report_next) { 645 clear_report_next = 0;646 return;666 clear_report_next = 0; 667 return; 647 668 } 648 669 649 670 if (timeout_next) { 650 timeout_next = 0;651 timeout = atoi(s);671 timeout_next = 0; 672 timeout = atoi(s); 652 673 653 if (timeout <= 0) 654 timeout = DEFAULT_CHAT_TIMEOUT; 655 656 return; 657 } 658 659 if (strcmp(s, "EOT") == 0) 660 s = "^D\\c"; 661 else if (strcmp(s, "BREAK") == 0) 662 s = "\\K\\c"; 663 664 if (!put_string(s)) { 665 exit_code = 2; 666 } 674 if (timeout <= 0){ 675 timeout = DEFAULT_CHAT_TIMEOUT; 676 } 677 return; 678 } 679 680 if (strcmp(s, "EOT") == 0){ 681 s = "^D\\c"; 682 } 683 else{ 684 if (strcmp(s, "BREAK") == 0){ 685 s = "\\K\\c"; 686 } 687 688 if (!put_string(s)) { 689 exit_code = 2; 690 } 691 } 667 692 } 668 693 … … 691 716 char ch = c; 692 717 693 write(ttyfd, &ch, 1); 694 695 return 0; 718 return(write(ttyfd, &ch, 1)); 696 719 } 697 720 … … 699 722 int c; 700 723 { 701 if (put_char(c) < 0) {702 return (0);724 if (put_char(c) < 1) { 725 return (0); 703 726 } 704 727 return (1); … … 708 731 register char *s; 709 732 { 733 char *out,*free_ptr=0; 734 710 735 quiet = 0; 711 s = clean(s, 1); 712 while (*s) { 713 register char c = *s++; 714 715 if (c != '\\') { 716 if (!write_char (c)) 717 return 0; 718 continue; 719 } 720 721 c = *s++; 722 switch (c) { 723 case 'd': 724 sleep(1); 725 break; 726 727 case 'K': 728 break_sequence(); 729 break; 730 731 case 'p': 736 out = free_ptr = clean(s, 1); 737 while (*out) { 738 register char c = *out++; 739 740 if (c != '\\') { 741 if (!write_char (c)){ 742 free(free_ptr); 743 return 0; 744 } 745 continue; 746 } 747 748 c = *out++; 749 750 switch (c) { 751 case 'd': 752 sleep(1); 753 break; 754 755 case 'K': 756 break_sequence(); 757 break; 758 759 case 'p': 732 760 #if 0 /* FIXME!!! */ 733 usleep(10000); /* 1/100th of a second (arg is microseconds) */761 usleep(10000); /* 1/100th of a second (arg is microseconds) */ 734 762 #else 735 sleep(1);763 sleep(1); 736 764 #endif 737 break; 738 739 default: 740 if (!write_char (c)) 741 return 0; 742 break; 743 } 744 } 765 break; 766 767 default: 768 if (!write_char (c)){ 769 free(free_ptr); 770 return 0; 771 } 772 break; 773 } 774 } 775 free(free_ptr); 745 776 746 777 return (1); … … 750 781 * 'Wait for' this string to appear on this file descriptor. 751 782 */ 752 static int get_string( string)753 register char * string;783 static int get_string(in_string) 784 register char *in_string; 754 785 { 755 786 int c, len, minlen; 756 787 register char *s = temp2, *end = s + STR_LEN; 757 788 char *logged = temp2; 789 char *string=0; 758 790 struct termios tios; 759 791 … … 765 797 tcsetattr(ttyfd, TCSANOW, &tios); 766 798 767 string = clean( string, 0);799 string = clean(in_string, 0); 768 800 len = strlen(string); 769 801 minlen = (len > sizeof(fail_buffer)? len: sizeof(fail_buffer)) - 1; 770 802 771 803 if (len > STR_LEN) { 772 exit_code = 1; 773 return 0; 804 exit_code = 1; 805 free(string); 806 return 0; 774 807 } 775 808 … … 781 814 int n, abort_len; 782 815 783 *s++ = c; 784 *s=0; 816 if(c == '\n' || c == '\r'){ 817 s = temp2; 818 *s=0; 819 } 820 else{ 821 *s++ = c; 822 *s=0; 823 } 785 824 786 825 if (s - temp2 >= len && 787 826 c == string[len - 1] && 788 827 strncmp(s - len, string, len) == 0) { 828 free(string); 789 829 return (1); 790 830 } … … 796 836 exit_code = n + 4; 797 837 strcpy(fail_reason = fail_buffer, abort_string[n]); 838 free(string); 798 839 return (0); 799 840 } … … 812 853 813 854 exit_code = 3; 855 free(string); 814 856 return (0); 815 857 } 858
Note: See TracChangeset
for help on using the changeset viewer.