sas             Tue Feb 20 19:04:28 2007 UTC

  Modified files:              (Branch: PHP_4_4)
    /php-src/ext/ircg   ircg.c php_ircg.h 
  Log:
  - sync with current dev
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/ircg/ircg.c?r1=1.137.2.18.4.2&r2=1.137.2.18.4.3&diff_format=u
Index: php-src/ext/ircg/ircg.c
diff -u php-src/ext/ircg/ircg.c:1.137.2.18.4.2 
php-src/ext/ircg/ircg.c:1.137.2.18.4.3
--- php-src/ext/ircg/ircg.c:1.137.2.18.4.2      Mon Jan  1 09:46:43 2007
+++ php-src/ext/ircg/ircg.c     Tue Feb 20 19:04:28 2007
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: ircg.c,v 1.137.2.18.4.2 2007/01/01 09:46:43 sebastian Exp $ */
+/* $Id: ircg.c,v 1.137.2.18.4.3 2007/02/20 19:04:28 sas Exp $ */
 
 /* {{{ includes */
 
@@ -124,6 +124,7 @@
 /* {{{ ircg_functions[] */
 function_entry ircg_functions[] = {
        PHP_FE(ircg_set_on_die, NULL)
+       PHP_FE(ircg_create_file_on_die, NULL)
        PHP_FE(ircg_pconnect, NULL)
        PHP_FE(ircg_set_current, NULL)
        PHP_FE(ircg_set_file, NULL)
@@ -204,6 +205,8 @@
        struct in_addr od_ip;
        short od_port;
 #endif
+
+       char *od_file;
        
        int file_fd;
        
@@ -231,6 +234,7 @@
        P_NICKNAME_JS = 3,
        P_HTML        = 4,
        P_HTML_JS     = 5,
+       P_XML         = 6,
        P_NOAUTO_LINKS = 8, /* Don't automatically convert links */
        P_CONV_BR      = 16,    /* Convert a special character to <br> */
        P_COND_STOP    = 32,    /* If argument != username, stop */
@@ -393,6 +397,7 @@
 static void quit_handler(irconn_t *c, void *dummy)
 {
        php_irconn_t *conn = dummy;
+       int fd;
 
        irc_quit_handlers++;
        if (conn->fd > -1) {
@@ -425,6 +430,14 @@
                free(conn->od_data);
        }
 #endif
+
+       if (conn->od_file) {
+               fd = open(conn->od_file, O_CREAT | O_WRONLY, 0666);
+               if (fd != -1) {
+                       close(fd);
+               }
+               free(conn->od_file);
+       }
        
        free(conn);
 }
@@ -451,6 +464,47 @@
        }
 }
 
+static void ircg_xml_escape(smart_str *input, smart_str *output)
+{
+       unsigned char *p;
+       unsigned char *end;
+       unsigned char c;
+
+       end = input->c + input->len;
+
+       for(p = input->c; p < end; p++) {
+               c = *p;
+
+               if (c >= 0 && c < 32) {
+                       smart_str_appendl_ex(output, "&#", 2, 1);
+                       smart_str_append_long_ex(output, c, 1);
+                       smart_str_appendc_ex(output, ';', 1);
+                       continue;
+               }
+               
+               switch (c) {
+               case '"':
+                       smart_str_appendl_ex(output, "&quot;", 6, 1);
+                       break;
+               case '\'':
+                       smart_str_appendl_ex(output, "&#039;", 6, 1);
+                       break;
+
+               case '<':
+                       smart_str_appendl_ex(output, "&lt;", 4, 1);
+                       break;
+
+               case '>':
+                       smart_str_appendl_ex(output, "&gt;", 4, 1);
+                       break;
+
+               default:
+                       smart_str_appendc_ex(output, c, 1);
+                       break;
+               }
+       }
+}
+
 static const char hextab[] = "0123456789abcdef";
 
 #define NICKNAME_ESC_CHAR '|'
@@ -621,6 +675,7 @@
                case '4': mode |= P_CONV_BR; goto next;
                case '5': mode |= P_COND_STOP; goto next;
                case '6': mode |= P_HTML; goto next;
+               case '7': mode |= P_XML; goto next;
 
                /* associate mode bits with each command where applicable */
                case 'c': NEW_TOKEN(C_CHANNEL, v) = mode; break;
@@ -701,6 +756,10 @@
                        ircg_js_escape(&tmp, result);                   \
                        smart_str_free_ex(&tmp, 1);                             
\
                        break;                                                  
                \
+               case P_XML:                                                     
                \
+                       if (!what) break;                                       
        \
+                       ircg_xml_escape(what, result);                  \
+                       break;                                                  
                \
                case P_HTML:                                                    
        \
                        if (!what) break;                                       
        \
                        if (use_cache) {                                        
        \
@@ -1442,6 +1501,33 @@
 #endif
 /* }}} */
 
+/* {{{ proto bool ircg_create_file_on_die(int connection, string path) 
+   Sets hostaction to be executed when connection dies */
+PHP_FUNCTION(ircg_create_file_on_die)
+{
+       zval **p1, **p2;
+       php_irconn_t *conn;
+       
+       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &p1, &p2) == 
FAILURE)
+               WRONG_PARAM_COUNT;
+
+       convert_to_long_ex(p1);
+
+       conn = lookup_irconn(Z_LVAL_PP(p1));
+
+       if (!conn) RETURN_FALSE;
+       
+       convert_to_string_ex(p2);
+
+       if (Z_STRLEN_PP(p2) > 0) {
+               /* path must be NUL terminated */
+               conn->od_file = strdup(Z_STRVAL_PP(p2));
+       }
+
+       RETURN_TRUE;
+}
+/* }}} */
+
 /* {{{ proto bool ircg_set_on_die(int connection, string host, int port, 
string data) 
    Sets hostaction to be executed when connection dies */
 PHP_FUNCTION(ircg_set_on_die)
@@ -2318,6 +2404,7 @@
 #ifdef IRCG_PENDING_URL
        conn->od_port = 0;
 #endif
+       conn->od_file = NULL;
        conn->fmt_msgs = fmt_msgs;      
        if (irc_connect(username, register_hooks, 
                        conn, server, port, &conn->conn)) {
http://cvs.php.net/viewvc.cgi/php-src/ext/ircg/php_ircg.h?r1=1.20.2.2.4.2&r2=1.20.2.2.4.3&diff_format=u
Index: php-src/ext/ircg/php_ircg.h
diff -u php-src/ext/ircg/php_ircg.h:1.20.2.2.4.2 
php-src/ext/ircg/php_ircg.h:1.20.2.2.4.3
--- php-src/ext/ircg/php_ircg.h:1.20.2.2.4.2    Mon Jan  1 09:46:44 2007
+++ php-src/ext/ircg/php_ircg.h Tue Feb 20 19:04:28 2007
@@ -60,6 +60,7 @@
 PHP_FUNCTION(ircg_names);
 PHP_FUNCTION(ircg_lusers);
 PHP_FUNCTION(ircg_oper);
+PHP_FUNCTION(ircg_create_file_on_die);
 
 PHP_MINIT_FUNCTION(ircg);
 PHP_MSHUTDOWN_FUNCTION(ircg);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to