libxdas_import.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039 #include <xdas.h>
00040 #include <xdasd.h>
00041 #include <xdas_buf.h>
00042 #include <xdas_wire.h>
00043 #include <xdas_util.h>
00044
00045 #include "libxdas_impl.h"
00046
00067 static char * xdas_strstr(const char * sp, const char * ep, const char * ssp)
00068 {
00069 size_t ssplen = strlen(ssp);
00070
00071 ep -= ssplen - 1;
00072 while (sp < ep)
00073 {
00074 if (*sp == *ssp && strncmp(sp, ssp, ssplen) == 0)
00075 return (char *)sp;
00076 sp++;
00077 }
00078 return 0;
00079 }
00080
00098 static int xdas_send_import_record(int * minorp, xdas_session * xs,
00099 const char * recp, const char * ep)
00100 {
00101 xdas_buffer req;
00102 size_t reclen = ep - recp;
00103 size_t reqsz = 5 * sizeof(uint32_t) + reclen;
00104
00105
00106 if ((req = xdas_buffer_realloc(xs->req, reqsz)) == 0)
00107 return (*minorp = OXDAS_MS_OUT_OF_MEMORY), XDAS_S_FAILURE;
00108 req->curpos = req->start;
00109 xs->req = req;
00110
00111
00112 xdas_buffer_put_uint32(req, reqsz);
00113 xdas_buffer_put_uint32(req, XDASD_REQ_EVENT);
00114 xdas_buffer_put_uint32(req, XDASD_EVT_SRQ_SUBMIT);
00115 xdas_buffer_put_uint32(req, 1);
00116 xdas_buffer_put_uint32(req, reclen);
00117 memcpy(req->curpos, recp, reclen);
00118 req->curpos += reclen;
00119
00120
00121 return xdas_req_rsp(minorp, xs);
00122 }
00123
00138 int xdas_internal_import_event_records(int * minor,
00139 xdas_session * xs, xdas_buffer_t bufp, size_t * bufposp)
00140 {
00141 int rv;
00142
00143 char * bp = bufp->value;
00144 char * ep = bp + bufp->length;
00145 char * cp = bp;
00146
00147 while (cp < ep)
00148 {
00149 char * cep;
00150 char * flds[33];
00151
00152 *bufposp = cp - bufp->value;
00153
00154 if (strncmp(cp, "HDR:", 4) != 0
00155 || (cep = xdas_strstr(cp, ep, ":END")) == 0)
00156 return XDAS_S_RECORD_SYNTAX_ERROR;
00157
00158 cep += 4;
00159 if ((rv = xdas_send_import_record(minor, xs, cp, cep)) != 0)
00160 break;
00161
00162 cp = cep;
00163 }
00164 return rv;
00165 }
00166