]> granicus.if.org Git - php/commitdiff
ezmlm_hash() function also available for php4.
authorKristian Köhntopp <kk@php.net>
Thu, 29 Jun 2000 14:07:10 +0000 (14:07 +0000)
committerKristian Köhntopp <kk@php.net>
Thu, 29 Jun 2000 14:07:10 +0000 (14:07 +0000)
ext/standard/basic_functions.c
ext/standard/mail.c
ext/standard/php_mail.h

index 717a776339dfc1b423a9bb4ece1203bcf1276cf3..91ce4a2de38c8a0b00806544a6eb0cf5ce9790db 100644 (file)
@@ -455,6 +455,7 @@ function_entry basic_functions[] = {
 
        /* functions from mail.c */
        PHP_FE(mail,                                    NULL)
+       PHP_FE(ezmlm_hash,                              NULL)
 
        /* functions from syslog.c */
        PHP_FE(openlog,                                 NULL)
index 4e71e333200e902c5a11bd539d1a51553cad2232..16753a7c5cd7b473971cacbf10087bea8a03eada 100644 (file)
 ZEND_GET_MODULE(odbc)
 #endif
 
+/* {{{ proto int ezmlm_hash(string addr)
+   Calculate EZMLM list hash value. */
+PHP_FUNCTION(ezmlm_hash)
+{
+       pval **pstr = NULL;
+       char *str=NULL;
+       unsigned long h = 5381L;
+       int j, l;
+       
+       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &pstr) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       convert_to_string_ex(pstr);
+       if ((*pstr)->value.str.val) {
+               str = (*pstr)->value.str.val;
+       } else {
+               php_error(E_WARNING, "Must give string parameter to ezmlm_hash()");
+               RETURN_FALSE;
+       }
+       
+       l = strlen(str);
+       for (j=0; j<l; j++) {
+               h = (h + (h<<5)) ^ (unsigned long) (unsigned char) tolower(str[j]);
+       }
+       
+       h = (h%53);
+       
+       RETURN_LONG((int) h);
+}
+
 /* {{{ proto int mail(string to, string subject, string message [, string additional_headers])
    Send an email message */
 PHP_FUNCTION(mail)
index e897c6c83e2540a84fbfdb8f7646ef83fdc8f823..d2e33a7ed94e44a117b6c731725b57d8aa084e2b 100644 (file)
@@ -36,6 +36,7 @@
 #if HAVE_SENDMAIL
 
 PHP_FUNCTION(mail);
+PHP_FUNCTION(ezmlm_hash);
 PHP_MINFO_FUNCTION(mail);
 extern int php_mail(char *to, char *subject, char *message, char *headers);