ocdrno.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
  2. See the COPYRIGHT file for more information. */
  3. #include "config.h"
  4. #include "oc.h"
  5. #include "ocinternal.h"
  6. #include "ocdebug.h"
  7. /*
  8. This file exports procedures
  9. that access the internals of
  10. oc. They are intended to be called
  11. by the drno code to avoid at least
  12. the appearance of breaking the oc
  13. encapsulation.
  14. */
  15. #if 0
  16. OCerror
  17. oc_svcerrordata(OCconnection conn, char** codep, char** msgp, long* httpp)
  18. {
  19. OCstate* state = (OCstate*)conn;
  20. if(codep) *codep = state->error.code;
  21. if(msgp) *msgp = state->error.message;
  22. if(httpp) *httpp = state->error.httpcode;
  23. return OC_NOERR;
  24. }
  25. /* DRNO need to explicitly get and walk string values*/
  26. int
  27. oc_stringcontent(OCstate* state, OCcontent* content, char** stringp, size_t* slenp)
  28. {
  29. int stat = OC_NOERR;
  30. XDR* xdrs;
  31. unsigned int slen;
  32. char* stringmemory;
  33. if(state == NULL || content == NULL) return OCTHROW(OC_EINVAL);
  34. if(content->node->octype != OC_Primitive) return OCTHROW(OC_EINVAL);
  35. if(content->node->etype != OC_String
  36. && content->node->etype != OC_URL) return OCTHROW(OC_EINVAL);
  37. xdrs = state->dap.xdrs;
  38. if(xdrs == NULL) return OCTHROW(OC_EXDR);
  39. if(oc_contentmode(state,content) != Datamode) return OCTHROW(OC_EINVAL);
  40. /* We are at a single instance of a string data type*/
  41. if(!xdr_setpos(xdrs,content->xdroffset)) return xdrerror();
  42. if(!xdr_u_int(xdrs,&slen)) return xdrerror();
  43. stringmemory = (char*)ocmalloc(slen+1);
  44. MEMCHECK(stringmemory,OC_ENOMEM);
  45. if(!xdr_opaque(xdrs,stringmemory,slen)) return xdrerror();
  46. stringmemory[slen] = '\0';
  47. /* restore location*/
  48. if(!xdr_setpos(xdrs,content->xdroffset)) return xdrerror();
  49. if(stringp != NULL) *stringp = stringmemory;
  50. if(slenp != NULL) *slenp = slen;
  51. return OCTHROW(stat);
  52. }
  53. #endif