Lines Matching refs:handle

16 static void emit_line_begin(rfc3676_parser_t handle);
18 static void emit_line_contents(rfc3676_parser_t handle,
22 static void emit_line_flowed_wrap(rfc3676_parser_t handle);
24 static void emit_line_end(rfc3676_parser_t handle);
27 static void nonflowed_line_begin(rfc3676_parser_t handle);
29 static void nonflowed_line_contents(rfc3676_parser_t handle,
33 static void nonflowed_line_end(rfc3676_parser_t handle);
85 void (*line_begin_handler)(rfc3676_parser_t handle);
88 void (*line_content_handler)(rfc3676_parser_t handle,
93 void (*line_end_handler)(rfc3676_parser_t handle);
117 void (*nonflowed_line_process)(struct rfc3676_parser_struct *handle,
122 void (*nonflowed_line_end)(struct rfc3676_parser_struct *handle);
127 static size_t scan_crlf(rfc3676_parser_t handle,
130 static size_t scan_crlf_seen_cr(rfc3676_parser_t handle,
133 static size_t start_of_line(rfc3676_parser_t handle,
136 static size_t count_quote_level(rfc3676_parser_t handle,
139 static size_t counted_quote_level(rfc3676_parser_t handle,
142 static size_t check_signature_block(rfc3676_parser_t handle,
145 static size_t start_content_line(rfc3676_parser_t handle,
148 static size_t scan_content_line(rfc3676_parser_t handle,
151 static size_t seen_sig_block(rfc3676_parser_t handle,
154 static size_t seen_notsig_block(rfc3676_parser_t handle,
157 static size_t seen_content_sp(rfc3676_parser_t handle,
167 rfc3676_parser_t handle= in rfc3676parser_init() local
171 if (!handle) in rfc3676parser_init()
174 handle->info=*info; in rfc3676parser_init()
175 if ((handle->uhandle=unicode_convert_init(info->charset, in rfc3676parser_init()
178 handle)) == NULL) in rfc3676parser_init()
180 free(handle); in rfc3676parser_init()
184 if (!handle->info.isflowed) in rfc3676parser_init()
185 handle->info.isdelsp=0; /* Sanity check */ in rfc3676parser_init()
187 handle->line_handler=scan_crlf; in rfc3676parser_init()
188 handle->content_handler=start_of_line; in rfc3676parser_init()
189 handle->has_previous_quote_level=0; in rfc3676parser_init()
190 handle->previous_quote_level=0; in rfc3676parser_init()
192 handle->line_begin_handler=emit_line_begin; in rfc3676parser_init()
193 handle->line_content_handler=emit_line_contents; in rfc3676parser_init()
194 handle->line_end_handler=emit_line_end; in rfc3676parser_init()
196 unicode_buf_init(&handle->nonflowed_line, (size_t)-1); in rfc3676parser_init()
197 unicode_buf_init(&handle->nonflowed_next_word, (size_t)-1); in rfc3676parser_init()
199 if (!handle->info.isflowed) in rfc3676parser_init()
201 handle->line_begin_handler=nonflowed_line_begin; in rfc3676parser_init()
202 handle->line_content_handler=nonflowed_line_contents; in rfc3676parser_init()
203 handle->line_end_handler=nonflowed_line_end; in rfc3676parser_init()
205 return handle; in rfc3676parser_init()
208 int rfc3676parser(rfc3676_parser_t handle, in rfc3676parser() argument
212 if (handle->errflag) in rfc3676parser()
213 return handle->errflag; /* Error occured previously */ in rfc3676parser()
217 return unicode_convert(handle->uhandle, txt, txt_cnt); in rfc3676parser()
227 rfc3676_parser_t handle=(rfc3676_parser_t)arg; in parse_unicode() local
233 while (handle->errflag == 0 && nbytes) in parse_unicode()
252 while (handle->errflag == 0 && cnt) in parse_unicode()
254 size_t n=(*handle->line_handler)(handle, p, cnt); in parse_unicode()
256 if (handle->errflag == 0) in parse_unicode()
264 return handle->errflag; in parse_unicode()
267 int rfc3676parser_deinit(rfc3676_parser_t handle, int *errptr) in rfc3676parser_deinit() argument
271 int rc=unicode_convert_deinit(handle->uhandle, errptr); in rfc3676parser_deinit()
274 rc=handle->errflag; in rfc3676parser_deinit()
278 (*handle->line_handler)(handle, NULL, 0); in rfc3676parser_deinit()
279 rc=handle->errflag; in rfc3676parser_deinit()
282 if (handle->lb) in rfc3676parser_deinit()
284 int rc2=unicode_lbc_end(handle->lb); in rfc3676parser_deinit()
290 unicode_buf_deinit(&handle->nonflowed_line); in rfc3676parser_deinit()
291 unicode_buf_deinit(&handle->nonflowed_next_word); in rfc3676parser_deinit()
293 free(handle); in rfc3676parser_deinit()
301 static size_t scan_crlf(rfc3676_parser_t handle, in scan_crlf() argument
308 if (handle->errflag == 0) in scan_crlf()
309 (*handle->content_handler)(handle, NULL, 0); in scan_crlf()
323 while (i && handle->errflag == 0) in scan_crlf()
325 size_t n=(*handle->content_handler)(handle, ptr, i); in scan_crlf()
336 handle->line_handler=scan_crlf_seen_cr; in scan_crlf()
344 static size_t scan_crlf_seen_cr(rfc3676_parser_t handle, in scan_crlf_seen_cr() argument
349 handle->line_handler=scan_crlf; in scan_crlf_seen_cr()
358 while (handle->errflag == 0) in scan_crlf_seen_cr()
359 if ((*handle->content_handler)(handle, &cr, 1)) in scan_crlf_seen_cr()
363 return scan_crlf(handle, ptr, cnt); in scan_crlf_seen_cr()
376 static size_t start_of_line(rfc3676_parser_t handle, in start_of_line() argument
381 if (handle->has_previous_quote_level) in start_of_line()
382 EMIT_LINE_END(handle); /* Last line was flowed */ in start_of_line()
389 handle->content_handler=count_quote_level; in start_of_line()
390 handle->quote_level=0; in start_of_line()
391 return count_quote_level(handle, ptr, cnt); in start_of_line()
398 static size_t count_quote_level(rfc3676_parser_t handle, in count_quote_level() argument
404 return (handle->content_handler=counted_quote_level) in count_quote_level()
405 (handle, ptr, cnt); in count_quote_level()
409 if (ptr[i] != '>' || !handle->info.isflowed) in count_quote_level()
411 handle->content_handler=counted_quote_level; in count_quote_level()
414 return counted_quote_level(handle, ptr, cnt); in count_quote_level()
417 ++handle->quote_level; in count_quote_level()
427 static size_t counted_quote_level(rfc3676_parser_t handle, in counted_quote_level() argument
430 handle->was_previous_quote_level=0; in counted_quote_level()
437 if (handle->has_previous_quote_level && in counted_quote_level()
438 handle->quote_level == handle->previous_quote_level) in counted_quote_level()
441 handle->was_previous_quote_level=1; in counted_quote_level()
450 if (handle->has_previous_quote_level) in counted_quote_level()
451 EMIT_LINE_END(handle); in counted_quote_level()
453 EMIT_LINE_BEGIN(handle); in counted_quote_level()
456 handle->has_previous_quote_level=0; in counted_quote_level()
460 if (!handle->info.isflowed) in counted_quote_level()
466 handle->content_handler=scan_content_line; in counted_quote_level()
467 return scan_content_line(handle, ptr, cnt); in counted_quote_level()
471 handle->content_handler=start_content_line; in counted_quote_level()
476 return start_content_line(handle, ptr, cnt); in counted_quote_level()
494 static size_t start_content_line(rfc3676_parser_t handle, in start_content_line() argument
501 handle->content_handler=check_signature_block; in start_content_line()
502 handle->sig_block_index=0; in start_content_line()
504 if (ptr && *ptr == '\n' && handle->was_previous_quote_level) in start_content_line()
506 EMIT_LINE_END(handle); in start_content_line()
507 EMIT_LINE_BEGIN(handle); in start_content_line()
508 handle->was_previous_quote_level=0; in start_content_line()
511 return check_signature_block(handle, ptr, cnt); in start_content_line()
519 static size_t check_signature_block(rfc3676_parser_t handle, in check_signature_block() argument
522 if (ptr && *ptr == sig_block[handle->sig_block_index]) in check_signature_block()
524 if (++handle->sig_block_index == sizeof(sig_block) in check_signature_block()
528 handle->content_handler=seen_sig_block; in check_signature_block()
532 return seen_notsig_block(handle, ptr, cnt); in check_signature_block()
535 static size_t seen_sig_block(rfc3676_parser_t handle, in seen_sig_block() argument
546 if (handle->was_previous_quote_level) in seen_sig_block()
548 EMIT_LINE_END(handle); in seen_sig_block()
549 EMIT_LINE_BEGIN(handle); in seen_sig_block()
550 handle->was_previous_quote_level=0; in seen_sig_block()
555 handle->content_handler=start_of_line; in seen_sig_block()
557 EMIT_LINE_CONTENTS(handle, sig_block, in seen_sig_block()
559 EMIT_LINE_END(handle); in seen_sig_block()
563 return seen_notsig_block(handle, ptr, cnt); in seen_sig_block()
568 static size_t seen_notsig_block(rfc3676_parser_t handle, in seen_notsig_block() argument
574 if (handle->was_previous_quote_level) in seen_notsig_block()
575 emit_line_flowed_wrap(handle); in seen_notsig_block()
577 handle->content_handler=scan_content_line; in seen_notsig_block()
580 i=handle->sig_block_index; in seen_notsig_block()
582 while (i && handle->errflag == 0) in seen_notsig_block()
584 size_t n=(*handle->content_handler)(handle, ptr, i); in seen_notsig_block()
590 return (*handle->content_handler)(handle, newptr, newcnt); in seen_notsig_block()
598 static size_t scan_content_line(rfc3676_parser_t handle, in scan_content_line() argument
604 (ptr[i] != ' ' || !handle->info.isflowed); ++i) in scan_content_line()
610 EMIT_LINE_CONTENTS(handle, ptr, i); in scan_content_line()
617 handle->content_handler=seen_content_sp; in scan_content_line()
622 EMIT_LINE_END(handle); in scan_content_line()
624 handle->content_handler=start_of_line; in scan_content_line()
629 static size_t seen_content_sp(rfc3676_parser_t handle, in seen_content_sp() argument
634 handle->content_handler=scan_content_line; in seen_content_sp()
642 EMIT_LINE_CONTENTS(handle, &sp, 1); in seen_content_sp()
643 return scan_content_line(handle, ptr, cnt); in seen_content_sp()
648 if (!handle->info.isdelsp) in seen_content_sp()
649 EMIT_LINE_CONTENTS(handle, &sp, 1); in seen_content_sp()
651 handle->has_previous_quote_level=1; in seen_content_sp()
652 handle->previous_quote_level=handle->quote_level; in seen_content_sp()
653 handle->content_handler=start_of_line; in seen_content_sp()
678 static void emit_line_begin(rfc3676_parser_t handle) in emit_line_begin() argument
680 if (handle->errflag == 0) in emit_line_begin()
681 handle->errflag=(*handle->info.line_begin)(handle->quote_level, in emit_line_begin()
682 handle->info.arg); in emit_line_begin()
685 static void emit_line_flowed_wrap(rfc3676_parser_t handle) in emit_line_flowed_wrap() argument
687 if (handle->errflag == 0 && handle->info.line_flowed_notify) in emit_line_flowed_wrap()
688 handle->errflag=(*handle->info.line_flowed_notify) in emit_line_flowed_wrap()
689 (handle->info.arg); in emit_line_flowed_wrap()
692 static void emit_line_contents(rfc3676_parser_t handle, in emit_line_contents() argument
696 if (handle->errflag == 0 && cnt > 0) in emit_line_contents()
697 handle->errflag=(*handle->info.line_contents) in emit_line_contents()
698 (uc, cnt, handle->info.arg); in emit_line_contents()
701 static void emit_line_end(rfc3676_parser_t handle) in emit_line_end() argument
703 if (handle->errflag == 0) in emit_line_end()
704 handle->errflag=(*handle->info.line_end)(handle->info.arg); in emit_line_end()
718 static void initial_nonflowed_line(rfc3676_parser_t handle,
723 static void initial_nonflowed_end(rfc3676_parser_t handle);
725 static void begin_forced_rewrap(rfc3676_parser_t handle);
730 static void nonflowed_line_begin(rfc3676_parser_t handle) in nonflowed_line_begin() argument
732 if (handle->lb) in nonflowed_line_begin()
736 int rc=unicode_lbc_end(handle->lb); in nonflowed_line_begin()
738 if (rc && handle->errflag == 0) in nonflowed_line_begin()
739 handle->errflag=rc; in nonflowed_line_begin()
742 if ((handle->lb=unicode_lbc_init(nonflowed_line_process, handle)) in nonflowed_line_begin()
745 if (handle->errflag == 0) in nonflowed_line_begin()
746 handle->errflag=-1; in nonflowed_line_begin()
749 if (handle->lb) in nonflowed_line_begin()
750 unicode_lbc_set_opts(handle->lb, in nonflowed_line_begin()
754 unicode_buf_clear(&handle->nonflowed_line); in nonflowed_line_begin()
755 unicode_buf_clear(&handle->nonflowed_next_word); in nonflowed_line_begin()
757 handle->nonflowed_line_width=0; in nonflowed_line_begin()
758 handle->nonflowed_next_word_width=0; in nonflowed_line_begin()
760 handle->nonflowed_line_process=initial_nonflowed_line; in nonflowed_line_begin()
761 handle->nonflowed_line_end=initial_nonflowed_end; in nonflowed_line_begin()
762 emit_line_begin(handle); /* Fallthru - user callback */ in nonflowed_line_begin()
764 handle->nonflowed_line_target_width= in nonflowed_line_begin()
765 handle->quote_level < NONFLOWED_WRAP_REDUCE - 20 ? in nonflowed_line_begin()
766 NONFLOWED_WRAP_REDUCE - handle->quote_level:20; in nonflowed_line_begin()
774 static void nonflowed_line_contents(rfc3676_parser_t handle, in nonflowed_line_contents() argument
778 if (!handle->lb) in nonflowed_line_contents()
783 if (handle->errflag == 0) in nonflowed_line_contents()
784 handle->errflag=unicode_lbc_next(handle->lb, *uc); in nonflowed_line_contents()
795 static void nonflowed_line_end(rfc3676_parser_t handle) in nonflowed_line_end() argument
797 if (handle->lb) in nonflowed_line_end()
799 int rc=unicode_lbc_end(handle->lb); in nonflowed_line_end()
801 if (rc && handle->errflag == 0) in nonflowed_line_end()
802 handle->errflag=rc; in nonflowed_line_end()
804 handle->lb=NULL; in nonflowed_line_end()
807 (*handle->nonflowed_line_end)(handle); in nonflowed_line_end()
808 emit_line_end(handle); /* FALLTHRU */ in nonflowed_line_end()
819 rfc3676_parser_t handle=(rfc3676_parser_t)dummy; in nonflowed_line_process() local
821 (*handle->nonflowed_line_process)(handle, linebreak_opportunity, ch, in nonflowed_line_process()
831 static void initial_nonflowed_line(rfc3676_parser_t handle, in initial_nonflowed_line() argument
841 handle->nonflowed_line_width + handle->nonflowed_next_word_width in initial_nonflowed_line()
842 <= handle->nonflowed_line_target_width) in initial_nonflowed_line()
844 unicode_buf_append_buf(&handle->nonflowed_line, in initial_nonflowed_line()
845 &handle->nonflowed_next_word); in initial_nonflowed_line()
846 handle->nonflowed_line_width += in initial_nonflowed_line()
847 handle->nonflowed_next_word_width; in initial_nonflowed_line()
849 unicode_buf_clear(&handle->nonflowed_next_word); in initial_nonflowed_line()
850 handle->nonflowed_next_word_width=0; in initial_nonflowed_line()
860 unicode_buf_append(&handle->nonflowed_next_word, &ch, 1); in initial_nonflowed_line()
861 handle->nonflowed_next_word_width += ch_width; in initial_nonflowed_line()
863 if (handle->nonflowed_line_width + handle->nonflowed_next_word_width in initial_nonflowed_line()
864 > handle->nonflowed_line_target_width in initial_nonflowed_line()
866 begin_forced_rewrap(handle); in initial_nonflowed_line()
872 static void initial_nonflowed_end(rfc3676_parser_t handle) in initial_nonflowed_end() argument
874 emit_line_contents(handle, in initial_nonflowed_end()
875 unicode_buf_ptr(&handle->nonflowed_line), in initial_nonflowed_end()
876 unicode_buf_len(&handle->nonflowed_line)); in initial_nonflowed_end()
878 emit_line_contents(handle, in initial_nonflowed_end()
879 unicode_buf_ptr(&handle->nonflowed_next_word), in initial_nonflowed_end()
880 unicode_buf_len(&handle->nonflowed_next_word)); in initial_nonflowed_end()
889 static void check_abnormal_line(rfc3676_parser_t handle) in check_abnormal_line() argument
894 if (unicode_buf_len(&handle->nonflowed_line) > 0) in check_abnormal_line()
899 n=unicode_buf_len(&handle->nonflowed_next_word); in check_abnormal_line()
900 p=unicode_buf_ptr(&handle->nonflowed_next_word); in check_abnormal_line()
911 unicode_buf_append(&handle->nonflowed_line, p, n); in check_abnormal_line()
912 unicode_buf_remove(&handle->nonflowed_next_word, 0, n); in check_abnormal_line()
918 handle->nonflowed_next_word_width=0; in check_abnormal_line()
919 p=unicode_buf_ptr(&handle->nonflowed_next_word); in check_abnormal_line()
921 for (i=0; i<unicode_buf_len(&handle->nonflowed_next_word); ++i) in check_abnormal_line()
922 handle->nonflowed_next_word_width += in check_abnormal_line()
930 static void forced_rewrap_line(rfc3676_parser_t handle,
935 static void forced_rewrap_end(rfc3676_parser_t handle);
940 static void emit_rewrapped_line(rfc3676_parser_t handle) in emit_rewrapped_line() argument
942 check_abnormal_line(handle); in emit_rewrapped_line()
943 emit_line_contents(handle, unicode_buf_ptr(&handle->nonflowed_line), in emit_rewrapped_line()
944 unicode_buf_len(&handle->nonflowed_line)); in emit_rewrapped_line()
946 emit_line_flowed_wrap(handle); in emit_rewrapped_line()
949 unicode_buf_clear(&handle->nonflowed_line); in emit_rewrapped_line()
950 handle->nonflowed_line_width=0; in emit_rewrapped_line()
953 static void begin_forced_rewrap(rfc3676_parser_t handle) in begin_forced_rewrap() argument
955 handle->nonflowed_line_process=forced_rewrap_line; in begin_forced_rewrap()
956 handle->nonflowed_line_end=forced_rewrap_end; in begin_forced_rewrap()
957 emit_rewrapped_line(handle); in begin_forced_rewrap()
960 static void forced_rewrap_line(rfc3676_parser_t handle, in forced_rewrap_line() argument
969 if (handle->nonflowed_line_width in forced_rewrap_line()
970 + handle->nonflowed_next_word_width in forced_rewrap_line()
971 > handle->nonflowed_line_target_width) in forced_rewrap_line()
974 emit_rewrapped_line(handle); in forced_rewrap_line()
977 unicode_buf_append_buf(&handle->nonflowed_line, in forced_rewrap_line()
978 &handle->nonflowed_next_word); in forced_rewrap_line()
980 handle->nonflowed_line_width += in forced_rewrap_line()
981 handle->nonflowed_next_word_width; in forced_rewrap_line()
982 unicode_buf_clear(&handle->nonflowed_next_word); in forced_rewrap_line()
983 handle->nonflowed_next_word_width=0; in forced_rewrap_line()
990 if (handle->nonflowed_line_width == 0 && in forced_rewrap_line()
991 handle->nonflowed_next_word_width + ch_width in forced_rewrap_line()
992 > handle->nonflowed_line_target_width) in forced_rewrap_line()
994 emit_rewrapped_line(handle); in forced_rewrap_line()
997 unicode_buf_append(&handle->nonflowed_next_word, &ch, 1); in forced_rewrap_line()
998 handle->nonflowed_next_word_width += ch_width; in forced_rewrap_line()
1001 static void forced_rewrap_end(rfc3676_parser_t handle) in forced_rewrap_end() argument
1003 initial_nonflowed_end(handle); /* Same logic, for now */ in forced_rewrap_end()