… | |
… | |
49 | #undef ROW |
49 | #undef ROW |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
50 | #define ROW(n) THIS->row_buf [LINENO (n)] |
51 | |
51 | |
52 | ///////////////////////////////////////////////////////////////////////////// |
52 | ///////////////////////////////////////////////////////////////////////////// |
53 | |
53 | |
|
|
54 | static SV * |
|
|
55 | taint (SV *sv) |
|
|
56 | { |
|
|
57 | SvTAINT (sv); |
|
|
58 | return sv; |
|
|
59 | } |
|
|
60 | |
|
|
61 | static SV * |
|
|
62 | taint_if (SV *sv, SV *src) |
|
|
63 | { |
|
|
64 | if (SvTAINTED (src)) |
|
|
65 | SvTAINT (sv); |
|
|
66 | |
|
|
67 | return sv; |
|
|
68 | } |
|
|
69 | |
54 | static wchar_t * |
70 | static wchar_t * |
55 | sv2wcs (SV *sv) |
71 | sv2wcs (SV *sv) |
56 | { |
72 | { |
57 | STRLEN len; |
73 | STRLEN len; |
58 | char *str = SvPVutf8 (sv, len); |
74 | char *str = SvPVutf8 (sv, len); |
… | |
… | |
396 | { |
412 | { |
397 | if (!perl) |
413 | if (!perl) |
398 | { |
414 | { |
399 | char *argv[] = { |
415 | char *argv[] = { |
400 | "", |
416 | "", |
|
|
417 | "-T", |
401 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
418 | "-edo '" LIBDIR "/urxvt.pm' or ($@ and die $@) or exit 1", |
402 | }; |
419 | }; |
403 | |
420 | |
404 | perl = perl_alloc (); |
421 | perl = perl_alloc (); |
405 | perl_construct (perl); |
422 | perl_construct (perl); |
406 | |
423 | |
407 | if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) |
424 | if (perl_parse (perl, xs_init, 3, argv, (char **)NULL) |
408 | || perl_run (perl)) |
425 | || perl_run (perl)) |
409 | { |
426 | { |
410 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
427 | rxvt_warn ("unable to initialize perl-interpreter, continuing without.\n"); |
411 | |
428 | |
412 | perl_destruct (perl); |
429 | perl_destruct (perl); |
413 | perl_free (perl); |
430 | perl_free (perl); |
414 | perl = 0; |
431 | perl = 0; |
415 | } |
432 | } |
|
|
433 | } |
|
|
434 | } |
|
|
435 | |
|
|
436 | static void |
|
|
437 | ungrab (rxvt_term *THIS) |
|
|
438 | { |
|
|
439 | if (THIS->perl.grabtime) |
|
|
440 | { |
|
|
441 | XUngrabKeyboard (THIS->display->display, THIS->perl.grabtime); |
|
|
442 | XUngrabPointer (THIS->display->display, THIS->perl.grabtime); |
|
|
443 | THIS->perl.grabtime = 0; |
416 | } |
444 | } |
417 | } |
445 | } |
418 | |
446 | |
419 | bool |
447 | bool |
420 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
448 | rxvt_perl_interp::invoke (rxvt_term *term, hook_type htype, ...) |
… | |
… | |
473 | case DT_LONG: |
501 | case DT_LONG: |
474 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
502 | XPUSHs (sv_2mortal (newSViv (va_arg (ap, long)))); |
475 | break; |
503 | break; |
476 | |
504 | |
477 | case DT_STR: |
505 | case DT_STR: |
478 | XPUSHs (sv_2mortal (newSVpv (va_arg (ap, char *), 0))); |
506 | XPUSHs (taint (sv_2mortal (newSVpv (va_arg (ap, char *), 0)))); |
479 | break; |
507 | break; |
480 | |
508 | |
481 | case DT_STR_LEN: |
509 | case DT_STR_LEN: |
482 | { |
510 | { |
483 | char *str = va_arg (ap, char *); |
511 | char *str = va_arg (ap, char *); |
484 | int len = va_arg (ap, int); |
512 | int len = va_arg (ap, int); |
485 | |
513 | |
486 | XPUSHs (sv_2mortal (newSVpvn (str, len))); |
514 | XPUSHs (taint (sv_2mortal (newSVpvn (str, len)))); |
487 | } |
515 | } |
488 | break; |
516 | break; |
489 | |
517 | |
490 | case DT_WCS_LEN: |
518 | case DT_WCS_LEN: |
491 | { |
519 | { |
492 | wchar_t *wstr = va_arg (ap, wchar_t *); |
520 | wchar_t *wstr = va_arg (ap, wchar_t *); |
493 | int wlen = va_arg (ap, int); |
521 | int wlen = va_arg (ap, int); |
494 | |
522 | |
495 | XPUSHs (sv_2mortal (wcs2sv (wstr, wlen))); |
523 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, wlen)))); |
496 | } |
524 | } |
497 | break; |
525 | break; |
498 | |
526 | |
499 | case DT_XEVENT: |
527 | case DT_XEVENT: |
500 | { |
528 | { |
… | |
… | |
565 | PUTBACK; |
593 | PUTBACK; |
566 | FREETMPS; |
594 | FREETMPS; |
567 | LEAVE; |
595 | LEAVE; |
568 | |
596 | |
569 | if (SvTRUE (ERRSV)) |
597 | if (SvTRUE (ERRSV)) |
|
|
598 | { |
570 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
599 | rxvt_warn ("perl hook %d evaluation error: %s", htype, SvPV_nolen (ERRSV)); |
|
|
600 | ungrab (term); // better lose the grab than the session |
|
|
601 | } |
571 | |
602 | |
572 | if (htype == HOOK_DESTROY) |
603 | if (htype == HOOK_DESTROY) |
573 | { |
604 | { |
574 | clearSVptr ((SV *)term->perl.self); |
605 | clearSVptr ((SV *)term->perl.self); |
575 | SvREFCNT_dec ((SV *)term->perl.self); |
606 | SvREFCNT_dec ((SV *)term->perl.self); |
… | |
… | |
676 | void |
707 | void |
677 | fatal (const char *msg) |
708 | fatal (const char *msg) |
678 | CODE: |
709 | CODE: |
679 | rxvt_fatal ("%s", msg); |
710 | rxvt_fatal ("%s", msg); |
680 | |
711 | |
|
|
712 | SV * |
|
|
713 | untaint (SV *sv) |
|
|
714 | CODE: |
|
|
715 | RETVAL = newSVsv (sv); |
|
|
716 | SvTAINTED_off (RETVAL); |
|
|
717 | OUTPUT: |
|
|
718 | RETVAL |
|
|
719 | |
|
|
720 | bool |
|
|
721 | safe () |
|
|
722 | CODE: |
|
|
723 | RETVAL = !rxvt_tainted (); |
|
|
724 | OUTPUT: |
|
|
725 | RETVAL |
|
|
726 | |
681 | NV |
727 | NV |
682 | NOW () |
728 | NOW () |
683 | CODE: |
729 | CODE: |
684 | RETVAL = NOW; |
730 | RETVAL = NOW; |
685 | OUTPUT: |
731 | OUTPUT: |
… | |
… | |
765 | } |
811 | } |
766 | OUTPUT: |
812 | OUTPUT: |
767 | RETVAL |
813 | RETVAL |
768 | |
814 | |
769 | void |
815 | void |
770 | rxvt_term::allow_events_async (U32 eventtime = THIS->perl.grabtime) |
816 | rxvt_term::allow_events_async () |
771 | CODE: |
817 | CODE: |
772 | XAllowEvents (THIS->display->display, AsyncBoth, eventtime); |
818 | XAllowEvents (THIS->display->display, AsyncBoth, THIS->perl.grabtime); |
773 | |
819 | |
774 | void |
820 | void |
775 | rxvt_term::allow_events_sync (U32 eventtime = THIS->perl.grabtime) |
821 | rxvt_term::allow_events_sync () |
776 | CODE: |
822 | CODE: |
777 | XAllowEvents (THIS->display->display, SyncBoth, eventtime); |
823 | XAllowEvents (THIS->display->display, SyncBoth, THIS->perl.grabtime); |
778 | |
824 | |
779 | void |
825 | void |
780 | rxvt_term::allow_events_replay (U32 eventtime = THIS->perl.grabtime) |
826 | rxvt_term::allow_events_replay () |
781 | CODE: |
827 | CODE: |
782 | XAllowEvents (THIS->display->display, ReplayPointer, eventtime); |
828 | XAllowEvents (THIS->display->display, ReplayPointer, THIS->perl.grabtime); |
783 | XAllowEvents (THIS->display->display, ReplayKeyboard, eventtime); |
829 | XAllowEvents (THIS->display->display, ReplayKeyboard, THIS->perl.grabtime); |
784 | |
830 | |
785 | void |
831 | void |
786 | rxvt_term::ungrab (U32 eventtime = THIS->perl.grabtime) |
832 | rxvt_term::ungrab () |
787 | CODE: |
833 | CODE: |
788 | THIS->perl.grabtime = 0; |
834 | ungrab (THIS); |
789 | XUngrabKeyboard (THIS->display->display, eventtime); |
|
|
790 | XUngrabPointer (THIS->display->display, eventtime); |
|
|
791 | |
835 | |
792 | int |
836 | int |
793 | rxvt_term::strwidth (SV *str) |
837 | rxvt_term::strwidth (SV *str) |
794 | CODE: |
838 | CODE: |
795 | { |
839 | { |
… | |
… | |
814 | char *mbstr = rxvt_wcstombs (wstr); |
858 | char *mbstr = rxvt_wcstombs (wstr); |
815 | rxvt_pop_locale (); |
859 | rxvt_pop_locale (); |
816 | |
860 | |
817 | free (wstr); |
861 | free (wstr); |
818 | |
862 | |
819 | RETVAL = newSVpv (mbstr, 0); |
863 | RETVAL = taint_if (newSVpv (mbstr, 0), str); |
820 | free (mbstr); |
864 | free (mbstr); |
821 | } |
865 | } |
822 | OUTPUT: |
866 | OUTPUT: |
823 | RETVAL |
867 | RETVAL |
824 | |
868 | |
… | |
… | |
831 | |
875 | |
832 | rxvt_push_locale (THIS->locale); |
876 | rxvt_push_locale (THIS->locale); |
833 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
877 | wchar_t *wstr = rxvt_mbstowcs (data, len); |
834 | rxvt_pop_locale (); |
878 | rxvt_pop_locale (); |
835 | |
879 | |
836 | RETVAL = wcs2sv (wstr); |
880 | RETVAL = taint_if (wcs2sv (wstr), octets); |
837 | free (wstr); |
881 | free (wstr); |
838 | } |
882 | } |
839 | OUTPUT: |
883 | OUTPUT: |
840 | RETVAL |
884 | RETVAL |
841 | |
885 | |
… | |
… | |
888 | case 2: RETVAL = THIS->ModNumLockMask; break; |
932 | case 2: RETVAL = THIS->ModNumLockMask; break; |
889 | } |
933 | } |
890 | OUTPUT: |
934 | OUTPUT: |
891 | RETVAL |
935 | RETVAL |
892 | |
936 | |
|
|
937 | char * |
|
|
938 | rxvt_term::display_id () |
|
|
939 | ALIAS: |
|
|
940 | display_id = 0 |
|
|
941 | locale = 1 |
|
|
942 | CODE: |
|
|
943 | switch (ix) |
|
|
944 | { |
|
|
945 | case 0: RETVAL = THIS->display->id; break; |
|
|
946 | case 1: RETVAL = THIS->locale; break; |
|
|
947 | } |
|
|
948 | OUTPUT: |
|
|
949 | RETVAL |
|
|
950 | |
893 | U32 |
951 | U32 |
894 | rxvt_term::parent () |
952 | rxvt_term::parent () |
895 | CODE: |
953 | CODE: |
896 | RETVAL = (U32)THIS->parent [0]; |
954 | RETVAL = (U32)THIS->parent [0]; |
897 | OUTPUT: |
955 | OUTPUT: |
… | |
… | |
948 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
1006 | wchar_t *wstr = new wchar_t [THIS->ncol]; |
949 | |
1007 | |
950 | for (int col = 0; col < THIS->ncol; col++) |
1008 | for (int col = 0; col < THIS->ncol; col++) |
951 | wstr [col] = l.t [col]; |
1009 | wstr [col] = l.t [col]; |
952 | |
1010 | |
953 | XPUSHs (sv_2mortal (wcs2sv (wstr, THIS->ncol))); |
1011 | XPUSHs (taint (sv_2mortal (wcs2sv (wstr, THIS->ncol)))); |
954 | |
1012 | |
955 | delete [] wstr; |
1013 | delete [] wstr; |
956 | } |
1014 | } |
957 | |
1015 | |
958 | if (new_text) |
1016 | if (new_text) |
… | |
… | |
1079 | else |
1137 | else |
1080 | *r++ = *s; |
1138 | *r++ = *s; |
1081 | |
1139 | |
1082 | rxvt_pop_locale (); |
1140 | rxvt_pop_locale (); |
1083 | |
1141 | |
1084 | RETVAL = wcs2sv (rstr, r - rstr); |
1142 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), string); |
1085 | |
1143 | |
1086 | delete [] rstr; |
1144 | delete [] rstr; |
1087 | } |
1145 | } |
1088 | OUTPUT: |
1146 | OUTPUT: |
1089 | RETVAL |
1147 | RETVAL |
… | |
… | |
1115 | else if (IS_COMPOSE (*s)) |
1173 | else if (IS_COMPOSE (*s)) |
1116 | r += rxvt_composite.expand (*s, r); |
1174 | r += rxvt_composite.expand (*s, r); |
1117 | else |
1175 | else |
1118 | *r++ = *s; |
1176 | *r++ = *s; |
1119 | |
1177 | |
1120 | RETVAL = wcs2sv (rstr, r - rstr); |
1178 | RETVAL = taint_if (wcs2sv (rstr, r - rstr), text); |
1121 | |
1179 | |
1122 | delete [] rstr; |
1180 | delete [] rstr; |
1123 | } |
1181 | } |
1124 | OUTPUT: |
1182 | OUTPUT: |
1125 | RETVAL |
1183 | RETVAL |
… | |
… | |
1147 | |
1205 | |
1148 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1206 | if (!IN_RANGE_EXC (index, 0, NUM_RESOURCES)) |
1149 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1207 | croak ("requested out-of-bound resource %s+%d,", name, index - rs->value); |
1150 | |
1208 | |
1151 | if (GIMME_V != G_VOID) |
1209 | if (GIMME_V != G_VOID) |
1152 | XPUSHs (THIS->rs [index] ? sv_2mortal (newSVpv (THIS->rs [index], 0)) : &PL_sv_undef); |
1210 | XPUSHs (THIS->rs [index] ? sv_2mortal (taint (newSVpv (THIS->rs [index], 0))) : &PL_sv_undef); |
1153 | |
1211 | |
1154 | if (newval) |
1212 | if (newval) |
1155 | { |
1213 | { |
1156 | if (SvOK (newval)) |
1214 | if (SvOK (newval)) |
1157 | { |
1215 | { |
… | |
… | |
1199 | } |
1257 | } |
1200 | OUTPUT: |
1258 | OUTPUT: |
1201 | RETVAL |
1259 | RETVAL |
1202 | |
1260 | |
1203 | void |
1261 | void |
1204 | rxvt_term::cur (...) |
1262 | rxvt_term::screen_cur (...) |
1205 | PROTOTYPE: $;$$ |
1263 | PROTOTYPE: $;$$ |
1206 | ALIAS: |
1264 | ALIAS: |
1207 | screen_cur = 0 |
1265 | screen_cur = 0 |
1208 | selection_beg = 1 |
1266 | selection_beg = 1 |
1209 | selection_end = 2 |
1267 | selection_end = 2 |
… | |
… | |
1238 | void |
1296 | void |
1239 | rxvt_term::selection (SV *newtext = 0) |
1297 | rxvt_term::selection (SV *newtext = 0) |
1240 | PPCODE: |
1298 | PPCODE: |
1241 | { |
1299 | { |
1242 | if (GIMME_V != G_VOID) |
1300 | if (GIMME_V != G_VOID) |
|
|
1301 | XPUSHs (THIS->selection.text |
1243 | XPUSHs (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))); |
1302 | ? taint (sv_2mortal (wcs2sv (THIS->selection.text, THIS->selection.len))) |
|
|
1303 | : &PL_sv_undef); |
1244 | |
1304 | |
1245 | if (newtext) |
1305 | if (newtext) |
1246 | { |
1306 | { |
1247 | free (THIS->selection.text); |
1307 | free (THIS->selection.text); |
1248 | |
1308 | |