pike.git / lib / modules / Sql.pmod / pgsql.pike

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:589:    }   }      private inline mixed callout(function(mixed ...:void) f,    float|int delay,mixed ... args) {    return .pgsql_util.local_backend->call_out(f,delay,@args);   }      final void _processloop(.pgsql_util.conxion ci) {    int terminating=0; +  .pgsql_util.conxiin cr=ci->i;    int|.pgsql_util.sql_result portal;    mixed err;    {    Stdio.Buffer plugbuffer=Stdio.Buffer()->add_int32(PG_PROTOCOL(3,0));    if(user)    plugbuffer->add("user\0")->add(user)->add_int8(0);    if(database)    plugbuffer->add("database\0")->add(database)->add_int8(0);    _options.reconnect=undefinedp(_options.reconnect) || _options.reconnect;    foreach(_options-.pgsql_util.censoroptions; string name; mixed value)
pike.git/lib/modules/Sql.pmod/pgsql.pike:633:    };   #endif    for(;;) {    err=catch {   #ifdef PG_DEBUG    if(!portal && datarowdebug) {    PD("%s rows %d\n",datarowdebug,datarowdebugcount);    datarowdebug=0; datarowdebugcount=0;    }   #endif -  int msgtype=ci->read_int8(); +  int msgtype=cr->read_int8();    if(!portal) {    portal=qportals->try_read();   #ifdef PG_DEBUG    showportal(msgtype);   #endif    } -  int msglen=ci->read_int32(); +  int msglen=cr->read_int32();    _msgsreceived++;    _bytesreceived+=1+msglen;    int errtype=NOERROR;    PD("%d>",ci->socket->query_fd());    switch(msgtype) {    array(mapping) getcols() { -  int bintext=ci->read_int8(); -  int cols=ci->read_int16(); +  int bintext=cr->read_int8(); +  int cols=cr->read_int16();   #ifdef PG_DEBUG    array a;    msglen-=4+1+2+2*cols;    foreach(a=allocate(cols,([]));;mapping m) -  m.type=ci->read_int16(); +  m.type=cr->read_int16();   #else -  ci->consume(cols<<1); +  cr->consume(cols<<1);   #endif // Discard column info, and make it line oriented    return ({(["type":bintext?BYTEAOID:TEXTOID,"name":"line"])});    };    array(string) reads() {   #ifdef PG_DEBUG    if(msglen<1)    errtype=PROTOCOLERROR;   #endif    array ret=({}),aw=({0});    do { -  string w=ci->read_cstring(); +  string w=cr->read_cstring();    msglen-=sizeof(w)+1; aw[0]=w; ret+=aw;    } while(msglen);    return ret;    };    mapping(string:string) getresponse() {    mapping(string:string) msgresponse=([]);    msglen-=4;    foreach(reads();;string f)    if(sizeof(f))    msgresponse[f[..0]]=f[1..];    PD("%O\n",msgresponse);    return msgresponse;    };    case 'R': {    PD("Authentication ");    string sendpass;    int authtype;    msglen-=4+4; -  switch(authtype=ci->read_int32()) { +  switch(authtype=cr->read_int32()) {    case 0:    PD("Ok\n");    .pgsql_util.local_backend->remove_call_out(reconnect); -  ci->gottimeout=cancelquery; -  ci->timeout=timeout; +  cr->gottimeout=cancelquery; +  cr->timeout=timeout;    reconnectdelay=0;    cancelsecret="";    break;    case 2:    PD("KerberosV5\n");    errtype=PROTOCOLUNSUPPORTED;    break;    case 3:    PD("ClearTextPassword\n");    sendpass=pass;
pike.git/lib/modules/Sql.pmod/pgsql.pike:714:    errtype=PROTOCOLUNSUPPORTED;    break;    case 5:    PD("MD5Password\n");   #ifdef PG_DEBUG    if(msglen<4)    errtype=PROTOCOLERROR;   #endif   #define md5hex(x) String.string2hex(Crypto.MD5.hash(x))    sendpass=md5hex(pass+user); -  sendpass="md5"+md5hex(sendpass+ci->read(msglen)); +  sendpass="md5"+md5hex(sendpass+cr->read(msglen));   #ifdef PG_DEBUG    msglen=0;   #endif    break;    case 6:    PD("SCMCredential\n");    errtype=PROTOCOLUNSUPPORTED;    break;    case 7:    PD("GSS\n");    errtype=PROTOCOLUNSUPPORTED;    break;    case 9:    PD("SSPI\n");    errtype=PROTOCOLUNSUPPORTED;    break;    case 8:    PD("GSSContinue\n");    errtype=PROTOCOLUNSUPPORTED; -  cancelsecret=ci->read(msglen); // Actually SSauthdata +  cancelsecret=cr->read(msglen); // Actually SSauthdata   #ifdef PG_DEBUG    if(msglen<1)    errtype=PROTOCOLERROR;    msglen=0;   #endif    break;    default:    PD("Unknown Authentication Method %c\n",authtype);    errtype=PROTOCOLUNSUPPORTED;    break;
pike.git/lib/modules/Sql.pmod/pgsql.pike:760:    ->add_int8(0)->sendcmd(SENDOUT);    break; // No flushing here, PostgreSQL 9.4 disapproves    default:    case PROTOCOLUNSUPPORTED:    ERROR("Unsupported authenticationmethod %c\n",authtype);    break;    }    break;    }    case 'K': -  msglen-=4+4;backendpid=ci->read_int32(); -  cancelsecret=ci->read(msglen); +  msglen-=4+4;backendpid=cr->read_int32(); +  cancelsecret=cr->read(msglen);   #ifdef PG_DEBUG    PD("BackendKeyData %O\n",cancelsecret);    msglen=0;   #endif    break;    case 'S': {    PD("ParameterStatus ");    msglen-=4;    array(string) ts=reads();   #ifdef PG_DEBUG
pike.git/lib/modules/Sql.pmod/pgsql.pike:789:   #endif    break;    }    case '3':   #ifdef PG_DEBUG    PD("CloseComplete\n");    msglen-=4;   #endif    break;    case 'Z': -  backendstatus=ci->read_int8(); +  backendstatus=cr->read_int8();   #ifdef PG_DEBUG    msglen-=4+1;    PD("ReadyForQuery %c\n",backendstatus);   #endif    for(;objectp(portal);portal=qportals->read()) {   #ifdef PG_DEBUG    showportal(msgtype);   #endif    portal->_purgeportal();    }
pike.git/lib/modules/Sql.pmod/pgsql.pike:811:    if(objectp(qp) && qp._synctransact && qp._synctransact<=portal) {    PD("Checking portal %O %d<=%d\n",    qp._portalname,qp._synctransact,portal);    qp->_purgeportal();    }    }    portal=0;    _readyforquerycount--;    if(readyforquery_cb)    readyforquery_cb(),readyforquery_cb=0; -  if(waitforauthready) +     destruct(waitforauthready);    break;    case '1':   #ifdef PG_DEBUG    PD("ParseComplete\n");    msglen-=4;   #endif    break;    case 't': {    array a; -  int cols=ci->read_int16(); +  int cols=cr->read_int16();   #ifdef PG_DEBUG    PD("%O ParameterDescription %d values\n",portal._query,cols);    msglen-=4+2+4*cols;   #endif    foreach(a=allocate(cols);int i;) -  a[i]=ci->read_int32(); +  a[i]=cr->read_int32();   #ifdef PG_DEBUGMORE    PD("%O\n",a);   #endif    if(portal._tprepared)    portal._tprepared.datatypeoid=a;    callout(portal->_preparebind,0,a);    break;    }    case 'T': {    array a;   #ifdef PG_DEBUG -  int cols=ci->read_int16(); +  int cols=cr->read_int16();    PD("RowDescription %d columns %O\n",cols,portal._query);    msglen-=4+2;    foreach(a=allocate(cols);int i;)   #else -  foreach(a=allocate(ci->read_int16());int i;) +  foreach(a=allocate(cr->read_int16());int i;)   #endif    { -  string s=ci->read_cstring(); +  string s=cr->read_cstring();    mapping(string:mixed) res=(["name":s]);   #ifdef PG_DEBUG    msglen-=sizeof(s)+1+4+2+4+2+4+2; -  res.tableoid=ci->read_int32()||UNDEFINED; -  res.tablecolattr=ci->read_int16()||UNDEFINED; +  res.tableoid=cr->read_int32()||UNDEFINED; +  res.tablecolattr=cr->read_int16()||UNDEFINED;   #else -  ci->consume(6); +  cr->consume(6);   #endif -  res.type=ci->read_int32(); +  res.type=cr->read_int32();   #ifdef PG_DEBUG    { -  int len=ci->read_sint(2); +  int len=cr->read_sint(2);    res.length=len>=0?len:"variable";    } -  res.atttypmod=ci->read_int32(); +  res.atttypmod=cr->read_int32();    /* formatcode contains just a zero when Bind has not been issued    * yet, but the content is irrelevant because it's determined    * at query time    */ -  res.formatcode=ci->read_int16(); +  res.formatcode=cr->read_int16();   #else -  ci->consume(8); +  cr->consume(8);   #endif    a[i]=res;    }   #ifdef PG_DEBUGMORE    PD("%O\n",a);   #endif    if(portal._forcetext)    portal->_setrowdesc(a); // Do not consume queued portal    else {    portal->_processrowdesc(a);
pike.git/lib/modules/Sql.pmod/pgsql.pike:954:    msglen-=4;   #endif    portal=0;    break;    case 'C': {    msglen-=4;   #ifdef PG_DEBUG    if(msglen<1)    errtype=PROTOCOLERROR;   #endif -  string s=ci->read(msglen-1); +  string s=cr->read(msglen-1);    portal->_storetiming();    PD("%O CommandComplete %O\n",portal._portalname,s);   #ifdef PG_DEBUG -  if(ci->read_int8()) +  if(cr->read_int8())    errtype=PROTOCOLERROR;    msglen=0;   #else -  ci->consume(1); +  cr->consume(1);   #endif    portal->_releasesession(s);    portal=0;    break;    }    case 'I':   #ifdef PG_DEBUG    PD("EmptyQueryResponse %O\n",portal._portalname);    msglen-=4;   #endif
pike.git/lib/modules/Sql.pmod/pgsql.pike:984:    portal=0;    break;    case 'd':    PD("%O CopyData\n",portal._portalname);    portal->_storetiming();    msglen-=4;   #ifdef PG_DEBUG    if(msglen<0)    errtype=PROTOCOLERROR;   #endif -  portal->_processdataready(({ci->read(msglen)}),msglen); +  portal->_processdataready(({cr->read(msglen)}),msglen);   #ifdef PG_DEBUG    msglen=0;   #endif    break;    case 'G':    portal->_setrowdesc(getcols());    PD("%O CopyInResponse\n",portal._portalname);    portal._state=COPYINPROGRESS;    break;    case 'c':
pike.git/lib/modules/Sql.pmod/pgsql.pike:1064:    lastmessage=({});    }    warningscollected++;    lastmessage=({sprintf("%s %s: %s",    msgresponse.S,msgresponse.C,msgresponse.M)});    break;    }    case 'A': {    PD("NotificationResponse\n");    msglen-=4+4; -  int pid=ci->read_int32(); +  int pid=cr->read_int32();    string condition,extrainfo=UNDEFINED;    {    array(string) ts=reads();    switch(sizeof(ts)) {   #if PG_DEBUG    case 0:    errtype=PROTOCOLERROR;    break;    default:    errtype=PROTOCOLERROR;
pike.git/lib/modules/Sql.pmod/pgsql.pike:1090:    }    }    PD("%d %s\n%s\n",pid,condition,extrainfo);    runcallback(pid,condition,extrainfo);    break;    }    default:    if(msgtype!=-1) {    string s;    PD("Unknown message received %c\n",msgtype); -  s=ci->read(msglen-=4);PD("%O\n",s); +  s=cr->read(msglen-=4);PD("%O\n",s);   #ifdef PG_DEBUG    msglen=0;   #endif    errtype=PROTOCOLUNSUPPORTED;    } else {    lastmessage+=({    sprintf("Connection lost to database %s@%s:%d/%s %d\n",    user,_host,_port,database,backendpid)});    if(!waitforauthready)    throw(0);
pike.git/lib/modules/Sql.pmod/pgsql.pike:1155:    _delayederror=err;    for(;objectp(portal);portal=qportals->read())    if(objectp(portal)) {   #ifdef PG_DEBUG    showportal(0);   #endif    portal->_purgeportal();    }    if(!ci->close() && !terminating && _options.reconnect)    _connectfail(); -  else if(waitforauthready) +  else    destruct(waitforauthready);    if(err && !stringp(err))    throw(err);   }      //! Closes the connection to the database, any running queries are   //! terminated instantly.   //!   //! @note   //! This function is PostgreSQL-specific, and thus it is not available   //! through the generic SQL-interface.   void close() {    catch(cancelquery());    catch(c->sendterminate());    c=0; -  if(waitforauthready) +     destruct(waitforauthready);   }      protected void destroy() {    catch(close());    .pgsql_util.unregister_backend();   }      void _connectfail(void|mixed err) {    PD("Connect failed %O reconnectdelay %d\n",err,reconnectdelay); -  catch { -  if(waitforauthready) +     destruct(waitforauthready); -  }; +     if(!err || reconnectdelay) {    int tdelay;    switch(tdelay=reconnectdelay) {    case 0:    reconnectdelay=RECONNECTDELAY;    break;    default:    if(err)    _delayederror=err;    if(_options.reconnect!=-1)