@@ -598,7 +598,7 @@ static void _php_libxml_free_error(void *ptr)
598
598
xmlResetError ((xmlErrorPtr ) ptr );
599
599
}
600
600
601
- static void _php_list_set_error_structure (xmlErrorPtr error , const char * msg )
601
+ static void _php_list_set_error_structure (xmlErrorPtr error , const char * msg , int line , int column )
602
602
{
603
603
xmlError error_copy ;
604
604
int ret ;
@@ -611,6 +611,8 @@ static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg)
611
611
} else {
612
612
error_copy .code = XML_ERR_INTERNAL_ERROR ;
613
613
error_copy .level = XML_ERR_ERROR ;
614
+ error_copy .line = line ;
615
+ error_copy .int2 = column ;
614
616
error_copy .message = (char * )xmlStrdup ((const xmlChar * )msg );
615
617
ret = 0 ;
616
618
}
@@ -620,17 +622,17 @@ static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg)
620
622
}
621
623
}
622
624
623
- static void php_libxml_ctx_error_level (int level , void * ctx , const char * msg )
625
+ static void php_libxml_ctx_error_level (int level , void * ctx , const char * msg , int line )
624
626
{
625
627
xmlParserCtxtPtr parser ;
626
628
627
629
parser = (xmlParserCtxtPtr ) ctx ;
628
630
629
631
if (parser != NULL && parser -> input != NULL ) {
630
632
if (parser -> input -> filename ) {
631
- php_error_docref (NULL , level , "%s in %s, line: %d" , msg , parser -> input -> filename , parser -> input -> line );
633
+ php_error_docref (NULL , level , "%s in %s, line: %d" , msg , parser -> input -> filename , line );
632
634
} else {
633
- php_error_docref (NULL , level , "%s in Entity, line: %d" , msg , parser -> input -> line );
635
+ php_error_docref (NULL , level , "%s in Entity, line: %d" , msg , line );
634
636
}
635
637
} else {
636
638
php_error_docref (NULL , E_WARNING , "%s" , msg );
@@ -640,13 +642,13 @@ static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg)
640
642
void php_libxml_issue_error (int level , const char * msg )
641
643
{
642
644
if (LIBXML (error_list )) {
643
- _php_list_set_error_structure (NULL , msg );
645
+ _php_list_set_error_structure (NULL , msg , 0 , 0 );
644
646
} else {
645
647
php_error_docref (NULL , level , "%s" , msg );
646
648
}
647
649
}
648
650
649
- static void php_libxml_internal_error_handler (int error_type , void * ctx , const char * * msg , va_list ap )
651
+ static void php_libxml_internal_error_handler_ex (int error_type , void * ctx , const char * * msg , va_list ap , int line , int column )
650
652
{
651
653
char * buf ;
652
654
int len , len_iter , output = 0 ;
@@ -666,15 +668,15 @@ static void php_libxml_internal_error_handler(int error_type, void *ctx, const c
666
668
667
669
if (output == 1 ) {
668
670
if (LIBXML (error_list )) {
669
- _php_list_set_error_structure (NULL , ZSTR_VAL (LIBXML (error_buffer ).s ));
671
+ _php_list_set_error_structure (NULL , ZSTR_VAL (LIBXML (error_buffer ).s ), line , column );
670
672
} else if (!EG (exception )) {
671
673
/* Don't throw additional notices/warnings if an exception has already been thrown. */
672
674
switch (error_type ) {
673
675
case PHP_LIBXML_CTX_ERROR :
674
- php_libxml_ctx_error_level (E_WARNING , ctx , ZSTR_VAL (LIBXML (error_buffer ).s ));
676
+ php_libxml_ctx_error_level (E_WARNING , ctx , ZSTR_VAL (LIBXML (error_buffer ).s ), line );
675
677
break ;
676
678
case PHP_LIBXML_CTX_WARNING :
677
- php_libxml_ctx_error_level (E_NOTICE , ctx , ZSTR_VAL (LIBXML (error_buffer ).s ));
679
+ php_libxml_ctx_error_level (E_NOTICE , ctx , ZSTR_VAL (LIBXML (error_buffer ).s ), line );
678
680
break ;
679
681
default :
680
682
php_error_docref (NULL , E_WARNING , "%s" , ZSTR_VAL (LIBXML (error_buffer ).s ));
@@ -684,6 +686,19 @@ static void php_libxml_internal_error_handler(int error_type, void *ctx, const c
684
686
}
685
687
}
686
688
689
+ static void php_libxml_internal_error_handler (int error_type , void * ctx , const char * * msg , va_list ap )
690
+ {
691
+ int line = 0 ;
692
+ int column = 0 ;
693
+ xmlParserCtxtPtr parser = (xmlParserCtxtPtr ) ctx ;
694
+ /* Context is not valid for PHP_LIBXML_ERROR, don't dereference it in that case */
695
+ if (error_type != PHP_LIBXML_ERROR && parser != NULL && parser -> input != NULL ) {
696
+ line = parser -> input -> line ;
697
+ column = parser -> input -> col ;
698
+ }
699
+ php_libxml_internal_error_handler_ex (error_type , ctx , msg , ap , line , column );
700
+ }
701
+
687
702
static xmlParserInputPtr _php_libxml_external_entity_loader (const char * URL ,
688
703
const char * ID , xmlParserCtxtPtr context )
689
704
{
@@ -813,6 +828,14 @@ static xmlParserInputPtr _php_libxml_pre_ext_ent_loader(const char *URL,
813
828
}
814
829
}
815
830
831
+ PHP_LIBXML_API void php_libxml_pretend_ctx_error_ex (int line , int column , const char * msg ,...)
832
+ {
833
+ va_list args ;
834
+ va_start (args , msg );
835
+ php_libxml_internal_error_handler_ex (PHP_LIBXML_CTX_ERROR , NULL , & msg , args , line , column );
836
+ va_end (args );
837
+ }
838
+
816
839
PHP_LIBXML_API void php_libxml_ctx_error (void * ctx , const char * msg , ...)
817
840
{
818
841
va_list args ;
@@ -831,7 +854,7 @@ PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...)
831
854
832
855
static void php_libxml_structured_error_handler (void * userData , xmlErrorPtr error )
833
856
{
834
- _php_list_set_error_structure (error , NULL );
857
+ _php_list_set_error_structure (error , NULL , 0 , 0 );
835
858
836
859
return ;
837
860
}
0 commit comments