X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frmr%2Fcommon%2Fsrc%2Fmbuf_api.c;h=e88ab233436c13ea550a9b240078eb44a464a956;hb=4ac73e3b9c0ff7aef80ad45f1bfead52bb2ffc99;hp=1074e371f12ea568620aa3e415765b83e2e1b697;hpb=a7610c690a3976e296ca768977e38ceb9aafa5ff;p=ric-plt%2Flib%2Frmr.git diff --git a/src/rmr/common/src/mbuf_api.c b/src/rmr/common/src/mbuf_api.c index 1074e37..e88ab23 100644 --- a/src/rmr/common/src/mbuf_api.c +++ b/src/rmr/common/src/mbuf_api.c @@ -188,6 +188,39 @@ extern int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char const* str ) { return RMR_OK; } +/* + Extracts the transaction bytes from the header and places into a + user supplied buffer (dest). The buffer must be at least RMR_MAX_XID + bytes in length as this function will copy the entire field (even if + the sender saved a shorter "string." If the user supplies a nil poniter + as the destination, a buffer is allocated; the caller must free when + finished. The buffer will be exactly RMR_MAX_XID bytes long. + + The return value is a pointer to the buffer that was filled (to + the dest buffer provided, or the buffer we allocated). If there is an + error, a nil pointer is returned, and errno should suggest the root + cause of the issue (invalid message or no memory). +*/ +extern unsigned char* rmr_get_xact( rmr_mbuf_t* mbuf, unsigned char* dest ) { + errno = 0; + + if( mbuf == NULL || mbuf->xaction == NULL ) { + errno = EINVAL; + return NULL; + } + + if( ! dest ) { + if( (dest = (unsigned char *) malloc( sizeof( unsigned char ) * RMR_MAX_XID )) == NULL ) { + errno = ENOMEM; + return NULL; + } + } + + memcpy( dest, mbuf->xaction, RMR_MAX_XID ); + + return dest; +} + /* Extracts the meid (managed equipment) from the header and copies the bytes to the user supplied area. If the user supplied pointer is nil, then @@ -200,6 +233,8 @@ extern int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char const* str ) { extern unsigned char* rmr_get_meid( rmr_mbuf_t* mbuf, unsigned char* dest ) { uta_mhdr_t* hdr; + errno = 0; + if( mbuf == NULL || mbuf->header == NULL ) { errno = EINVAL; return NULL; @@ -213,7 +248,7 @@ extern unsigned char* rmr_get_meid( rmr_mbuf_t* mbuf, unsigned char* dest ) { } hdr = (uta_mhdr_t *) mbuf->header; - memcpy( dest, hdr->meid, RMR_MAX_XID ); + memcpy( dest, hdr->meid, RMR_MAX_MEID ); return dest; }