CVS update: php31/ext/standard

From: Date: Tue, 01 Sep 1998 19:53:16 +0000
Subject: CVS update: php31/ext/standard
Groups: php.dev 
Request: Send a blank email to php-dev+get-722@lists.php.net to get a copy of this message
Date: Tuesday September 1, 1998 @ 15:53 Author: shane Update of /repository/php31/ext/standard In directory asf:/u2/tmp/cvs-serv28399/ext/standard Modified Files: file.c file.h Log Message: add get_meta_tags Index: php31/ext/standard/file.c diff -c php31/ext/standard/file.c:2.2 php31/ext/standard/file.c:2.3 *** php31/ext/standard/file.c:2.2 Tue Aug 25 14:56:29 1998 --- php31/ext/standard/file.c Tue Sep 1 15:53:15 1998 *************** *** 26,32 **** | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: file.c,v 2.2 1998/08/25 18:56:29 rasmus Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 26,32 ---- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: file.c,v 2.3 1998/09/01 19:53:15 shane Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 197,202 **** --- 197,203 ---- {"copy", php3_file_copy, NULL}, {"tempnam", php3_tempnam, NULL}, {"file", php3_file, NULL}, + {"get_meta_tags", php3_get_meta_tags, NULL}, {"set_socket_blocking", php3_set_socket_blocking, NULL}, #if (0 && HAVE_SYS_TIME_H && HAVE_SETSOCKOPT && defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)) {"set_socket_timeout", php3_set_socket_timeout, NULL}, *************** *** 207,212 **** --- 208,341 ---- php3_module_entry php3_file_module_entry = { "PHP_file", php3_file_functions, php3_minit_file, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES }; + + /* get_meta_tags(string filename); + extracts all meta tags from a file and creates variables from them (prefixed with meta_) + The meta tag must have a name and content attribute, otherwise it will be skipped. + The variable type created is always a string. + The function stops parsing at the closing head tag. + */ + void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS) { + pval *filename, *arg2; + FILE *fp; + char buf[8192]; + register int i=0; + int use_include_path = 0; + + int issock=0, socketd=0; + TLS_VARS; + + /* check args */ + switch (ARG_COUNT(ht)) { + case 1: + if (getParameters(ht,1,&filename) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 2: + if (getParameters(ht,2,&filename,&arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg2); + use_include_path = arg2->value.lval; + break; + default: + WRONG_PARAM_COUNT; + } + convert_to_string(filename); + + fp = php3_fopen_wrapper(filename->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd); + if (!fp && !socketd) { + if (issock != BAD_URL) { + php3_strip_url_passwd(filename->value.str.val); + php3_error(E_WARNING,"File(\"%s\") - %s",filename->value.str.val,strerror(errno)); + } + RETURN_FALSE; + } + + /* Initialize return array */ + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + /* Now loop through the file and do the magic quotes thing if needed */ + memset(buf,0,8191); + while((issock?SOCK_FGETS(buf,8191,socketd):(int)fgets(buf,8191,fp)) + && !strstr(buf,"</head>") && !strstr(buf,"</HEAD>")) { + if(strstr(buf,"<meta")||strstr(buf,"<META")) { + pval entry; + int len,var_namelen; + char var_name[50],*var,*tmp,*end; + + /* get the variable name from the name attribute of the meta tag */ + tmp=strstr(buf,"name=\""); + if(tmp){ + tmp+=6; + end=strstr(tmp,"\""); + if(end){ + unsigned char *c; + *end='\0'; + snprintf(var_name,50,"meta_%s",tmp); + *end='"'; + + c = var_name; + while (*c) { + switch(*c) { + case '.': + case '\\': + case '+': + case '*': + case '?': + case '[': + case '^': + case ']': + case '$': + case '(': + case ')': + case ' ': + *c++ ='_'; + break; + default: + *c++ = tolower((unsigned char)*c); + } + } + var_namelen=strlen(var_name); + } + + /* get the variable value from the content attribute of the meta tag */ + tmp=strstr(buf,"content=\""); + if(tmp) { + tmp+=9; + end=strstr(tmp,"\""); + if(end) { + *end='\0'; + var=estrdup(tmp); + *end='"'; + } + } + } + if(var) { + if (GLOBAL(php3_ini)->magic_quotes_runtime) { + entry.value.str.val = _php3_addslashes(var,0,&len,0); + } else { + entry.value.str.len = strlen(var); + entry.value.str.val = var; + } + entry.type = IS_STRING; + _php3_hash_update(GLOBAL(active_symbol_table), var_name, var_namelen+1, (void *) &entry, sizeof(pval),NULL); + } + } + } + if (issock) { + #if WIN32|WINNT + closesocket(socketd); + #else + close(socketd); + #endif + } else { + fclose(fp); + } + } void php3_file(INTERNAL_FUNCTION_PARAMETERS) { pval *filename, *arg2; Index: php31/ext/standard/file.h diff -c php31/ext/standard/file.h:2.0 php31/ext/standard/file.h:2.1 *** php31/ext/standard/file.h:2.0 Fri Jul 3 09:14:23 1998 --- php31/ext/standard/file.h Tue Sep 1 15:53:15 1998 *************** *** 27,33 **** +----------------------------------------------------------------------+ */ ! /* $Id: file.h,v 2.0 1998/07/03 13:14:23 rasmus Exp $ */ #ifndef _FILE_H #define _FILE_H --- 27,33 ---- +----------------------------------------------------------------------+ */ ! /* $Id: file.h,v 2.1 1998/09/01 19:53:15 shane Exp $ */ #ifndef _FILE_H #define _FILE_H *************** *** 64,68 **** --- 64,69 ---- extern void php3_file(INTERNAL_FUNCTION_PARAMETERS); extern void php3_set_socket_blocking(INTERNAL_FUNCTION_PARAMETERS); extern void php3_set_socket_timeout(INTERNAL_FUNCTION_PARAMETERS); + extern void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS); #endif /* _FILE_H */ -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#722) next »