libxdas_import.c

Go to the documentation of this file.
00001 /*----------------------------------------------------------------------------
00002  * Copyright (c) 2006, Novell, Inc.
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without 
00006  * modification, are permitted provided that the following conditions are 
00007  * met:
00008  * 
00009  *     * Redistributions of source code must retain the above copyright 
00010  *       notice, this list of conditions and the following disclaimer.
00011  *     * Redistributions in binary form must reproduce the above copyright 
00012  *       notice, this list of conditions and the following disclaimer in the 
00013  *       documentation and/or other materials provided with the distribution.
00014  *     * Neither the name of the Novell nor the names of its contributors 
00015  *       may be used to endorse or promote products derived from this 
00016  *       software without specific prior written permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00020  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00021  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00025  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
00026  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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    /* resize request buffer */
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    /* put header and data request fields */
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);  /* import */
00116    xdas_buffer_put_uint32(req, reclen);
00117    memcpy(req->curpos, recp, reclen);
00118    req->curpos += reclen;
00119 
00120    /* Send request, return status. */
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;   /* skip past ":END" */
00159       if ((rv = xdas_send_import_record(minor, xs, cp, cep)) != 0)
00160          break;
00161 
00162       cp = cep;
00163    }
00164    return rv;
00165 }
00166 

Generated on Thu Aug 20 22:33:05 2009 for OpenXDAS by  doxygen 1.5.6