CAPI replication history

Hello

First message in this forum!

Im doing some developing in Lotus Notes CAPI and have not been able to get the replication history from Notes.

The funny thing is that I have cut a “code snippet” from the CAPI documentation which in turn does not seem to work?

I have googled and searched for a solution to my problem but have not been able to get any information!

Anyway, the code snippet i found in the CAPI doc:

//==========================================

STATUS error = NOERROR; /* error code from API calls */

HANDLE hReplHist;

REPLHIST_SUMMARY ReplHist;

REPLHIST_SUMMARY *pReplHist;

char szTimedate[MAXALPHATIMEDATE+1];

WORD wLen;

DWORD dwNumEntries, i;

char pServerName; / terminating NULL not included */

char szServerName[MAXUSERNAME + 1];

char pFileName; / includes terminating NULL */

char szDirection[10]; /* NEVER, SEND, RECEIVE */

/* Open the database */

/* Get the Replication History Summary */

error = NSFDbGetReplHistorySummary (db_handle, 0, hReplHist, &dwNumEntries);

if (error)

{

NSFDbClose (db_handle);

LAPI_RETURN (ERR(error));

}

/* Obtain a pointer to the first member of the Replication History Summary

array */

pReplHist = OSLock (REPLHIST_SUMMARY, hReplHist);

for (i = 0; i < dwNumEntries; i++)

{

ReplHist = pReplHist[i];

error = ConvertTIMEDATEToText (NULL, NULL, &(ReplHist.ReplicationTime),

                           szTimedate, MAXALPHATIMEDATE, &wLen);

if (error)

{

OSUnlock (hReplHist);

OSMemFree (hReplHist);

NSFDbClose (db_handle);

LAPI_RETURN (ERR(error));

}

szTimedate[wLen] = ‘\0’;

if (ReplHist.Direction == DIRECTION_NEVER)

strcpy (szDirection, "NEVER");

else if (ReplHist.Direction == DIRECTION_SEND)

strcpy (szDirection, "SEND");

else if (ReplHist.Direction == DIRECTION_RECEIVE)

strcpy (szDirection, "RECEIVE");

else

strcpy (szDirection, "");

pServerName = NSFGetSummaryServerNamePtr (pReplHist, i);

strncpy (szServerName, pServerName, ReplHist.ServerNameLength);

szServerName[ReplHist.ServerNameLength] = ‘\0’;

/* FileName will be NULL terminated */

pFileName = NSFGetSummaryFileNamePtr (pReplHist, i);

printf (“%s %s %s (%s)\n”, szTimedate, szServerName, pFileName, szDirection);

}

OSUnlock (hReplHist);

OSMemFree (hReplHist);

//==========================================

::ConvertTIMEDATEToText

The first iteration in the loop seems to work well, I get a valid date which matches the saved date.

::NSFGetSummaryServerNamePtr

If I look at the pReplHist pointer, it has a servernamelength > 0, which should result in a valid servername.

But, I dont get a servername, pServerName is always empty.

::NSFGetSummaryFileNamePtr

Always returns empty!

In the second iteration, I get an unvalid date and the program exits. If i uncomment the errorhandling and iterates over all

dwNumEntries I never get any data which is not junk.

The only data that is valid is the ReplHist.Direction which seems to work fine!

I found 1 post from a user who had the same problems as me, and he never got a solution.

http://www.mydatabasesupport.com/forums/lotus-notes-programmer/159901-pb-nsfdbgetreplhistorysummary.html

Does anyone have a solution?

// David

Subject: CAPI replication history

check this thread:

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/46eba23b498b79a08525719900570617?OpenDocument

Subject: RE: CAPI replication history

Thanks, but already done that!

Dont see any differences between that code and the code snippet from the capi documentation?

// David

Subject: RE: CAPI replication history

well that code worked fine for me and I have made some changes to it in order to trim down what is returnd and to clean it up a bit so prob. any changes you added may be causing your problem.

Subject: RE: CAPI replication history

OkWell, im not exactly using that code…the code im using is from the capi documentation without any changes. The code you are using is notes script or?(I am fairly new to notes!) Anyway, to my understanding, it does the same thing as the “code snippet” i use. Maybee theres something wrong with the notes replications history in my database?

// David

Subject: RE: CAPI replication history

you say you are new to notes, so I assume you haven’t done much Notes C API programming either. In that case I’d like to point out once more: you need to define 1-byte data alignment for your code. All Notes structures use that one; otherwise you’ll get problems similar to what you describe.

Subject: RE: CAPI replication history

Hi!

Yes, im relatively new to notes but have been programming c++ for a couple of years! I have in the last months done some notes capi programming and it mostly functions well.

define 1 byte data alignment!

Ok, so how would you do it?

Exactly what lines should i change to make it work?

Have you tested that code snippet? it is found in the capi documentation!

I havent changed a line in that code, so it is really peculiar that the notes team doesnt tell anything about 1 byte data alignment?

// David

Subject: RE: CAPI replication history

The Lotus documentation isn’t always as clear as it could be. I know you are programming from C/C++, and that Normunds isn’t here to pimp his work, but the data structure alignment descriptions and some of the peculiarities of the Notes C API are very well explained in his excellent book, “LotusScript to Lotus C API Programming Guide”:

http://www.ls2capi.com/

It’s a great companion reference to the Lotus documentation, even if you aren’t using LotusScript.

Subject: RE: CAPI replication history

well they do. And if you haven’t heard about it surely is the cause of the problem. It is explained in C API User Guide:http://www-12.lotus.com/ldd/doc/tools/c/7.0/api70ug.nsf/85255d56004d2bfd85255b1800631684/aa398d10d6e3157385256083006cc8c3?OpenDocument

see section “Data Structure Packing”

Subject: RE: CAPI replication history

Thanks!

Yes, the problem was the “Data Structure Packing”, had to use the compiler setting (/Zp1).

// David

Subject: RE: CAPI replication history

Normunds has almost certainly identified the problem. There is a compiler settings (/Zp1) which must be set because so much of Notes internal workings were created back in an age when space was at a great premium, so all structures are packed on a single byte boundary. If you don’t have that set, things just won’t work.

Subject: CAPI replication history

a bit not clear - how can pServerName be empty - it is a pointer so you must get some value in there. Where it points to is a different issue.

You might try to replace the macro NSFGetSummaryServerNamePtr with a code and see if the way it calculates is the correct one.

I haven’t tried this, but I’d think something like this should do the trick:

pServerName = pReplHist + ReplHist.ServerNameOffset

Subject: RE: CAPI replication history

HelloSorry, pServerName is not empty, it has an adress to something which is empty! There isint anything for the next row, strcpy, to copy.

Tested your solution with this line of code:

cout << (((char FAR *) pReplHist) + pReplHist[i].ServerNameOffset) << endl;

Sorry to say, an empty line this time also?

And as i said in the first post, the first time in the loop, i get a valid date but not the second!

Dont know what to make of this. I get the feeling that either it is something wrong with the notes replication historydb or is it a bug in the capi? I have looked in the replication history and it did look ok with dates, servername etc. Why cant i get the same result programatically?

hmm!

Subject: RE: CAPI replication history

I hope you are using 1-byte alignment?