35
35
#include <pthread.h>
37
#ifdef LARGE_VOL_SUPPORT
40
#include <curl/curl.h> // new
41
#include <time.h> // new
42
#include <sys/time.h> // new
43
#include <setjmp.h> // new
45
struct _CMCIConnectionFT; // new
46
typedef struct _CMCIConnectionFT CMCIConnectionFT; // new
48
char * getNextSection(struct _CMCIConnection * ) ;
49
int checkTag(char * , int ) ;
52
#include "utilStringBuffer.h" // new
53
#include "cimXmlParser.h" // new
54
#include "native.h" // new
55
#include "esinfo.h" // new
56
#include "conn.h" // new
61
* response data helper functions.
63
inline char * CURPTR (enumScanInfo * esi ){
64
return(((char*)(esi->base)) + (esi->curoff)) ;
66
inline char * SSECPTR (enumScanInfo * esi ){
67
return(((char*)(esi->base)) + (esi->ssecoff)) ;
69
inline char * LASTPTR (enumScanInfo * esi ){
70
return(((char*)(esi->base)) + (esi->eodoff)) ;
72
inline void INCOFF (enumScanInfo * esi ){
76
int sfccFreeSection(ParserControl * );
77
void * enumScanThrd(struct native_enum *);
78
int sfccLex(parseUnion * , ParserControl * );
79
char * getNextSection(struct _CMCIConnection * );
80
int checkTag(char * , int );
82
#endif /* endif LARGE_VOL_SUPPORT */
84
37
static int attrsOk(XmlBuffer * xb, const XmlElement * e, XmlAttr * r,
85
38
const char *tag, int etag);
86
39
static char *getValue(XmlBuffer * xb, const char *v);
1489
#if LARGE_VOL_SUPPORT
1491
/* **************************************************************************/
1492
/* **************************************************************************/
1493
/* **************************************************************************/
1494
/* **************************************************************************/
1495
/* **************************************************************************/
1496
/* **************************************************************************/
1497
/* **************************************************************************/
1498
int sfccFreeSection(ParserControl * parm)
1500
if(parm->econ->asynRCntl.escanInfo.section){
1501
free(parm->econ->asynRCntl.escanInfo.section) ;
1502
parm->econ->asynRCntl.escanInfo.section = NULL ;
1505
#define TIMEDELAY 10
1506
void * enumScanThrd(struct native_enum *NatEnum)
1508
CMCIConnection * con = NatEnum->econ ; /* enumeration */
1509
CMPIObjectPath * cop = NatEnum->ecop ; /* enumeration */
1511
struct timespec tp ;
1514
ParserControl control;
1515
struct native_enum *local_enmp ;
1517
memset(&control,0,sizeof(control));
1520
* get the data array and save a copy of address in enumeration
1523
XmlBuffer *xmb = newXmlBuffer(NULL);
1525
control.respHdr.xmlBuffer = xmb;
1527
control.respHdr.rvArray=newCMPIArray(0,0,NULL);
1529
local_enmp = con->asynRCntl.enmp ;
1531
local_enmp->data = control.respHdr.rvArray ;
1533
control.requestObjectPath = cop;
1535
control.heap = parser_heap_init();
1537
control.econ = con ;
1539
if(rc = setjmp(save_env)) {
1540
printf(" we had a timeout , we are going to exit from here \n") ;
1541
con->asynRCntl.escanInfo.parsestate = PARSTATE_SERVER_TIMEOUT ;
1542
con->asynRCntl.xfer_state = XFER_ERROR ;
1547
* wait for first data block received or xfer complete
1548
* we need to have some data before starting
1550
while((con->asynRCntl.xfer_state != XFER_DATA_RECVD )&&
1551
(con->asynRCntl.xfer_state != XFER_COMPLETE)){
1555
control.respHdr.rc = startParsing(&control);
1558
* releaseXmlBuffer free's that last con->asynRCntl.escanInfo.section
1559
* we clear out that pointer just to be safe
1561
releaseXmlBuffer(xmb);
1563
con->asynRCntl.escanInfo.section = 0 ;
1565
parser_heap_term(control.heap);
1567
con->asynRCntl.escanInfo.parsestate = PARSTATE_COMPLETE ;
1571
int sfccLex(parseUnion * lvalp, ParserControl * parm)
1581
if(parm->econ->asynRCntl.escanInfo.getnew == 1 ){
1583
nextSection = getNextSection(parm->econ) ;
1584
if(nextSection != NULL) {
1585
parm->xmb->base = nextSection ;
1586
parm->xmb->cur = nextSection ;
1587
parm->xmb->last = nextSection + (parm->econ->asynRCntl.escanInfo.sectlen) ;
1590
printf(" sfccLex --- section is NULL !!!!!!!!!!!!!!!!! \n") ;
1596
next = nextTag(parm->xmb);
1600
// fprintf(stderr,"--- token: %.32s\n",next); //usefull for debugging
1601
if (parm->xmb->eTagFound) {
1602
parm->xmb->eTagFound = 0;
1603
return parm->xmb->etag;
1607
for (i = 0; i < TAGS_NITEMS; i++) {
1608
if (nextEquals(next + 1, tags[i].tag, tags[i].tagLen) == 1) {
1610
return tags[i].etag;
1616
if (strncmp(parm->xmb->cur, "<!--", 4) == 0) {
1617
parm->xmb->cur = strstr(parm->xmb->cur, "-->") + 3;
1620
if (strncmp(parm->xmb->cur, "<EC>", 4) == 0) {
1621
parm->econ->asynRCntl.escanInfo.getnew = 1 ;
1622
parm->econ->asynRCntl.escanInfo.parsestate = PARSTATE_STARTED ;
1625
for (i = 0; i < TAGS_NITEMS; i++) {
1626
if (nextEquals(next, tags[i].tag, tags[i].tagLen) == 1) {
1627
// printf("+++ %d\n",i);
1628
rc=tags[i].process(lvalp, parm);
1638
char * getNextSection(struct _CMCIConnection * con)
1641
char * workptr = NULL;
1642
char * curptr = NULL;
1649
* free that old buffer
1652
if(con->asynRCntl.escanInfo.section != NULL) {
1653
free(con->asynRCntl.escanInfo.section);
1654
con->asynRCntl.escanInfo.section = NULL ;
1657
if((retcode = pthread_mutex_lock(&(con->asynRCntl.escanlock))) != 0){
1658
printf(" getNextSection pthread lock return code %d\n",retcode) ;
1662
* If we have no more new data from the server , we
1663
* unlock and sleep then check till we see that we have
1667
while(con->asynRCntl.escanInfo.prevtotl == con->asynRCntl.escanInfo.recdtotl){
1668
if((retcode = pthread_mutex_unlock(&(con->asynRCntl.escanlock))) != 0){
1669
printf(" getNextSection pthread lock return code %d\n",retcode) ;
1671
/* *******************************************
1672
* *******************************************
1673
* timeout toval keeps us from hanging forever
1674
* *******************************************
1675
* *******************************************
1681
longjmp (save_env, 1);
1683
if(con->asynRCntl.escanInfo.prevtotl != con->asynRCntl.escanInfo.recdtotl){
1685
* we got more data , exit this loop
1687
if((retcode = pthread_mutex_lock(&(con->asynRCntl.escanlock))) != 0){
1688
printf(" getNextSection pthread lock return code %d\n",retcode) ;
1694
if((con->asynRCntl.xfer_state == XFER_DATA_RECVD) ||
1695
(con->asynRCntl.xfer_state == XFER_COMPLETE) ) {
1697
workptr = LASTPTR(&(con->asynRCntl.escanInfo)) ;
1698
curptr = CURPTR(&(con->asynRCntl.escanInfo));
1700
con->asynRCntl.escanInfo.ssecoff = con->asynRCntl.escanInfo.curoff ;
1703
while(workptr > curptr) {
1704
if(*workptr == '>'){
1705
tagval = checkTag(workptr , con->asynRCntl.eMethodType) ;
1707
con->asynRCntl.escanInfo.curoff = con->asynRCntl.escanInfo.curoff + (workptr - curptr) + 1 ;
1708
xmlblen = ((workptr - curptr) + 5) ;
1710
xmlb = malloc(xmlblen + 64) ;
1711
con->asynRCntl.escanInfo.section = xmlb ;
1713
con->asynRCntl.escanInfo.sectlen = xmlblen + 5 ;
1714
memset(xmlb , 0x0cc , xmlblen + 5) ;
1717
memcpy(xmlb , SSECPTR(&con->asynRCntl.escanInfo) , xmlblen) ;
1718
strcpy((xmlb+(xmlblen - 4)) , "<EC>") ;
1719
con->asynRCntl.escanInfo.getnew = 0 ;
1722
/* getNextSection xmlb is NULL !!! This is bad */
1725
con->asynRCntl.escanInfo.prevtotl = con->asynRCntl.escanInfo.recdtotl ;
1727
if((retcode = pthread_mutex_unlock(&(con->asynRCntl.escanlock))) != 0){
1728
printf(" getNextSection pthread lock return code %d\n",retcode) ;
1733
* backup before this tag
1735
workptr = workptr - tagval ;
1736
if(workptr <= curptr){
1737
if (con->asynRCntl.escanInfo.prevtotl != con->asynRCntl.escanInfo.recdtotl){
1738
pthread_mutex_unlock(&(con->asynRCntl.escanlock));
1742
longjmp (save_env, 2);
1743
pthread_mutex_lock(&(con->asynRCntl.escanlock));
1744
workptr = LASTPTR(&(con->asynRCntl.escanInfo)) ;
1745
curptr = CURPTR(&(con->asynRCntl.escanInfo));
1752
if(workptr <= curptr){
1753
if (con->asynRCntl.escanInfo.prevtotl != con->asynRCntl.escanInfo.recdtotl){
1754
workptr = LASTPTR(&(con->asynRCntl.escanInfo)) ;
1755
curptr = CURPTR(&(con->asynRCntl.escanInfo));
1762
if((retcode = pthread_mutex_unlock(&(con->asynRCntl.escanlock))) != 0){
1763
printf(" getNextSection pthread unlock return code %d\n",retcode) ;
1768
* check to see if the ending tag is at a
1769
* place in the data that we can use to
1770
* start parsing. The parsing needs to be
1771
* given certain chunks of the data based on
1772
* the request we are processing.
1773
* If we see </CIM> thats good , we are
1774
* at the end of the data.
1775
* return 0 if ending tag is OK
1776
* return >0 if ending tag is not OK
1778
* VALUE.NAMEDINSTANCE
1783
int checkTag(char * wrkptr , int methodtype ) {
1784
char * workptr = wrkptr ;
1788
memset(&temptag[0] , 00 , 119) ;
1792
while(*workptr != '<'){
1798
if (strncmp(workptr , "</CIM>", 6) == 0) {
1802
switch(methodtype) {
1803
case ENUMERATEINSTANCES:
1804
if (strncmp(workptr , "</VALUE.NAMEDINSTANCE>", 22) == 0) {
1808
case ENUMERATEINSTANCENAMES:
1809
if (strncmp(workptr , "</INSTANCENAME>", 15) == 0) {
1813
case ENUMERATECLASSES:
1814
if (strncmp(workptr , "</CLASS>", 8) == 0) {
1818
case ENUMERATECLASSNAMES:
1819
if (strncmp(workptr , "<CLASSNAME ", 11) == 0) {
1826
* return the length of this tag
1828
strncpy(&temptag[0] , workptr , taglength) ;