diff options
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/wps_parser.c | 79 |
1 files changed, 52 insertions, 27 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index fd4db2e9de..54f9f588bf 100644 --- a/apps/gui/wps_parser.c +++ b/apps/gui/wps_parser.c | |||
@@ -489,7 +489,7 @@ static int parse_image_load(const char *wps_bufptr, | |||
489 | 489 | ||
490 | ptr++; | 490 | ptr++; |
491 | 491 | ||
492 | if (!(ptr = parse_list("ssdd", '|', ptr, &id, &filename, &x, &y))) | 492 | if (!(ptr = parse_list("ssdd", NULL, '|', ptr, &id, &filename, &x, &y))) |
493 | return WPS_ERROR_INVALID_PARAM; | 493 | return WPS_ERROR_INVALID_PARAM; |
494 | 494 | ||
495 | /* Check there is a terminating | */ | 495 | /* Check there is a terminating | */ |
@@ -540,17 +540,34 @@ static int parse_viewport(const char *wps_bufptr, | |||
540 | struct wps_token *token, | 540 | struct wps_token *token, |
541 | struct wps_data *wps_data) | 541 | struct wps_data *wps_data) |
542 | { | 542 | { |
543 | (void)token; /* Kill warnings */ | ||
543 | const char *ptr = wps_bufptr; | 544 | const char *ptr = wps_bufptr; |
544 | struct viewport* vp; | 545 | struct viewport* vp; |
545 | int depth; | 546 | int depth; |
546 | 547 | int valid = 0; | |
547 | (void)token; /* Kill warnings */ | 548 | enum { |
549 | PL_X = 0, | ||
550 | PL_Y, | ||
551 | PL_WIDTH, | ||
552 | PL_HEIGHT, | ||
553 | PL_FONT, | ||
554 | PL_FG, | ||
555 | PL_BG, | ||
556 | }; | ||
557 | int lcd_width = LCD_WIDTH, lcd_height = LCD_HEIGHT; | ||
558 | #ifdef HAVE_REMOTE_LCD | ||
559 | if (wps_data->remote_wps) | ||
560 | { | ||
561 | lcd_width = LCD_REMOTE_WIDTH; | ||
562 | lcd_height = LCD_REMOTE_HEIGHT; | ||
563 | } | ||
564 | #endif | ||
548 | 565 | ||
549 | if (*wps_bufptr != '|') | 566 | if (*wps_bufptr != '|') |
550 | return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl7 */ | 567 | return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl7 */ |
551 | 568 | ||
552 | ptr = wps_bufptr + 1; | 569 | ptr = wps_bufptr + 1; |
553 | /* format: %V|x|y|width|height|fg_pattern|bg_pattern| */ | 570 | /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */ |
554 | 571 | ||
555 | if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS) | 572 | if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS) |
556 | return WPS_ERROR_INVALID_PARAM; | 573 | return WPS_ERROR_INVALID_PARAM; |
@@ -573,7 +590,7 @@ static int parse_viewport(const char *wps_bufptr, | |||
573 | #ifdef HAVE_LCD_COLOR | 590 | #ifdef HAVE_LCD_COLOR |
574 | if (depth == 16) | 591 | if (depth == 16) |
575 | { | 592 | { |
576 | if (!(ptr = parse_list("dddddcc", '|', ptr, &vp->x, &vp->y, &vp->width, | 593 | if (!(ptr = parse_list("dddddcc", &valid, '|', ptr, &vp->x, &vp->y, &vp->width, |
577 | &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern))) | 594 | &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern))) |
578 | return WPS_ERROR_INVALID_PARAM; | 595 | return WPS_ERROR_INVALID_PARAM; |
579 | } | 596 | } |
@@ -581,7 +598,10 @@ static int parse_viewport(const char *wps_bufptr, | |||
581 | #endif | 598 | #endif |
582 | #if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) | 599 | #if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) |
583 | if (depth == 2) { | 600 | if (depth == 2) { |
584 | if (!(ptr = parse_list("dddddgg", '|', ptr, &vp->x, &vp->y, &vp->width, | 601 | /* Default to black on white */ |
602 | vp->fg_pattern = 0; | ||
603 | vp->bg_pattern = 3; | ||
604 | if (!(ptr = parse_list("dddddgg", &valid, '|', ptr, &vp->x, &vp->y, &vp->width, | ||
585 | &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern))) | 605 | &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern))) |
586 | return WPS_ERROR_INVALID_PARAM; | 606 | return WPS_ERROR_INVALID_PARAM; |
587 | } | 607 | } |
@@ -590,8 +610,8 @@ static int parse_viewport(const char *wps_bufptr, | |||
590 | #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) | 610 | #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) |
591 | if (depth == 1) | 611 | if (depth == 1) |
592 | { | 612 | { |
593 | if (!(ptr = parse_list("ddddd", '|', ptr, &vp->x, &vp->y, &vp->width, | 613 | if (!(ptr = parse_list("ddddd", &valid, '|', ptr, &vp->x, &vp->y, |
594 | &vp->height, &vp->font))) | 614 | &vp->width, &vp->height, &vp->font))) |
595 | return WPS_ERROR_INVALID_PARAM; | 615 | return WPS_ERROR_INVALID_PARAM; |
596 | } | 616 | } |
597 | else | 617 | else |
@@ -602,34 +622,39 @@ static int parse_viewport(const char *wps_bufptr, | |||
602 | if (*ptr != '|') | 622 | if (*ptr != '|') |
603 | return WPS_ERROR_INVALID_PARAM; | 623 | return WPS_ERROR_INVALID_PARAM; |
604 | 624 | ||
625 | if ((valid&(1<<PL_X)) == 0 || (valid&(1<<PL_Y)) == 0) | ||
626 | return WPS_ERROR_INVALID_PARAM; | ||
627 | |||
628 | /* fix defaults */ | ||
629 | if ((valid&(1<<PL_WIDTH)) == 0) | ||
630 | vp->width = lcd_width - vp->x; | ||
631 | if ((valid&(1<<PL_HEIGHT)) == 0) | ||
632 | vp->height = lcd_height - vp->y; | ||
633 | |||
605 | /* Default to using the user font if the font was an invalid number */ | 634 | /* Default to using the user font if the font was an invalid number */ |
606 | if ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)) | 635 | if (((valid&(1<<PL_FONT)) == 0) || |
636 | ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))) | ||
607 | vp->font = FONT_UI; | 637 | vp->font = FONT_UI; |
608 | 638 | ||
609 | /* Validate the viewport dimensions - we know that the numbers are | 639 | /* Validate the viewport dimensions - we know that the numbers are |
610 | non-negative integers */ | 640 | non-negative integers */ |
611 | #ifdef HAVE_REMOTE_LCD | 641 | if ((vp->x >= lcd_width) || |
612 | if (wps_data->remote_wps) | 642 | ((vp->x + vp->width) > lcd_width) || |
643 | (vp->y >= lcd_height) || | ||
644 | ((vp->y + vp->height) > lcd_height)) | ||
613 | { | 645 | { |
614 | if ((vp->x >= LCD_REMOTE_WIDTH) || | 646 | return WPS_ERROR_INVALID_PARAM; |
615 | ((vp->x + vp->width) > LCD_REMOTE_WIDTH) || | ||
616 | (vp->y >= LCD_REMOTE_HEIGHT) || | ||
617 | ((vp->y + vp->height) > LCD_REMOTE_HEIGHT)) | ||
618 | { | ||
619 | return WPS_ERROR_INVALID_PARAM; | ||
620 | } | ||
621 | } | 647 | } |
622 | else | 648 | |
623 | #endif | 649 | #ifdef HAVE_LCD_COLOR |
650 | if (depth == 16) | ||
624 | { | 651 | { |
625 | if ((vp->x >= LCD_WIDTH) || | 652 | if ((valid&(1<<PL_FG)) == 0) |
626 | ((vp->x + vp->width) > LCD_WIDTH) || | 653 | vp->fg_pattern = global_settings.fg_color; |
627 | (vp->y >= LCD_HEIGHT) || | 654 | if ((valid&(1<<PL_BG)) == 0) |
628 | ((vp->y + vp->height) > LCD_HEIGHT)) | 655 | vp->fg_pattern = global_settings.bg_color; |
629 | { | ||
630 | return WPS_ERROR_INVALID_PARAM; | ||
631 | } | ||
632 | } | 656 | } |
657 | #endif | ||
633 | 658 | ||
634 | wps_data->viewports[wps_data->num_viewports-1].last_line = wps_data->num_lines - 1; | 659 | wps_data->viewports[wps_data->num_viewports-1].last_line = wps_data->num_lines - 1; |
635 | 660 | ||