pike.git / lib / modules / Protocols.pmod / LDAP.pmod / protocol.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:1:   #pike __REAL_VERSION__      // LDAP client protocol implementation for Pike.   // - // $Id: protocol.pike,v 1.16 2005/03/11 16:49:57 mast Exp $ + // $Id: protocol.pike,v 1.17 2005/03/29 17:59:31 mast Exp $   //   // Honza Petrous, hop@unibase.cz   //   // ----------------------------------------------------------------------   //   // History:   //   // v1.9 1999-02-19 created separate file   // - improved checking of readed bytes in 'readmsg'   // v1.9.1.1
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:40:    /*private*/ string writebuf=""; // write buffer   // private written; // count of written chars    private function con_ok, con_fail; // async callback functions    object conthread; // thread connection    array extra_args; // not used, yet   // /*private*/ int errno;    int connected = 0;    object low_fd = Stdio.File(); // helper fd    object ldapfd; // helper fd    + static int last_io_time; // Timestamp when I/O on the fd was made last. +     int seterr(int errno) {    // Sets ldap_err* variables and returns errno       //ldap_rem_errstr = errstr;    ldap_errno = errno;    return errno;    }       //!    //! Returns error number of last transaction.
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:65:    //!    //! Returns error description of search result.    //!    //! @seealso    //! @[LDAP.protocol.error_number]    string error_string() { return ldap_errlist[ldap_errno]; }       array error() { return ({error_number(), error_string()}); }       + //! Returns when I/O was made last. Useful to find out whether it's + //! safe to continue using a connection that has been idle for some + //! time. + int get_last_io_time() {return last_io_time;} +     static void read_answer() {    // ----------------------    // Reads LDAP PDU (with defined msgid) from the server       int msglen = 0, ix, ofs;    string s, shlp;       if(sizeof(readbuf) < 2)    readbuf = ldapfd->read(2); // 1. byte = 0x0C, 2. byte = msglen    if (intp(readbuf) || (sizeof(readbuf) < 2)) {
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:130:    seterr (LDAP_SERVER_DOWN);    THROW(({"LDAP: connection closed by server.\n",backtrace()}));    //return -ldap_errno;    return;    }    readbuf += s;    //DWRITE(sprintf("protocol.read_answer: %s\n", .ldap_privates.ldap_der_decode(readbuf)->debug_string()));    DWRITE("protocol.read_answer: ok=1.\n");    ok = 1;    +  last_io_time = time(); +     if(con_ok)    con_ok(this, @extra_args);    }       static int is_whole_pdu() {    // ----------------------    // Check if LDAP PDU is complete in 'readbuf'       int msglen, ix, ofs;    string shlp;
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:171:    ix = (ofs + msglen) - sizeof(readbuf);    if(ix > 0)    return 0; // incomplete PDU       return 1;    }       void create(object fd) {    // -------------------    ldapfd = fd; +  last_io_time = time();    }          string|int do_op(object msgop, object|void controls) {    // ---------------------------    // Make LDAP PDU envelope for 'msgop', send it and read answer ...       object msgval;    object msgid;    int rv = 0, msgnum;
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:212:    if (rv < 2) {    seterr (LDAP_SERVER_DOWN);    THROW(({"LDAP: connection closed by server.\n",backtrace()}));    return -ldap_errno;    }    DWRITE(sprintf("protocol.do_op: write OK [%d bytes].\n",rv));    msgval = 0; msgid = 0;    writebuf= "";    readbuf= ""; // !!! NEni to pozde ?    +  last_io_time = time(); +     //`()();       read_answer();    // now is all in 'readbuf'       return readbuf;       }      /* ------------ legacy support -----------------*/
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:273:    }    }    DWRITE(sprintf("protocol.readmsg: reading %d bytes.\n", msglen));    s = ldapfd->read(msglen);    if (!s | (sizeof(s) < msglen)) {    seterr (LDAP_SERVER_DOWN);    THROW(({"LDAP: connection closed by server.\n",backtrace()}));    return -ldap_errno;    }    retv += s; +  last_io_time = time();    DWRITE(sprintf("protocol.readmsg: %s\n", .ldap_privates.ldap_der_decode(retv)->debug_string()));    return retv;    }       int writemsg(object msgop) {    // Make LDAP PDU envelope for 'msgop' and send it       object msgval;    object msgid;    int rv = 0, msgnum;
pike.git/lib/modules/Protocols.pmod/LDAP.pmod/protocol.pike:306:    // call_out    rv = ldapfd->write(msgval->get_der());    // call_out    if (rv < 2) {    seterr (LDAP_SERVER_DOWN);    THROW(({"LDAP: connection closed by server.\n",backtrace()}));    return -ldap_errno;    }    DWRITE(sprintf("protocol.writemsg: write OK [%d bytes].\n",rv));    msgval = 0; msgid = 0; +  last_io_time = time();    return msgnum;    }      #else   constant this_program_does_not_exist=1;   #endif