irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

printMS.cpp
Go to the documentation of this file.
1 
6 
8 //#include "reGlobalsExtern.hpp"
10 #include "apiHeaderAll.h"
11 #include "rsApiHandler.hpp"
12 //#include "reFuncDefs.hpp"
13 #include "irods_re_structs.hpp"
14 
15 #if defined(_LP64) || defined(__LP64__)
16 #define CAST_PTR_INT (long int)
17 #else
18 #define CAST_PTR_INT (uint)
19 #endif
20 
58 int writeLine( msParam_t* where, msParam_t* inString, ruleExecInfo_t *rei ) {
59  int i;
60  char tmp[3];
61  char *ptr;
62  char *writeId = ( char * ) where->inOutStruct;
63 
64  if ( writeId != NULL && strcmp( writeId, "serverLog" ) == 0 &&
65  inString->inOutStruct != NULL ) {
66  rodsLog( LOG_NOTICE, "writeLine: inString = %s\n", inString->inOutStruct );
67  return 0;
68  }
69 
70  i = writeString( where, inString, rei );
71  if ( i < 0 ) {
72  return i;
73  }
74  ptr = ( char* )inString->inOutStruct;
75  sprintf( tmp, "%s\n", "" );
76  inString->inOutStruct = tmp;
77  i = writeString( where, inString, rei );
78  inString->inOutStruct = ptr;
79  return i;
80 
81 }
82 
113 int writePosInt( msParam_t* where, msParam_t* inInt, ruleExecInfo_t *rei ) {
114  char *writeId;
115  char writeStr[LONG_NAME_LEN];
116  int status;
117 
118  if ( where->inOutStruct != NULL ) {
119  writeId = ( char* )where->inOutStruct;
120  }
121  else {
122  writeId = where->label;
123  }
124 
125  if ( inInt->inOutStruct != NULL ) {
126  sprintf( writeStr, "%d", parseMspForPosInt( inInt ) );
127  }
128  else {
129  snprintf( writeStr, LONG_NAME_LEN, "%s", inInt->label );
130  }
131 
132  status = _writeString( writeId, writeStr, rei );
133 
134  return status;
135 }
136 
137 
168 int writeBytesBuf( msParam_t* where, msParam_t* inBuf, ruleExecInfo_t *rei ) {
169  char *writeId;
170  char *writeStr;
171  int status;
172 
173  if ( where->inOutStruct != NULL ) {
174  writeId = ( char* )where->inOutStruct;
175  }
176  else {
177  writeId = where->label;
178  }
179 
180  if ( inBuf->inpOutBuf ) {
181  /* Buffer might no be null-terminated */
182  writeStr = ( char* )malloc( inBuf->inpOutBuf->len + 1 );
183  strncpy( writeStr, ( char* )inBuf->inpOutBuf->buf, inBuf->inpOutBuf->len );
184  writeStr[inBuf->inpOutBuf->len] = '\0';
185  }
186  else {
187  writeStr = strdup( inBuf->label );
188  }
189 
190  status = _writeString( writeId, writeStr, rei );
191 
192  if ( writeStr != NULL ) {
193  free( writeStr );
194  }
195 
196  return status;
197 }
198 
230 int writeKeyValPairs( msParam_t *where, msParam_t *inKVPair, msParam_t *separator, ruleExecInfo_t *rei ) {
231  keyValPair_t *KVPairs;
232  char *writeId;
233  char *writeStr;
234  char *sepStr;
235  int i;
236  size_t size;
237 
238 
239  RE_TEST_MACRO( " Calling writeKeyValPairs" )
240 
241 
242  /* sanity checks */
243  if ( !rei ) {
244  rodsLog( LOG_ERROR, "writeKeyValPairs: input rei is NULL." );
246  }
247 
248  if ( !where ) {
249  rodsLog( LOG_ERROR, "writeKeyValPairs: No destination provided for writing." );
250  return USER__NULL_INPUT_ERR;
251  }
252 
253  /* empty? */
254  if ( !inKVPair || !inKVPair->inOutStruct ) {
255  return 0;
256  }
257 
258  /* check for proper input type and get keyValPair input */
259  if ( inKVPair->type && strcmp( inKVPair->type, KeyValPair_MS_T ) ) {
260  rodsLog( LOG_ERROR, "writeKeyValPairs: input parameter is not of KeyValPair_MS_T type." );
261  return USER_PARAM_TYPE_ERR;
262  }
263  KVPairs = ( keyValPair_t * )inKVPair->inOutStruct;
264 
265 
266  /* where are we writing to? */
267  if ( where->inOutStruct != NULL ) {
268  writeId = ( char* )where->inOutStruct;
269  }
270  else {
271  writeId = where->label;
272  }
273 
274 
275  /* get separator string or use default */
276  if ( ( sepStr = parseMspForStr( separator ) ) == NULL ) {
277  sepStr = "\t|\t";
278  }
279 
280 
281  /* find out how much memory is needed for writeStr */
282  size = 0;
283  for ( i = 0; i < KVPairs->len; i++ ) {
284  size += strlen( KVPairs->keyWord[i] ) + strlen( sepStr ) + strlen( KVPairs->value[i] ) + strlen( "\n" );
285  }
286 
287  /* allocate memory for writeStr and pad with null chars */
288  writeStr = ( char * )malloc( size + MAX_COND_LEN );
289  memset( writeStr, '\0', size + MAX_COND_LEN );
290 
291 
292  /* print each key-value pair to writeStr */
293  for ( i = 0; i < KVPairs->len; i++ ) {
294  strcat( writeStr, KVPairs->keyWord[i] );
295  strcat( writeStr, sepStr );
296  strcat( writeStr, KVPairs->value[i] );
297  strcat( writeStr, "\n" );
298  }
299 
300 
301  /* call _writeString() routine */
302  rei->status = _writeString( writeId, writeStr, rei );
303 
304 
305  /* free writeStr since its content has been copied somewhere else */
306  if ( writeStr != NULL ) {
307  free( writeStr );
308  }
309 
310  return rei->status;
311 }
312 
313 
314 
349 int _writeXMsg( int streamId, char *hdr, char *msg );
350 
351 int
352 writeXMsg( msParam_t* inStreamId, msParam_t *inHdr, msParam_t *inMsg, ruleExecInfo_t *rei ) {
353  int i;
354  int streamId;
355  xmsgTicketInfo_t *xmsgTicketInfo;
356 
357  RE_TEST_MACRO( " Calling writeXMsg" )
358 
359  if ( !strcmp( inStreamId->type, XmsgTicketInfo_MS_T ) ) {
360  xmsgTicketInfo = ( xmsgTicketInfo_t * ) inStreamId->inOutStruct;
361  streamId = ( int ) xmsgTicketInfo->rcvTicket;
362  }
363  else if ( !strcmp( inStreamId->type, STR_MS_T ) ) {
364  streamId = ( int ) atoi( ( char* )inStreamId->inOutStruct );
365  }
366  else {
367  streamId = CAST_PTR_INT inStreamId->inOutStruct;
368  }
369 
370  i = _writeXMsg( streamId, ( char* )inHdr->inOutStruct, ( char* )inMsg->inOutStruct );
371  return i;
372 }
373 
417 int _readXMsg( int streamId, char *condRead, int *msgNum, int *seqNum, char **hdr, char **msg, char **user, char **addr );
418 int
419 readXMsg( msParam_t* inStreamId, msParam_t *inCondRead,
420  msParam_t *outMsgNum, msParam_t *outSeqNum,
421  msParam_t *outHdr, msParam_t *outMsg,
422  msParam_t *outUser, msParam_t *outAddr, ruleExecInfo_t *rei ) {
423  int i;
424  int sNum = 0;
425  int mNum = 0;
426  char *hdr = NULL;
427  char *msg = NULL;
428  char *user = NULL;
429  char *addr = NULL;
430  int streamId;
431  xmsgTicketInfo_t *xmsgTicketInfo;
432  char *condRead = NULL;
433  RE_TEST_MACRO( " Calling readXMsg" );
434 
435  if ( !strcmp( inStreamId->type, XmsgTicketInfo_MS_T ) ) {
436  xmsgTicketInfo = ( xmsgTicketInfo_t * ) inStreamId->inOutStruct;
437  streamId = xmsgTicketInfo->rcvTicket;
438  }
439  else if ( !strcmp( inStreamId->type, STR_MS_T ) ) {
440  streamId = ( int ) atoi( ( char* )inStreamId->inOutStruct );
441  }
442  else {
443  streamId = CAST_PTR_INT inStreamId->inOutStruct;
444  }
445  condRead = ( char * ) inCondRead->inOutStruct;
446  i = _readXMsg( streamId, condRead, &mNum, &sNum, &hdr, &msg, &user, &addr );
447  if ( i >= 0 ) {
448  outHdr->inOutStruct = ( void * ) hdr;
449  outHdr->type = strdup( STR_MS_T );
450  outMsg->inOutStruct = ( void * ) msg;
451  outMsg->type = strdup( STR_MS_T );
452  fillIntInMsParam( outMsgNum, mNum );
453  fillIntInMsParam( outSeqNum, sNum );
454  outUser->inOutStruct = ( void * ) user;
455  outUser->type = strdup( STR_MS_T );
456  outAddr->inOutStruct = ( void * ) addr;
457  outAddr->type = strdup( STR_MS_T );
458 
459  }
460  return i;
461 }
462 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
BytesBuf::buf
void * buf
Definition: rodsDef.h:199
_writeString
int _writeString(char *writeId, char *writeStr, ruleExecInfo_t *rei)
Definition: irods_re_structs.cpp:278
RuleExecInfo::status
int status
Definition: irods_re_structs.hpp:19
parseMspForStr
char * parseMspForStr(msParam_t *inpParam)
Definition: msParam.cpp:893
LONG_NAME_LEN
#define LONG_NAME_LEN
Definition: rodsDef.h:57
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
MsParam::type
char * type
Definition: msParam.h:78
_readXMsg
int _readXMsg(int streamId, char *condRead, int *msgNum, int *seqNum, char **hdr, char **msg, char **user, char **addr)
Definition: xmsgMS.cpp:532
STR_MS_T
#define STR_MS_T
Definition: msParam.h:21
BytesBuf::len
int len
Definition: rodsDef.h:198
KeyValPair::value
char ** value
Definition: objInfo.h:123
writeBytesBuf
int writeBytesBuf(msParam_t *where, msParam_t *inBuf, ruleExecInfo_t *rei)
Definition: printMS.cpp:168
writeLine
int writeLine(msParam_t *where, msParam_t *inString, ruleExecInfo_t *rei)
Definition: printMS.cpp:58
writeKeyValPairs
int writeKeyValPairs(msParam_t *where, msParam_t *inKVPair, msParam_t *separator, ruleExecInfo_t *rei)
Definition: printMS.cpp:230
KeyValPair::keyWord
char ** keyWord
Definition: objInfo.h:122
CAST_PTR_INT
#define CAST_PTR_INT
Definition: printMS.cpp:18
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
MsParam
Definition: msParam.h:76
writePosInt
int writePosInt(msParam_t *where, msParam_t *inInt, ruleExecInfo_t *rei)
Definition: printMS.cpp:113
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
MsParam::inpOutBuf
bytesBuf_t * inpOutBuf
Definition: msParam.h:81
int
typedef int((*funcPtr)())
writeString
int writeString(msParam_t *where, msParam_t *inString, ruleExecInfo_t *rei)
Definition: irods_re_structs.cpp:311
writeXMsg
int writeXMsg(msParam_t *inStreamId, msParam_t *inHdr, msParam_t *inMsg, ruleExecInfo_t *rei)
Definition: printMS.cpp:352
MsParam::label
char * label
Definition: msParam.h:77
USER_PARAM_TYPE_ERR
@ USER_PARAM_TYPE_ERR
Definition: rodsErrorTable.h:254
XmsgTicketInfo
Definition: rodsXmsg.h:23
XmsgTicketInfo::rcvTicket
uint rcvTicket
Definition: rodsXmsg.h:25
apiHeaderAll.h
_writeXMsg
int _writeXMsg(int streamId, char *hdr, char *msg)
Definition: xmsgMS.cpp:479
KeyValPair_MS_T
#define KeyValPair_MS_T
Definition: msParam.h:37
RuleExecInfo
Definition: irods_re_structs.hpp:18
MAX_COND_LEN
#define MAX_COND_LEN
Definition: reDefines.h:17
irods_re_structs.hpp
XmsgTicketInfo_MS_T
#define XmsgTicketInfo_MS_T
Definition: msParam.h:48
RE_TEST_MACRO
#define RE_TEST_MACRO(msg)
Definition: reDefines.h:58
KeyValPair::len
int len
Definition: objInfo.h:121
parseMspForPosInt
int parseMspForPosInt(msParam_t *inpParam)
Definition: msParam.cpp:861
readXMsg
int readXMsg(msParam_t *inStreamId, msParam_t *inCondRead, msParam_t *outMsgNum, msParam_t *outSeqNum, msParam_t *outHdr, msParam_t *outMsg, msParam_t *outUser, msParam_t *outAddr, ruleExecInfo_t *rei)
Definition: printMS.cpp:419
icatHighLevelRoutines.hpp
fillIntInMsParam
void fillIntInMsParam(msParam_t *msParam, const int myInt)
Definition: msParam.cpp:242
size
long long size
Definition: filesystem.cpp:102
MsParam::inOutStruct
void * inOutStruct
Definition: msParam.h:80
rsApiHandler.hpp
KeyValPair
Definition: objInfo.h:120
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247