Created
July 11, 2012 13:11
-
-
Save peta/3090316 to your computer and use it in GitHub Desktop.
qrencode.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* $ Id: $ */ | |
#include "php_qrencode.h" | |
#if HAVE_QRENCODE | |
/* {{{ qrencode_functions[] */ | |
function_entry qrencode_functions[] = { | |
PHP_FE(qrencode , NULL) | |
{ NULL, NULL, NULL } | |
}; | |
/* }}} */ | |
/* {{{ qrencode_module_entry | |
*/ | |
zend_module_entry qrencode_module_entry = { | |
STANDARD_MODULE_HEADER, | |
"qrencode", | |
qrencode_functions, | |
PHP_MINIT(qrencode), /* Replace with NULL if there is nothing to do at php startup */ | |
PHP_MSHUTDOWN(qrencode), /* Replace with NULL if there is nothing to do at php shutdown */ | |
PHP_RINIT(qrencode), /* Replace with NULL if there is nothing to do at request start */ | |
PHP_RSHUTDOWN(qrencode), /* Replace with NULL if there is nothing to do at request end */ | |
PHP_MINFO(qrencode), | |
"0.0.1", | |
STANDARD_MODULE_PROPERTIES | |
}; | |
/* }}} */ | |
#ifdef COMPILE_DL_QRENCODE | |
ZEND_GET_MODULE(qrencode) | |
#endif | |
/* {{{ PHP_MINIT_FUNCTION */ | |
PHP_MINIT_FUNCTION(qrencode) | |
{ | |
REGISTER_LONG_CONSTANT("QR_MODE_NUM", QR_MODE_NUM, CONST_PERSISTENT | CONST_CS); | |
REGISTER_LONG_CONSTANT("QR_MODE_AN", QR_MODE_AN, CONST_PERSISTENT | CONST_CS); | |
REGISTER_LONG_CONSTANT("QR_MODE_8", QR_MODE_8, CONST_PERSISTENT | CONST_CS); | |
REGISTER_LONG_CONSTANT("QR_MODE_KANJI", QR_MODE_KANJI, CONST_PERSISTENT | CONST_CS); | |
REGISTER_LONG_CONSTANT("QR_ECLEVEL_L", QR_ECLEVEL_L, CONST_PERSISTENT | CONST_CS); | |
REGISTER_LONG_CONSTANT("QR_ECLEVEL_M", QR_ECLEVEL_M, CONST_PERSISTENT | CONST_CS); | |
REGISTER_LONG_CONSTANT("QR_ECLEVEL_Q", QR_ECLEVEL_Q, CONST_PERSISTENT | CONST_CS); | |
REGISTER_LONG_CONSTANT("QR_ECLEVEL_H", QR_ECLEVEL_H, CONST_PERSISTENT | CONST_CS); | |
/* add your stuff here */ | |
return SUCCESS; | |
} | |
/* }}} */ | |
/* {{{ PHP_MSHUTDOWN_FUNCTION */ | |
PHP_MSHUTDOWN_FUNCTION(qrencode) | |
{ | |
/* add your stuff here */ | |
return SUCCESS; | |
} | |
/* }}} */ | |
/* {{{ PHP_RINIT_FUNCTION */ | |
PHP_RINIT_FUNCTION(qrencode) | |
{ | |
/* add your stuff here */ | |
return SUCCESS; | |
} | |
/* }}} */ | |
/* {{{ PHP_RSHUTDOWN_FUNCTION */ | |
PHP_RSHUTDOWN_FUNCTION(qrencode) | |
{ | |
/* add your stuff here */ | |
return SUCCESS; | |
} | |
/* }}} */ | |
/* {{{ PHP_MINFO_FUNCTION */ | |
PHP_MINFO_FUNCTION(qrencode) | |
{ | |
php_info_print_box_start(0); | |
php_printf("<p>The unknown extension</p>\n"); | |
php_printf("<p>Version 0.0.1devel (2007-04-09)</p>\n"); | |
php_info_print_box_end(); | |
/* add your stuff here */ | |
} | |
/* }}} */ | |
/* {{{ proto array qrencode(string text,int version,int level,int mode) | |
*/ | |
PHP_FUNCTION(qrencode) | |
{ | |
const char * text = NULL; | |
int text_len = 0; | |
long version = 0; | |
long level = 0; | |
long mode = 0; | |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slll", &text, &text_len, &version, &level, &mode) == FAILURE) { | |
return; | |
} | |
array_init(return_value); | |
do { | |
QRinput *input; | |
QRcode *code; | |
unsigned char *p; | |
int x,y; | |
input = QRinput_new(); | |
QRinput_append(input,mode,text_len,text); | |
// Required because of API changes in recent libqrencode releases | |
QRinput_setVersion(input, version); | |
QRinput_setErrorCorrectionLevel(input, level); | |
code = QRcode_encodeInput(input); | |
//code = QRcode_encodeString(text, version, level, mode); | |
if(code == NULL) { | |
RETURN_FALSE; | |
} | |
array_init(return_value); | |
p = code->data; | |
for(y=0;y<code->width;y++){ | |
zval *new_array; | |
MAKE_STD_ZVAL(new_array); | |
array_init(new_array); | |
for(x=0;x<code->width;x++){ | |
add_next_index_long(new_array, (*p &1)?1:0); | |
p++; | |
} | |
add_next_index_zval(return_value, new_array); | |
} | |
QRinput_free(input); | |
QRcode_free(code); | |
} while (0); | |
} | |
/* }}} qrencode */ | |
#endif /* HAVE_QRENCODE */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment