1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
getreply.cc from librms
Copyright (C) 1999 Patrick Caulfield patrick@tykepenguin.cix.co.uk
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <netdnet/dn.h>
#include <netdnet/dnetdb.h>
#include "connection.h"
#include "protocol.h"
#include "rms.h"
#include "rmsp.h"
int check_status(rms_conn *rc, dap_message *m)
{
if (!rc) return -1;
if (m->get_type() != dap_message::STATUS) return -1;
dap_status_message *sm = (dap_status_message *)m;
// Save this stuff so we can delete the message
int code = sm->get_code() & 0xFF;
char *err = sm->get_message();
delete m;
rc->lasterr = code;
if (code == 0225) return 0; // Success
if (code == 047) return code; // EOF
rc->lasterror = err;
return -1;
}
// Users should not need to call this.
int rms_getreply(RMSHANDLE h, int wait, dap_message **msg)
{
rms_conn *rc = (rms_conn *)h;
dap_connection *conn = (dap_connection *)rc->conn;
*msg = NULL;
if (!wait)
{
int next_msg = dap_message::peek_message_type(*conn);
if (next_msg == dap_message::DATA) return 0;
}
dap_message *m = dap_message::read_message(*conn,true);
if (m)
{
if (m->get_type() == dap_message::STATUS)
return check_status(rc, m);
if (m->get_type() == dap_message::ACK)
{
delete m;
return 0; // OK
}
if (m->get_type() == dap_message::ACCOMP)
{
delete m;
return 0; // OK
}
if (m->get_type() == dap_message::ATTRIB)
{
delete m;
return 0; // OK
}
// Don't know what that was - let the caller deal with it.
*msg = m;
return -2;
}
rc->lasterror = conn->get_error();
return -1;
}
char *rms_lasterror(RMSHANDLE h)
{
rms_conn *rc = (rms_conn *)h;
return rc->lasterror;
}
int rms_lasterrorcode(RMSHANDLE h)
{
rms_conn *rc = (rms_conn *)h;
return rc->lasterr;
}
|