/* {{{ proto bool GmagickDraw::setFont(string font_name) Sets the fully-sepecified font to use when annotating with text. */ PHP_METHOD(gmagickdraw, setfont) { php_gmagickdraw_object *internd; char *font, *absolute; int font_len, error = 0; /* Parse parameters given to function */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &font, &font_len) == FAILURE) { return; } /* Check that no empty string is passed */ if (font_len == 0) { GMAGICK_THROW_EXCEPTION_WITH_MESSAGE(GMAGICKDRAW_CLASS, "Can not set empty font", 2); } internd = (php_gmagickdraw_object *)zend_object_store_get_object(getThis() TSRMLS_CC); /* And if it wasn't */ if (!check_configured_font(font, font_len TSRMLS_CC)) { if (!(absolute = expand_filepath(font, NULL TSRMLS_CC))) { GMAGICK_THROW_EXCEPTION_WITH_MESSAGE(GMAGICKDRAW_CLASS, "Unable to set font", 2); } /* Do a safe-mode check for the font */ GMAGICK_SAFE_MODE_CHECK(absolute, error); GMAGICKDRAW_CHECK_READ_OR_WRITE_ERROR(internd, absolute, error, GMAGICK_FREE_FILENAME); if (VCWD_ACCESS(absolute, F_OK|R_OK)) { zend_throw_exception_ex(php_gmagickdraw_exception_class_entry, 2 TSRMLS_CC, "The given font is not found in the GraphicsMagick configuration and the file (%s) is not accessible", absolute); efree(absolute); return; } DrawSetFont(internd->drawing_wand, absolute); efree(absolute); } else { DrawSetFont(internd->drawing_wand, font); } GMAGICK_CHAIN_METHOD; }
/**{{{ */ int _log(char *str) { zval *logPath, *fileName, *maxSize, *maxNum, *instance; char *fileHandler = NULL, *fileHandlerTmp = NULL, *fileHandlerTmpNew = NULL, *format_time = NULL, *format_str = NULL; struct stat buf; FILE *fp = NULL; instance = _getInstance(); maxNum = zend_read_property(mylogs_ce, instance, ZEND_STRL(MYLOGS_MAXFILE_NUM), 0 TSRMLS_CC); maxSize = zend_read_property(mylogs_ce, instance, ZEND_STRL(MYLOGS_MAXFILE_SIZE), 0 TSRMLS_CC); logPath = zend_read_property(mylogs_ce, instance, ZEND_STRL(MYLOGS_PATH), 0 TSRMLS_CC); fileName = zend_read_property(mylogs_ce, instance, ZEND_STRL(MYLOGS_FILE_NAME), 0 TSRMLS_CC); format_time = _formatTime(); spprintf(&fileHandler, 0, "%s%s.log", Z_STRVAL_P(logPath), Z_STRVAL_P(fileName)); spprintf(&format_str, 0, "%s %s\n", format_time, str); _efree_char(format_time); if(VCWD_ACCESS(fileHandler, 0) == F_OK) { stat(fileHandler, &buf); if(buf.st_size >= Z_LVAL_P(maxSize)) { int index = 1; for(; index < Z_LVAL_P(maxNum); index++) { spprintf(&fileHandlerTmp, 0, "%s%s_%d.log", Z_STRVAL_P(logPath), Z_STRVAL_P(fileName), index); if(VCWD_ACCESS(fileHandlerTmp, 0) != F_OK) { break; } else { _efree_char(fileHandlerTmp); } } if(index == Z_LVAL_P(maxNum)) index--; for(; index >= 1; index--) { spprintf(&fileHandlerTmpNew, 0, "%s%s_%d.log", Z_STRVAL_P(logPath), Z_STRVAL_P(fileName), index); spprintf(&fileHandlerTmp, 0, "%s%s_%d.log", Z_STRVAL_P(logPath), Z_STRVAL_P(fileName), (index - 1)); VCWD_RENAME(fileHandlerTmp, fileHandlerTmpNew); _efree_char(fileHandlerTmp); _efree_char(fileHandlerTmpNew); } spprintf(&fileHandlerTmpNew, 0, "%s%s_1.log", Z_STRVAL_P(logPath), Z_STRVAL_P(fileName)); VCWD_RENAME(fileHandler, fileHandlerTmpNew); _efree_char(fileHandlerTmpNew); } } if(fileHandler != NULL) { fp = VCWD_FOPEN(fileHandler, "a+b"); efree(fileHandler); } if(fp == NULL) { _efree_char(format_str); return FAILURE; } fputs(format_str, fp); _efree_char(format_str); fclose(fp); return SUCCESS; }
PHP_METHOD(Spotify, __construct) { zval *object = getThis(); zval *z_key, *z_user, *z_pass; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &z_key, &z_user, &z_pass) == FAILURE) { return; } sp_session_config config; sp_error error; sp_session *session; FILE *fp; long key_size; char *key_filename; spotify_object *obj = (spotify_object*)zend_object_store_get_object(object TSRMLS_CC); memset(&config, 0, sizeof(config)); config.api_version = SPOTIFY_API_VERSION; config.cache_location = INI_STR("spotify.cache_location"); config.settings_location = INI_STR("spotify.settings_location"); config.user_agent = "libspotify-php"; if (VCWD_ACCESS(config.cache_location, W_OK|X_OK|R_OK) != 0) { zend_throw_exception(zend_exception_get_default(), "spotify.cache_location is not writable or readable", 0 TSRMLS_CC); return; } if (VCWD_ACCESS(config.settings_location, W_OK|X_OK|R_OK) != 0) { zend_throw_exception(zend_exception_get_default(), "spotify.settings_location is not writable or readable", 0 TSRMLS_CC); return; } key_filename = Z_STRVAL_P(z_key); fp = fopen(key_filename, "rb"); if (!fp) { zend_throw_exception(zend_exception_get_default(), "Unable to open spotify key file", 0 TSRMLS_CC); return; } fseek(fp, 0L, SEEK_END); key_size = ftell(fp); fseek(fp, 0L, SEEK_SET); if (key_size > 4096) { fclose(fp); zend_throw_exception(zend_exception_get_default(), "Key file is way too large to be a key file", 0 TSRMLS_CC); return; } obj->key_data = (char*)emalloc(sizeof(char) * key_size); if (fread(obj->key_data, 1, key_size, fp) != key_size) { fclose(fp); zend_throw_exception(zend_exception_get_default(), "Failed reading key file", 0 TSRMLS_CC); return; } fclose(fp); config.application_key = obj->key_data; config.application_key_size = key_size; config.callbacks = &callbacks; config.userdata = obj; error = sp_session_create(&config, &session); if (SP_ERROR_OK != error) { char *errMsg; spprintf(&errMsg, 0, "Unable to create session: %s", sp_error_message(error)); zend_throw_exception(zend_exception_get_default(), errMsg, 0 TSRMLS_CC); return; } sp_session_login(session, Z_STRVAL_P(z_user), Z_STRVAL_P(z_pass), 0, 0); obj->session = session; obj->timeout = 0; obj->playlistcontainer = NULL; do { sp_session_process_events(obj->session, &obj->timeout); } while (obj->timeout == 0 || !obj->is_logged_in); }