@@ -77,6 +77,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_dcode_qrcode8bit, 0, 0, 1)
77
77
ZEND_ARG_INFO (0 , level )
78
78
ZEND_END_ARG_INFO ()
79
79
80
+ ZEND_BEGIN_ARG_INFO_EX (arginfo_dcode_qrcodedata , 0 , 0 , 2 )
81
+ ZEND_ARG_INFO (0 , size )
82
+ ZEND_ARG_INFO (0 , data )
83
+ ZEND_ARG_INFO (0 , version )
84
+ ZEND_ARG_INFO (0 , level )
85
+ ZEND_END_ARG_INFO ()
80
86
/** }}} */
81
87
82
88
/* {{{ dcode_functions[]
@@ -88,6 +94,7 @@ const zend_function_entry dcode_functions[] = {
88
94
PHP_FE (dcode_decrypt , arginfo_dcode_decrypt )
89
95
PHP_FE (dcode_qrcode , arginfo_dcode_qrcode )
90
96
PHP_FE (dcode_qrcode8bit , arginfo_dcode_qrcode8bit )
97
+ PHP_FE (dcode_qrcodedata , arginfo_dcode_qrcodedata )
91
98
PHP_FE_END
92
99
};
93
100
@@ -96,6 +103,7 @@ const zend_function_entry dcode_methods[] = {
96
103
PHP_ME (dcode , decrypt , arginfo_dcode_decrypt , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
97
104
PHP_ME (dcode , qrcode , arginfo_dcode_qrcode , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
98
105
PHP_ME (dcode , qrcode8bit , arginfo_dcode_qrcode8bit , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
106
+ PHP_ME (dcode , qrcodedata , arginfo_dcode_qrcodedata , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
99
107
PHP_FE_END
100
108
};
101
109
/* }}} */
@@ -369,6 +377,30 @@ static char* dcode_write_to_png(QRcode *qrcode, int size, int margin, int *pp_le
369
377
}
370
378
/** }}} */
371
379
380
+ /** {{{ dcode_qrcode_error(QRcode * TSRMLS_DC)
381
+ * process qrcode result
382
+ * Return TRUE or FALSE */
383
+ static bool dcode_qrcode_error (QRcode * qcode TSRMLS_DC ) {
384
+ if (qcode == NULL )
385
+ {
386
+ if (errno == EINVAL ) {
387
+ php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode encode error, error invalid input object" );
388
+ }
389
+ else if (errno == ENOMEM ) {
390
+ php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode encode error, unable to allocate memory for input objects" );
391
+ }
392
+ else if (errno == ERANGE ) {
393
+ php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode encode error, input data is too large" );
394
+ }
395
+ else {
396
+ php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode encode error, errno : %d" , errno );
397
+ }
398
+ return 0 ;
399
+ }
400
+ return 1 ;
401
+ }
402
+ /** }}} */
403
+
372
404
/** {{{ DCode::encrypt($src, $sec_key = "THIS IS SHIT", $sec_rand_key_len = 8, $expire = 0)
373
405
Return False or String */
374
406
PHP_METHOD (dcode , encrypt )
@@ -671,23 +703,9 @@ PHP_METHOD(dcode, qrcode)
671
703
672
704
QRcode * qcode = NULL ;
673
705
qcode = QRcode_encodeString (str_encode , version , (QRecLevel ) level , (QRencodeMode ) mode , casesensitive );
674
- if (qcode == NULL )
675
- {
676
- if (errno == EINVAL ) {
677
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, error invalid input object" );
678
- }
679
- else if (errno == ENOMEM ) {
680
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, unable to allocate memory for input objects" );
681
- }
682
- else if (errno == ERANGE ) {
683
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, input data is too large" );
684
- }
685
- else {
686
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, errno : %d" , errno );
687
- }
706
+ if (!dcode_qrcode_error (qcode TSRMLS_CC )) {
688
707
RETURN_FALSE ;
689
708
}
690
-
691
709
int pp_len ;
692
710
char * pp = dcode_write_to_png (qcode , 3 , 4 , & pp_len );
693
711
QRcode_free (qcode );
@@ -723,20 +741,48 @@ PHP_METHOD(dcode, qrcode8bit)
723
741
724
742
QRcode * qcode = NULL ;
725
743
qcode = QRcode_encodeString8bit (src , version , (QRecLevel ) level );
726
- if (qcode == NULL )
744
+ if (!dcode_qrcode_error (qcode TSRMLS_CC )) {
745
+ RETURN_FALSE ;
746
+ }
747
+
748
+ int pp_len ;
749
+ char * pp = dcode_write_to_png (qcode , 3 , 4 , & pp_len );
750
+ QRcode_free (qcode );
751
+ qcode = NULL ;
752
+
753
+ if (pp )
727
754
{
728
- if (errno == EINVAL ) {
729
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, error invalid input object" );
730
- }
731
- else if (errno == ENOMEM ) {
732
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, unable to allocate memory for input objects" );
733
- }
734
- else if (errno == ERANGE ) {
735
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, input data is too large" );
736
- }
737
- else {
738
- php_error_docref (NULL TSRMLS_CC , E_ERROR , "DCode::qrcode error, errno : %d" , errno );
739
- }
755
+ ZVAL_STRINGL (return_value , pp , pp_len , 1 );
756
+ efree (pp );
757
+ return ;
758
+ }
759
+ else {
760
+ RETURN_FALSE ;
761
+ }
762
+ }
763
+ /** }}} */
764
+
765
+ /** {{{ DCode::qrcodedata($size, $data, $version = 0, $level = QR_ECLEVEL_L)
766
+ * Encode byte stream (may include '\0') in 8-bit mode.
767
+ * Return qrcode string
768
+ * example: file_put_contents("test.png", DCode::qrcodedata(strlen("hello"), "hello"));
769
+ */
770
+ PHP_METHOD (dcode , qrcodedata )
771
+ {
772
+ int size ;
773
+ char * data ;
774
+ int version = 0 ;
775
+ int level = (int ) QR_ECLEVEL_L ;
776
+ int data_len ;
777
+
778
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ls|ll" , & size , & data , & data_len , & version , & level ) == FAILURE ) {
779
+ php_error_docref (NULL TSRMLS_CC , E_ERROR , "Invalid arguments ");
780
+ RETURN_FALSE ;
781
+ }
782
+
783
+ QRcode * qcode = NULL ;
784
+ qcode = QRcode_encodeData (size , (const unsigned char * )data , version , (QRecLevel ) level );
785
+ if (!dcode_qrcode_error (qcode TSRMLS_CC )) {
740
786
RETURN_FALSE ;
741
787
}
742
788
@@ -793,6 +839,16 @@ PHP_FUNCTION(dcode_qrcode8bit)
793
839
}
794
840
/** }}} */
795
841
842
+ /** {{{ DCode::qrcodedata($size, $data, $version = 0, $level = QR_ECLEVEL_L)
843
+ * Return qrcode string
844
+ * example: file_put_contents("test.png", DCode::qrcodedata("hello"));
845
+ */
846
+ PHP_FUNCTION (dcode_qrcodedata )
847
+ {
848
+ PHP_MN (dcode_qrcodedata )(INTERNAL_FUNCTION_PARAM_PASSTHRU );
849
+ }
850
+ /** }}} */
851
+
796
852
/*
797
853
* Local variables:
798
854
* tab-width: 4
0 commit comments