76static int php_iptc_put1(FILE *fp,
int spool,
unsigned char c,
unsigned char **spoolbuf)
81 if (spoolbuf) *(*spoolbuf)++ = c;
88static int php_iptc_get1(FILE *fp,
int spool,
unsigned char **spoolbuf)
95 if (c == EOF)
return EOF;
102 if (spoolbuf) *(*spoolbuf)++ = c;
109static int php_iptc_read_remaining(FILE *fp,
int spool,
unsigned char **spoolbuf)
111 while (php_iptc_get1(fp, spool, spoolbuf) != EOF)
continue;
118static int php_iptc_skip_variable(FILE *fp,
int spool,
unsigned char **spoolbuf)
123 if ((c1 = php_iptc_get1(fp, spool, spoolbuf)) == EOF)
return M_EOI;
125 if ((c2 = php_iptc_get1(fp, spool, spoolbuf)) == EOF)
return M_EOI;
127 length = (((
unsigned char) c1) << 8) + ((
unsigned char) c2);
132 if (php_iptc_get1(fp, spool, spoolbuf) == EOF)
return M_EOI;
139static int php_iptc_next_marker(FILE *fp,
int spool,
unsigned char **spoolbuf)
145 c = php_iptc_get1(fp, spool, spoolbuf);
147 if (c == EOF)
return M_EOI;
150 if ((c = php_iptc_get1(fp, spool, spoolbuf)) == EOF)
156 c = php_iptc_get1(fp, 0, 0);
161 php_iptc_put1(fp, spool, (
unsigned char)c, spoolbuf);
164 return (
unsigned int) c;
168static char psheader[] =
"\xFF\xED\0\0Photoshop 3.0\08BIM\x04\x04\0\0\0\0";
173 char *iptcdata, *jpeg_file;
174 size_t iptcdata_len, jpeg_file_len;
177 unsigned int marker, done = 0;
180 unsigned char *poi =
NULL;
195 if (iptcdata_len >=
SIZE_MAX -
sizeof(psheader) - 1025) {
200 if ((fp =
VCWD_FOPEN(jpeg_file,
"rb")) == 0) {
211 spoolbuf = zend_string_safe_alloc(1, iptcdata_len +
sizeof(psheader) + 1024 + 1, sb.st_size, 0);
212 poi = (
unsigned char*)
ZSTR_VAL(spoolbuf);
213 memset(poi, 0, iptcdata_len +
sizeof(psheader) + sb.st_size + 1024 + 1);
216 if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xFF) {
219 zend_string_efree(spoolbuf);
224 if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xD8) {
227 zend_string_efree(spoolbuf);
233 marker = php_iptc_next_marker(fp, spool, poi?&poi:0);
235 if (marker ==
M_EOI) {
237 }
else if (marker !=
M_APP13) {
238 php_iptc_put1(fp, spool, (
unsigned char)marker, poi?&poi:0);
244 php_iptc_skip_variable(fp, 0, 0);
246 php_iptc_read_remaining(fp, spool, poi?&poi:0);
259 php_iptc_skip_variable(fp, spool, poi?&poi:0);
261 if (iptcdata_len & 1) {
265 psheader[ 2 ] = (char) ((iptcdata_len+28)>>8);
266 psheader[ 3 ] = (iptcdata_len+28)&0xff;
268 for (inx = 0; inx < 28; inx++) {
269 php_iptc_put1(fp, spool, psheader[inx], poi?&poi:0);
272 php_iptc_put1(fp, spool, (
unsigned char)(iptcdata_len>>8), poi?&poi:0);
273 php_iptc_put1(fp, spool, (
unsigned char)(iptcdata_len&0xff), poi?&poi:0);
275 for (inx = 0; inx < iptcdata_len; inx++) {
276 php_iptc_put1(fp, spool, iptcdata[inx], poi?&poi:0);
282 php_iptc_read_remaining(fp, spool, poi?&poi:0);
287 php_iptc_skip_variable(fp, spool, poi?&poi:0);
295 spoolbuf = zend_string_truncate(spoolbuf, poi - (
unsigned char*)
ZSTR_VAL(spoolbuf), 0);
307 unsigned int tagsfound = 0;
308 unsigned char *
buffer, recnum, dataset;
311 zval values, *element;
317 buffer = (
unsigned char *)str;
319 while (inx < str_len) {
327 while (inx < str_len) {
328 if (
buffer[ inx++ ] != 0x1c) {
332 if ((inx + 4) >= str_len)
335 dataset =
buffer[ inx++ ];
338 if (
buffer[ inx ] & (
unsigned char) 0x80) {
339 if((inx+6) >= str_len) {
346 len = (((
unsigned short)
buffer[ inx ])<<8) | (
unsigned short)
buffer[ inx+1 ];
350 if ((
len > str_len) || (inx +
len) > str_len) {
354 snprintf(
key,
sizeof(
key),
"%d#%03d", (
unsigned int) dataset, (
unsigned int) recnum);
356 if (tagsfound == 0) {
iptcparse(string $iptc_block)
iptcembed(string $iptc_data, string $filename, int $spool=0)
memset(ptr, 0, type->size)
PHPAPI int php_check_open_basedir(const char *path)
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
unsigned char key[REFLECTION_KEY_LEN]
ZEND_API zend_result add_next_index_stringl(zval *arg, const char *str, size_t length)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
#define ZEND_PARSE_PARAMETERS_END()
#define Z_PARAM_STRING(dest, dest_len)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define Z_PARAM_LONG(dest)
#define RETURN_NEW_STR(s)
#define Z_PARAM_PATH(dest, dest_len)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
struct _zend_string zend_string
#define Z_ARRVAL_P(zval_p)
#define VCWD_FOPEN(path, mode)