Summary: Isode provides a number of APIs which allow integrators and product developers to build components that access the Isode Messaging server products or other products supporting the same protocols.
examples/x400_msrcv.c

This is an example program which can receive a message either from a P7 Message Store or directly from the MTA's P3 channel.

/* Copyright (c) 2003-2014, Isode Limited, London, England.
* All rights reserved.
*
* Acquisition and use of this software and related materials for any
* purpose requires a written licence agreement from Isode Limited,
* or a written licence from an organisation licenced by Isode Limited
* to grant such a licence.
*
*/
/*
*
* Simple example program for receiving a message from a store.
*/
#include <stdio.h>
#include <stdlib.h>
#ifndef _WIN32
#include <unistd.h>
#endif
#include <x400_msapi.h>
#include <amhs_att.h>
#include <seclabel_api.h> /* For security labels */
#include "example.h"
#include "ms_example.h"
static char *optstr = "u371m:d:p:w:M:D:P:W:";
static void usage(void);
static int get_msg (
struct X400msSession *sp
);
#ifdef WANT_DL_EXP_HIST
static int do_dl_hist (
struct X400msMessage *mp
);
#endif
static int do_redirection_hist_env (
struct X400msMessage *mp
);
static int do_trace_info (
struct X400msMessage *mp
);
static int do_internal_trace_info (
struct X400msMessage *mp
);
static int do_orig_and_dl (
struct X400msMessage *mp
);
int
main(
int argc,
char **argv)
{
char buffer[BUFSIZ];
char pa[BUFSIZ];
char orn[BUFSIZ];
int status;
int nummsg;
int nummsg_ready;
struct X400msSession *sp;
int contype;
char *def_oraddr;
char *def_dn;
char *def_pa;
/* period to pass into X400msWait() */
int ms_timeout_period = 10;
/* number of timeouts from X400msWait() before exiting */
# define NUM_MSWAIT_TIMEOUTS 10
int max_timeouts = NUM_MSWAIT_TIMEOUTS;
if (get_args(argc, argv, optstr)) {
usage();
exit(-1);
}
printf("Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
contype = ic_fgetc(x400_contype, stdin);
if (contype != 10)
ic_fgetc(x400_contype, stdin);
if ( contype < '0' || '2' < contype )
contype = x400_contype;
else
contype -= '0';
if (contype == 0) {
def_oraddr = x400_ms_user_addr;
def_dn = x400_ms_user_dn;
def_pa = x400_ms_presentation_address;
}
else {
def_oraddr = x400_mta_user_addr;
def_dn = x400_mta_user_dn;
def_pa = x400_mta_presentation_address;
}
printf("Your ORAddress [%s] > ", def_oraddr);
ic_fgets(orn, sizeof orn, stdin);
if (orn[strlen(orn) - 1] == '\n')
orn[strlen(orn) - 1] = '\0';
if (orn[0] == '\0')
strcpy(orn, def_oraddr);
/* Prompt for password; note: reflected. */
printf("Password [%s]: ",
contype == 0 ? x400_p7_password : x400_p3_password);
if (ic_fgets(buffer, sizeof buffer, stdin) == NULL)
exit(1);
if (buffer[strlen(buffer) - 1] == '\n')
buffer[strlen(buffer) - 1] = '\0';
if (buffer[0] == '\0')
strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
printf("Presentation Address [%s] > ", def_pa);
ic_fgets(pa, sizeof pa, stdin);
if (pa[strlen(pa) - 1] == '\n')
pa[strlen(pa) - 1] = '\0';
if (pa[0] == '\0')
strcpy(pa, def_pa);
if (talking_to_marben_ms)
status = X400msOpen(contype, orn, def_dn, buffer, pa, &nummsg, &sp);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error in Open: %s\n", X400msError(status));
exit(status);
}
if (talking_to_marben_ms)
#ifdef USING_ALERTS
/* If we register the alert auto-action, we will get an alert indication
when a message is delivered. So there is no need to poll at
short intervals within X400ms_Wait - we can do a slow background
poll and rely on the Alert indication to wake the code up instead */
#endif
/* setup logging from $(ETCDIR)x400api.xml or $(SHAREDIR)x400api.xml */
if (contype == 0) {
#ifdef WANT_AUTOFORWARDING
struct X400msAutoActionParameter *aa_param;
/* Register an Autoforwarding Autoaction. */
/* Add mandatory things to AutoAction parameter for auto-forwarding:
i.e. recipient address */
X400RecipNew(0, &rp);
strlen(def_oraddr));
"AF contentid", -1);
1);
1);
1);
"This message was autoforwarded",
-1);
"This is a cover note", -1);
"AutoForwarded:", -1);
4, aa_param);
if (status != X400_E_NOERROR) {
fprintf(stderr,
"Error in RegisterAutoAction: %s\n", X400msError(status));
/* tidily close the session */
(void) X400msClose(sp);
exit(status);
}
printf("Registered AutoForwarding autoaction (id = 4) OK\n");
#endif
#ifdef USING_ALERTS
/* No parameter needed for Alert autoaction - we do not support
configuration of requested-attributes in this API yet. */
status = X400msRegisterAutoAction(sp, X400_AUTO_ALERT, 9, NULL);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error in RegisterAutoAction: %s\n",
X400msError(status));
/* tidily close the session */
(void) X400msClose(sp);
exit(status);
}
printf("Registered AutoAlert autoaction (id = 9) OK\n");
#endif
/* Just test the register and deregister functions */
status = X400msRegisterAutoAction(sp, X400_AUTO_ALERT, 10, NULL);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error in RegisterAutoAction: %s\n",
X400msError(status));
/* tidily close the session */
(void) X400msClose(sp);
exit(status);
}
printf("Registered AutoAlert autoaction (id = 10) OK\n");
/* Lets do a deregistration of the action we just registered */
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error in DeregisterAutoAction: %s\n",
X400msError(status));
/* tidily close the session */
(void) X400msClose(sp);
exit(status);
}
printf("Deregistered AutoAlert autoaction (id = 10) OK\n");
}
ms_timeout_period = 20;
if (nummsg == 0) {
if (ms_timeout_period == 0) {
printf ("\n\nno messages - looping in msWait(%d) .....\n",
ms_timeout_period);
} else {
printf ("\n\nno messages - calling msWait(%d) .....\n",
ms_timeout_period);
}
} else {
printf("%d messages waiting\n", nummsg);
}
while (1) {
/* Using P3
* - if ms_timeout_period > 0, wait once then break
* - if ms_timeout_period == 0, loop through NUM_MSWAIT_TIMEOUTS
* times, then break.
*/
status = X400msWait(sp, ms_timeout_period, &nummsg_ready);
if (status == X400_E_NOERROR) {
printf("====== Getting next msg ======= (%d)\n", nummsg_ready);
(void) get_msg(sp);
max_timeouts = NUM_MSWAIT_TIMEOUTS;
} else {
if (status != X400_E_TIMED_OUT) {
/* tidily close the session */
fprintf(stderr, "X400msWait returned error: %s\n",
X400msError(status));
status = X400msClose(sp);
exit(status);
}
/* printf("X400msWait returned timeout\n"); */
sleep(1);
if (max_timeouts-- == 0)
break;
}
if (ms_timeout_period != 0)
break;
}
status = X400msClose(sp);
return(status);
}
static int get_msg (
struct X400msSession *sp
)
{
int n;
size_t length;
int intparam;
char recipient_str[BUFSIZ];
int num_recips = -1;
int type;
int seqn;
char buffer[BUFSIZ];
int status;
struct X400Recipient *rp;
struct X400Recipient *orig;
struct X400msMessage *mp;
printf("Getting message\n");
status = X400msMsgGet(sp, 0, &mp, &type, &seqn);
switch (status) {
fprintf(stderr, "MsgGet successfully got message\n");
break;
default :
fprintf(stderr, "Error from MsgGet: %s\n", X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
break;
}
if (type != X400_MSG_MESSAGE) {
fprintf(stderr, "Got a report (printing only some attributes)\n");
/* The ORADDRESS in the message is the (envelope) originator */
buffer, sizeof buffer, &length);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from MsgGetStrParam: %s\n",
X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
printf("Subject Identifier: %.*s\n", (int)length, buffer);
/* Get hold of the Originator and DL history*/
status = do_orig_and_dl (mp);
if (status != X400_E_NOERROR &&
status != X400_E_MISSING_ATTR) {
fprintf(stderr,"Failed to fetch originator and dl history: %s\n",
X400msError (status));
}
/* Get the primary recipients */
for (n = 1;; n++) {
status = X400msRecipGet(mp, X400_RECIP_REPORT, n, &rp);
if (status == X400_E_NO_RECIP)
break;
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from RecipGet: %s\n",
X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
/* Note: recipient may not actually have an O/R address */
recipient_str,
sizeof recipient_str, &length);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from RecipGetStrParam: %s\n",
X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
/* The original message delivery time, if this attribute exists,
* then the report is a positive Delivery Report */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR) {
/* Positive Delivery Report */
printf("Positive Delivery Report for recipient %d: %s\n", n,
recipient_str);
printf("Delivery Time: %.*s\n", (int)length, buffer);
}
else {
/* Negative Delivery Report */
printf("Negative Delivery Report for recipient %d: %s\n", n,
recipient_str);
/* Supplementary Info to the report */
buffer, sizeof buffer,
&length);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from RecipGetStrParam: %s\n",
X400msError(status));
buffer[0] = '\0';
}
printf("Supplementary Info: %.*s\n", (int)length, buffer);
/* The reason why the message was not delivered */
status =
&intparam);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from MsgGetIntParam: %s\n",
X400msError(status));
}
printf("Non-Delivery Reason: %d\n", intparam);
/* The diagnostics of the report for this recipient */
status =
&intparam);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from MsgGetIntParam: %s\n",
X400msError(status));
}
printf("Non-Delivery Diagnostic: %d\n", intparam);
}
}
(void) X400msMsgDelete(mp, 0);
status = X400msClose(sp);
exit(status);
}
/* The message identifier */
buffer, sizeof buffer, &length);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from MsgGetStrParam: %s\n",
X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
printf("Message Identifier: %.*s\n", (int)length, buffer);
/* The ORADDRESS in the message is the (envelope) originator */
buffer, sizeof buffer, &length);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from MsgGetStrParam: %s\n",
X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
printf("Envelope Originator: %.*s\n", (int)length, buffer);
/* The header originator is retrieved using GetRecip() */
status = X400msRecipGet(mp, X400_ORIGINATOR, 1, &orig);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from RecipGet: %s\n", X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
/* The X400_ORIGINATOR in the reicpient is the header originator */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR) {
printf("Header Originator %.*s\n", (int)length, buffer);
} else {
printf("No Header Originator\n");
}
status = X400msMsgCountRecip(mp, X400_RECIP_PRIMARY, &num_recips);
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from MsgCountRecip: %s\n",
X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
printf("There are %d recipients\n", num_recips);
/* Get the envelope recipients */
for (n = 1;; n++) {
status = X400msRecipGet(mp, X400_RECIP_ENVELOPE, n, &rp);
if (status == X400_E_NO_RECIP)
break;
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from RecipGet: %s\n", X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
/* Note: recipient may not actually have an O/R address */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR) {
printf("Header Recipient %d: %.*s\n", n, (int)length, buffer);
}
}
/* Get the primary recipients */
for (n = 1;; n++) {
status = X400msRecipGet(mp, X400_RECIP_PRIMARY, n, &rp);
if (status == X400_E_NO_RECIP)
break;
if (status != X400_E_NOERROR) {
fprintf(stderr, "Error from RecipGet: %s\n", X400msError(status));
/* tidily close the session */
status = X400msClose(sp);
exit(status);
}
/* Note: recipient may not actually have an O/R address */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR) {
printf("Primary Recipient %d: %.*s\n", n, (int)length, buffer);
}
}
#ifdef WANT_DL_EXP_HIST
/* DL Expansion history */
{
status = do_dl_hist(hist);
/* Normally the status is "X400_E_NO_VALUE" If there is no
* DL Expansion history.
* Or X400_E_MISSING_ATTR if the DL Expansion history entry is missing
* (so end of loop)
*/
if ( status == X400_E_NO_VALUE) {
/* do nothing */
} else if (status == X400_E_MISSING_ATTR ) {
printf("There is no DL expansion history\n");
} else {
/* There has been an error fetching the DL expansion history*/
printf("error getting DL Expansion History\n");
fprintf (stderr, "Error in X400mtDLExpHistGet: %s\n",
X400msError (status));
return status;
}
}
#endif
#define WANT_TRACE_INFO 1
#ifdef WANT_TRACE_INFO
{
status = do_trace_info(mp);
if ( status == X400_E_NOERROR) {
printf("Got Trace Info\n");
} else if ( status == X400_E_NO_VALUE) {
printf("There is no value for Trace Info\n");
} else if (status == X400_E_MISSING_ATTR ) {
printf("There is no Trace Info\n");
} else {
printf("error getting Trace Info\n");
fprintf (stderr, "Error fetching trace info: %s\n",
X400msError (status));
return status;
}
}
#endif
#define USE_INTERNAL_TRACE_INFO 1
#ifdef USE_INTERNAL_TRACE_INFO
{
status = do_internal_trace_info(mp);
if ( status == X400_E_NOERROR) {
printf("Got Trace Info\n");
} else if ( status == X400_E_NO_VALUE) {
printf("There is no value for internal Trace Info\n");
} else if (status == X400_E_MISSING_ATTR ) {
printf("There is no internal Trace Info\n");
} else {
printf("error getting int Trace Info\n");
fprintf (stderr, "Error fetching int trace info: %s\n",
X400msError (status));
return status;
}
}
#endif
#define USE_REDIRECTION_HISTORY 1
#ifdef USE_REDIRECTION_HISTORY
{
status = do_redirection_hist_env(mp);
if ( status == X400_E_NOERROR) {
printf("Got Redirection History\n");
} else if ( status == X400_E_NO_VALUE) {
/* do nothing */
printf("There is no value for Redirection History\n");
} else if (status == X400_E_MISSING_ATTR ) {
printf("There is no Redirection History\n");
} else {
printf("error getting Redirection History\n");
fprintf (stderr, "Error fetching Redirection History: %s\n",
X400msError (status));
return status;
}
}
#endif
/* Security Label */
#ifdef USE_SEC_LABEL
#define XML_BUFSIZE 1024
{
char xml_buffer[XML_BUFSIZE];
unsigned char slab_buffer[XML_BUFSIZE];
status = X400msMsgGetStrParam(mp,
(char*)slab_buffer,
XML_BUFSIZE,
&length);
if (status == X400_E_NO_VALUE) {
printf("No security label\n");
} else if (status != X400_E_NOERROR) {
fprintf(stderr,"Failed to fetch security label: %d",status);
exit(1);
} else {
int sec_status = 0;
sec_status = SecLabelInit("Example program");
if (sec_status != SECLABEL_E_NOERROR) {
fprintf(stderr, "SecLabelInit returned error %d\n", sec_status);
exit(1);
}
status = SecLabelPrint(slab_buffer,
length,
xml_buffer,
XML_BUFSIZE);
if (status != SECLABEL_E_NOERROR) {
fprintf(stderr, "SecLabelPrint returned error %d\n", status);
exit(1);
}
/* You could now write out the XML file, or parse it in memory..*/
printf("Got security label:%s\n",xml_buffer);
}
}
#endif
/* Subject is optional */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR)
printf("Subject: %.*s\n", (int)length, buffer);
/* content type */
status = X400msMsgGetIntParam(mp, X400_N_CONTENT_TYPE, &intparam);
if (status == X400_E_NOERROR)
printf ("Content type : P%d\n", intparam);
/* external content type */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR)
printf("External Content Type: %.*s\n", (int)length, buffer);
/* And message text (or it could be another type) */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR)
printf("\nIA5 Text:\n%.*s\n\n", (int)length, buffer);
else
printf("No IA5 Text content (%d: %s)\n", status, X400msError(status));
/* ATS attributes */
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR)
printf("ATS Priority Indicator: %.*s\n", (int)length, buffer);
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR)
printf("ATS Filing Time: %.*s\n", (int)length, buffer);
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR)
printf("ATS Optional Heading Info: %.*s\n", (int)length, buffer);
buffer, sizeof buffer, &length);
if (status == X400_E_NOERROR)
printf("ATS Text: %.*s\n", (int)length, buffer);
/* get all the attachments */
(void) get_body_parts(mp);
/* Deletes message in message store as well as internal copy */
printf("\n+++ got message - deleting it and returning+++\n");
status = X400msMsgDelete(mp, 0);
return(status);
}
#ifdef WANT_DL_EXP_HIST
static int do_dl_hist (
struct X400msMessage *mp
)
{
char DLORAddress[BUFSIZ];
char DLORDN[BUFSIZ];
char DLExpTime[BUFSIZ];
size_t length;
int n;
int status;
struct X400DLExpHist *hist = NULL;
/* Loop through the entries, pulling out the OR Address, DN, and expansion
* time for each entry.
* Stop looping when there is no n entry
*/
for ( n=1; ;n++ ) {
status = X400msDLExpHistGet (mp,n,&hist);
if (status != X400_E_NOERROR) {
return status;
}
status = X400DLGetStrParam (hist, X400_S_OR_ADDRESS,
DLORAddress, BUFSIZ , &length);
if (status == X400_E_NO_VALUE) {
}
if ( status == X400_E_NOERROR ) {
DLORAddress[length] = '\0';
printf ("DLExpansion List entry %d OR Address:%s\n",
n,DLORAddress);
} else {
fprintf (stderr, "Error in :X400mtDLGetStrParam OR %s\n",
X400msError (status));
}
status = X400DLGetStrParam (hist, X400_S_DIRECTORY_NAME,
DLORDN, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
DLORDN[length] = '\0';
printf ("DLExpansion List entry %d DN :%s\n",n,DLORDN);
} else {
fprintf (stderr, "Error in :X400mtDLGetStrParam DN %s\n",
X400msError (status));
}
status = X400DLGetStrParam (hist, X400_S_DLEXP_TIME,
DLExpTime, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
DLExpTime[length] = '\0';
printf ("DLExpansion List entry %d Time :%s\n",n,DLExpTime);
} else {
fprintf (stderr, "Error in :X400mtDLGetStrParam Time %s\n",
X400msError (status));
}
}
if (n == 1) {
printf("No DLEH found in message");
} else {
printf("%d DLEH entries found in message", n - 1);
}
}
#endif
static int do_redirection_hist_env (
struct X400msMessage *mp
)
{
char redirection_time [BUFSIZ];
char or_address [BUFSIZ];
char dn [BUFSIZ];
int rr;
size_t length;
int n;
int status;
struct X400RediHist *hist = NULL;
for ( n=1; ;n++ ) {
status = X400msRediHistGetEnv (mp,n,&hist);
if (status != X400_E_NOERROR)
break;
redirection_time, BUFSIZ,&length);
if (status == X400_E_NO_VALUE) {
}
if ( status == X400_E_NOERROR ) {
redirection_time[length] = '\0';
printf ("Redirection time: %i %s\n",n,redirection_time);
} else {
fprintf (stderr, "Error in do_redirection_hist_env: %s\n",
X400msError (status));
}
or_address, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
or_address[length] = '\0';
printf ("Redirection OR address %i :%s\n",n,or_address);
} else {
fprintf (stderr, "Error in do_redirection_hist_env: %s\n",
X400msError (status));
}
dn, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
dn[length] = '\0';
printf ("Redirection DN %i :%s\n",n,dn);
} else {
fprintf (stderr, "Error in do_redirection_hist_env: %s\n",
X400msError (status));
}
if ( status == X400_E_NOERROR ) {
printf ("DSI routing action %d :%s\n",n,X400RediReason(rr));
} else {
fprintf (stderr, "Error in do_redirection_hist_env: %s\n",
X400msError (status));
}
}
if (n == 1) {
printf("No Redirection histories found in envelope\n");
} else {
printf("%d Redirection histories found in envelope\n", n - 1);
}
}
static int do_trace_info (
struct X400msMessage *mp
)
{
char GDI [BUFSIZ];
char DSI_arrival_time[BUFSIZ];
int DSI_routing_action;
char DSI_attempted_domain[BUFSIZ];
char DSI_AA_def_time[BUFSIZ];
char DSI_AA_CEIT[BUFSIZ];
int DSI_AA_redirected = 0;
int DSI_AA_dl_operation = 0;
size_t length;
int n;
int status;
struct X400TraceInfo *info = NULL;
for ( n=1; ;n++ ) {
status = X400msTraceInfoGet (mp, n, &info, X400_TRACE_INFO);
if (status != X400_E_NOERROR)
break;
GDI, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
GDI[length] = '\0';
printf ("GDI entry %d OR Address:%s\n",n,GDI);
} else {
fprintf (stderr, "Error in do_trace_info: %s\n",
X400msError (status));
}
DSI_arrival_time, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
DSI_arrival_time[length] = '\0';
printf ("DSI arrival time %d :%s\n",n,DSI_arrival_time);
} else {
fprintf (stderr, "Error in do_trace_info: %s\n",
X400msError (status));
}
&DSI_routing_action);
if ( status == X400_E_NOERROR ) {
printf ("DSI routing action %d :%s\n",n,
DSI_routing_action ? "rerouted" : "relayed");
} else {
fprintf (stderr, "Error in do_trace_info: %s\n",
X400msError (status));
}
/* This one is optional*/
status = X400TraceInfoGetStrParam (info,
DSI_attempted_domain,
BUFSIZ ,&length);
if ( status == X400_E_NOERROR ) {
DSI_attempted_domain[length] = '\0';
printf ("DSI attempted domain %d :%s\n",n,DSI_attempted_domain);
} else {
fprintf (stderr, "Error in do_trace_info optional component: %s\n",
X400msError (status));
}
/*optional*/
status = X400TraceInfoGetStrParam (info,
DSI_AA_def_time,
BUFSIZ ,&length);
if ( status == X400_E_NOERROR ) {
DSI_AA_def_time[length] = '\0';
printf ("DSI AA %d :%s\n",n,DSI_AA_def_time);
} else {
fprintf (stderr, "Error in do_trace_info optional component: %s\n",
X400msError (status));
}
/*optional*/
status = X400TraceInfoGetStrParam (info,
DSI_AA_CEIT,
BUFSIZ ,&length);
if ( status == X400_E_NOERROR ) {
DSI_AA_CEIT[length] = '\0';
printf ("DSI AA %d :%s\n",n,DSI_AA_CEIT);
} else {
fprintf (stderr, "Error in do_trace_info optional component: %s\n",
X400msError (status));
}
status = X400TraceInfoGetIntParam (info,
&DSI_AA_redirected);
if ( status == X400_E_NOERROR ) {
printf ("DSI AA redirected %d :%d\n",n,DSI_AA_redirected );
} else {
fprintf (stderr, "Error in do_trace_info: %s\n",
X400msError (status));
}
status = X400TraceInfoGetIntParam (info,
&DSI_AA_dl_operation);
if ( status == X400_E_NOERROR ) {
printf ("DSI AA dl operation %d :%d\n",n,DSI_AA_dl_operation );
} else {
fprintf (stderr, "Error in do_trace_info: %s\n",
X400msError (status));
}
}
if (n == 1) {
printf("No Trace Info found in message\n");
} else {
printf("%d Trace Info entries found in message\n", n - 1);
}
}
static int do_internal_trace_info (
struct X400msMessage *mp
)
{
size_t length;
int n;
int status;
int SI_routing_action = 0;
int SI_attempted_action = 0;
int SI_OA = 0;
char GDI [BUFSIZ];
char SI_MTA_name [BUFSIZ];
char SI_time [BUFSIZ];
char SI_attempted_MTA_name[BUFSIZ];
char SI_attempted_domain [BUFSIZ];
char SI_defered_time [BUFSIZ];
char SI_CEIT [BUFSIZ];
struct X400InternalTraceInfo *info = NULL;
for ( n=1; ;n++ ) {
/*GDI*/
status = X400msInternalTraceInfoGet (mp,n, &info);
if (status == X400_E_NO_VALUE)
break;
GDI, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
GDI[length] = '\0';
printf ("GDI entry %d Domain:%s\n",n,GDI);
} else {
fprintf (stderr, "Error in do_trace_info: %s\n",
X400msError (status));
}
/*MTA Name */
SI_MTA_name, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
SI_MTA_name [length] = '\0';
printf ("MTA Name entry %d :%s\n",n,SI_MTA_name);
} else {
fprintf (stderr, "Error in do_internal_trace_info: %s\n",
X400msError (status));
}
/*SI MTA Name*/
SI_time, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
SI_time[length] = '\0';
printf ("SI MTA TIME entry %d :%s\n",n,SI_time);
} else {
fprintf (stderr, "Error in do_internal_trace_info: %s\n",
X400msError (status));
}
/* SI routing action */
&SI_routing_action);
if ( status == X400_E_NOERROR ) {
if (SI_routing_action == X400_MTA_SI_ROUTING_ACTION_RELAYED) {
printf ("SI routing action %d :relayed\n",n);
} else {
printf ("SI routing action %d :rerouted\n",n);
}
} else {
fprintf (stderr, "Error in do_internal_trace_info: %s\n",
X400msError (status));
}
&SI_attempted_action);
if ( status == X400_E_NOERROR ) {
if (SI_routing_action == X400_MTA_SI_RA_MTA) {
printf ("SI attempted action %d :MTA\n",n);
} else {
printf ("SI attempted action %d :Domain\n",n);
}
} else {
fprintf (stderr, "Error in do_internal_trace_info: %s\n",
X400msError (status));
}
if (SI_attempted_action == X400_MTA_SI_RA_MTA) {
/* SI Attempted MTA Name */
SI_attempted_MTA_name,
BUFSIZ,&length);
if ( status == X400_E_NOERROR ) {
SI_attempted_MTA_name[length] = '\0';
printf ("Supplied information attempted MTA %d"
":%s\n",n,SI_attempted_MTA_name);
} else {
fprintf (stderr, "Error in do_trace_info: %s\n",
X400msError (status));
}
} else {
/*SI Attempted domain*/
SI_attempted_domain, BUFSIZ,
&length);
if ( status == X400_E_NOERROR ) {
SI_attempted_domain[length] = '\0';
printf ("Supplied information attempted Domain entry"
" %d :%s\n",n,SI_attempted_domain);
} else {
fprintf (stderr, "Error in do_internal_trace_info: %s\n",
X400msError (status));
}
}
/* SI MTA Defered time*/
SI_defered_time,
BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
SI_defered_time[length] = '\0';
printf ("SI_defered_time entry %d :%s\n",n,
SI_defered_time);
} else {
fprintf (stderr, "Error in do_internaltrace_info: %s\n",
X400msError (status));
}
/* SI MTA Converted Encoded Information Types*/
SI_CEIT,
BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
SI_CEIT[length] = '\0';
printf ("SI_CEIT entry %d :%s\n",n,
SI_CEIT);
} else {
fprintf (stderr, "Error in do_internaltrace_info: %s\n",
X400msError (status));
}
&SI_OA);
if ( status == X400_E_NOERROR ) {
printf("SI_Other_Actions: %d: Redirected\n",n);
}
printf("SI_Other_Actions: %d: DLOP\n",n);
}
} else {
fprintf (stderr, "Error in do_internal_trace_info: %s\n",
X400msError (status));
}
}
if (n == 1) {
printf("No Internal Trace Info found in message\n");
} else {
printf("%d Internal Trace Info entries found in message\n", n - 1);
}
}
static int do_orig_and_dl (
struct X400msMessage *mp
)
{
char exp_time [BUFSIZ];
char or_address [BUFSIZ];
char dn_address [BUFSIZ];
size_t length;
int n;
int status;
struct X400ORandDL *orig_and_dl = NULL;
for ( n=1; ;n++ ) {
status = X400msORandDLGet (mp,n,&orig_and_dl);
if (status == X400_E_NO_VALUE) {
printf("Finished getting originator and dl expansion history\n");
break;
} else if (status != X400_E_NOERROR) {
return status;
}
status = X400ORandDLGetStrParam (orig_and_dl,
exp_time, BUFSIZ,&length);
if ( status == X400_E_NOERROR ) {
exp_time[length] = '\0';
printf ("do_orig_and_dl: %i %s\n",n,exp_time);
} else if(status != X400_E_MISSING_ATTR ) {
fprintf (stderr, "Error in do_orig_and_dl: %s\n",
X400msError (status));
}
or_address, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
or_address[length] = '\0';
printf ("do_orig_and_dl OR address %i :%s\n",n,or_address);
} else if(status != X400_E_MISSING_ATTR ) {
fprintf (stderr, "Error in do_orig_and_dl: %s\n",
X400msError (status));
}
status = X400ORandDLGetStrParam(orig_and_dl,
dn_address, BUFSIZ , &length);
if ( status == X400_E_NOERROR ) {
dn_address[length] = '\0';
printf ("originator and DL expansion DN %i :%s\n",n,dn_address);
} else if(status != X400_E_MISSING_ATTR ) {
fprintf (stderr, "Error in do_orig_and_dl: %s\n",
X400msError (status));
}
}
if (n == 1) {
printf("No orig and dl hist found in message\n");
} else {
printf("%d orig and dl hist found in message\n", n - 1);
}
return X400_E_NOERROR;
}
static void usage(void) {
printf("usage: %s\n", optstr);
printf("\t where:\n");
printf("\t -u : Don't prompt to override defaults \n");
printf("\t -3 : Use P3 connection \n");
printf("\t -7 : Use P7 connection \n");
printf("\t -m : OR Address in P7 bind arg \n");
printf("\t -d : DN in P7 bind arg \n");
printf("\t -p : Presentation Address of P7 Store \n");
printf("\t -w : P7 password of P7 user \n");
printf("\t -M : OR Address in P3 bind arg \n");
printf("\t -D : DN in P3 bind arg \n");
printf("\t -P : Presentation Address of P3 server\n");
printf("\t -W : P3 password of P3 user \n");
return;
}