📄 ospmsgutil.c
字号:
return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgFloatFromElement() - extract float value from an element *-----------------------------------------------------------------------*/int /* returns error code */OSPPMsgFloatFromElement( OSPTXMLELEM *ospvElem, /* input is XML element */ float *ospvNumber /* where to put number */){ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvNumber == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* get the number */ *ospvNumber = (float)OSPM_ATOF(OSPPXMLElemGetValue(ospvElem)); } return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgFloatToElement() - create an XML element from a float * float 1.175494351 E - 38(min) 3.402823466 E + 38 (max) *-----------------------------------------------------------------------*/int /* returns error code */OSPPMsgFloatToElement( float ospvFloat, /* number to serve as data */ const unsigned char *ospvName, /* name of element */ OSPTXMLELEM **ospvElem /* where to put XML element pointer */){ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; char val[41]; /* 39 digits will accomodate 2^128 */ /*!!!PS added 1 */ if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvName == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* start with no element */ *ospvElem = OSPC_OSNULL; /* convert number */ OSPM_SPRINTF(val, "%.4f", ospvFloat); /* create the element */ *ospvElem = OSPPXMLElemNew((const char *)ospvName, val); if (*ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } } return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgCodeFromElement() - extract status code from an element *-----------------------------------------------------------------------*/unsigned /* returns error code */OSPPMsgCodeFromElement( OSPTXMLELEM *ospvElem, /* input is XML element */ unsigned long *ospvNumber /* where to put number */){ return (OSPPMsgNumFromElement(ospvElem, ospvNumber));}/**//*-----------------------------------------------------------------------* * OSPPMsgCodeToElement() - create an XML element from status code *-----------------------------------------------------------------------*/unsigned /* returns error code */OSPPMsgCodeToElement( unsigned long ospvNumber, /* number to serve as data */ const unsigned char *ospvName, /* name of element */ OSPTXMLELEM **ospvElem /* where to put XML element pointer */){ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; char val[4]; /* 39 digits will accomodate 2^128 */ /*!!!PS added 1 */ if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvName == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* start with no element */ *ospvElem = OSPC_OSNULL; /* format the status code with leading zeroes */ sprintf(val,"%03ld",ospvNumber); /* create the element */ *ospvElem = OSPPXMLElemNew((const char *)ospvName, (const char *)val); if (*ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } } return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgTXFromElement() - extract transaction ID value from an element *-----------------------------------------------------------------------*/unsigned /* returns error code */OSPPMsgTXFromElement( OSPTXMLELEM *ospvElem, /* input is XML element */ OSPTTRXID *ospvTX /* where to put transaction ID */){ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; char *cptr = OSPC_OSNULL; unsigned pos; if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvTX == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* check for errors */ if ((cptr = (char *) OSPPXMLElemGetValue(ospvElem)) == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_DATA_BAD_NUMBER; } } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* get the number - must be decimal */ *ospvTX = 0; for (pos = 0; pos < OSPM_STRLEN(cptr); pos++) { *ospvTX *= 10; *ospvTX += cptr[pos]-'0'; } } return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgTXToElement() - create an XML element from a Transaction *-----------------------------------------------------------------------*/unsigned /* returns error code */OSPPMsgTXToElement( OSPTTRXID ospvNumber, /* number to serve as data */ const unsigned char *ospvName, /* name of element */ OSPTXMLELEM **ospvElem /* where to put XML element pointer */){ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; char val[41]; /* 39 digits will accomodate 2^128 */ /*!!!PS added 1 */ char *cptr; if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvName == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* start with no element */ *ospvElem = OSPC_OSNULL; /* * So we don't have to worry about the size of unsigned longs on * the system, we work backwards. */ val[sizeof(val)-1]=0; /* !!!PS Make sure it looks like a string */ cptr = &val[sizeof(val)-2]; do { *cptr-- = (char)('0' + (ospvNumber%10)); ospvNumber = ospvNumber/10; } while ((ospvNumber != 0) && (cptr >= &val[0])); if (ospvNumber != 0) { /* error - we ran out of space before completing the number */ ospvErrCode = OSPC_ERR_DATA_BAD_NUMBER; } else { /* create the element */ *ospvElem = OSPPXMLElemNew((const char *)ospvName, &val[cptr-&val[0]+1]); if (*ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } } } return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgTimeFromElement() - extract time value from an element *-----------------------------------------------------------------------*/#ifdef OSPC_DEBUGunsigned /* returns error code */OSPPMsgTimeFromElement( OSPTXMLELEM *ospvElem, /* input is XML element */ OSPTTIME *ospvTime) /* where to put time */{ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvTime == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { ospvErrCode = OSPPOSTimeStringToCal(OSPPXMLElemGetValue(ospvElem), ospvTime); } return(ospvErrCode);}#endif /* OSPC_DEBUG *//**//*-----------------------------------------------------------------------* * OSPPMsgTimeToElement() - create an XML element from a time value *-----------------------------------------------------------------------*/unsigned /* returns error code */OSPPMsgTimeToElement( OSPTTIME ospvTime, /* number to serve as data */ const unsigned char *ospvName, /* name of element */ OSPTXMLELEM **ospvElem /* where to put XML element pointer */){ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; char tstr[OSPC_TIMESTRINGSIZE]; if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvName == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* start with no element */ *ospvElem = OSPC_OSNULL; ospvErrCode = OSPPOSTimeCalToString(ospvTime, tstr); if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* create the element */ *ospvElem = OSPPXMLElemNew((const char *)ospvName, tstr); if (*ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } } } return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgRoleToElement() - create an XML element from a role value *-----------------------------------------------------------------------*/unsigned /* returns error code */OSPPMsgRoleToElement( unsigned ospvRole, /* number to serve as data */ const unsigned char *ospvName, /* name of element */ OSPTXMLELEM **ospvElem /* where to put XML element pointer */){ unsigned ospvErrCode = OSPC_ERR_NO_ERROR; char rolestr[OSPC_ROLESTRSZ]; OSPM_MEMSET(rolestr, 0, OSPC_ROLESTRSZ); if (ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } if (ospvName == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_INVALID_ARGS; } if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* start with no element */ *ospvElem = OSPC_OSNULL; ospvErrCode = OSPPOSRoleValToString(ospvRole, rolestr); if (ospvErrCode == OSPC_ERR_NO_ERROR) { /* create the element */ *ospvElem = OSPPXMLElemNew((const char *)ospvName, rolestr); if (*ospvElem == OSPC_OSNULL) { ospvErrCode = OSPC_ERR_XML_NO_ELEMENT; } } } return(ospvErrCode);}/**//*-----------------------------------------------------------------------* * OSPPMsgElemIsCritical() - is an element critical *-----------------------------------------------------------------------*/unsigned /* returns non-zero if critical */OSPPMsgElemIsCritical( OSPTXMLELEM *ospvElem /* input is XML element */){ unsigned ospvIsCritical = OSPC_TRUE; OSPTXMLATTR *attr; if (ospvElem != OSPC_OSNULL) { /* look for a critical attribute */ for (attr = (OSPTXMLATTR *)OSPPXMLElemFirstAttr(ospvElem); attr != (OSPTXMLATTR *)OSPC_OSNULL; attr = (OSPTXMLATTR *)OSPPXMLElemNextAttr(ospvElem, attr)) { if (OSPPMsgGetAttrPart(OSPPXMLAttrGetName(attr)) == ospeAttrCritical) { /* we found an critical attribute - is it false? */ if (OSPM_STRCMP(OSPPXMLAttrGetValue(attr), "False") == 0) { /* yes, change our return value */ ospvIsCritical = OSPC_FALSE; /* don't stop now, in case a later version supercedes */ } } } } return(ospvIsCritical);}/**//*-----------------------------------------------------------------------* * OSPPOSRoleValToString() - convert role value to string *-----------------------------------------------------------------------*/intOSPPOSRoleValToString(unsigned ospvRole, char *ospvRolestr){ int errorcode = OSPC_ERR_NO_ERROR; switch(ospvRole) { case OSPC_SOURCE: memcpy(ospvRolestr, "source", strlen("source")); break; case OSPC_DESTINATION: memcpy(ospvRolestr, "destination", strlen("destination")); break; case OSPC_OTHER: memcpy(ospvRolestr, "other", strlen("other")); break; default: errorcode = OSPC_ERR_DATA_INVALID; break; } return errorcode;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -