22 #include <seclabel_api.h>
24 #include "ms_example.h"
26 static char *optstr =
"u371m:d:p:w:M:D:P:W:";
28 static void usage(
void);
31 struct X400msSession *sp
48 struct X400msSession *sp;
54 int ms_timeout_period = 10;
56 # define NUM_MSWAIT_TIMEOUTS 10
57 int max_timeouts = NUM_MSWAIT_TIMEOUTS;
62 fprintf(stderr,
"Failed to initialize logging, %s\n",
X400msError(status));
64 printf(
"Initialized logging from file x400api.xml\n");
67 if (get_args(argc, argv, optstr)) {
72 printf(
"Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
73 contype = ic_fgetc(x400_contype, stdin);
75 ic_fgetc(x400_contype, stdin);
77 if ( contype <
'0' ||
'2' < contype )
78 contype = x400_contype;
83 def_oraddr = x400_ms_user_addr;
84 def_dn = x400_ms_user_dn;
85 def_pa = x400_ms_presentation_address;
88 def_oraddr = x400_mta_user_addr;
89 def_dn = x400_mta_user_dn;
90 def_pa = x400_mta_presentation_address;
93 printf(
"Your ORAddress [%s] > ", def_oraddr);
94 ic_fgets(orn,
sizeof orn, stdin);
96 if (orn[strlen(orn) - 1] ==
'\n')
97 orn[strlen(orn) - 1] =
'\0';
100 strcpy(orn, def_oraddr);
103 printf(
"Password [%s]: ",
104 contype == 0 ? x400_p7_password : x400_p3_password);
105 if (ic_fgets(buffer,
sizeof buffer, stdin) == NULL)
108 if (buffer[strlen(buffer) - 1] ==
'\n')
109 buffer[strlen(buffer) - 1] =
'\0';
110 if (buffer[0] ==
'\0')
111 strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
113 printf(
"Presentation Address [%s] > ", def_pa);
114 ic_fgets(pa,
sizeof pa, stdin);
116 if (pa[strlen(pa) - 1] ==
'\n')
117 pa[strlen(pa) - 1] =
'\0';
122 if (talking_to_marben_ms)
125 status =
X400msOpen(contype, orn, def_dn, buffer, pa, &nummsg, &sp);
127 fprintf(stderr,
"Error in Open: %s\n",
X400msError(status));
131 if (talking_to_marben_ms)
142 #ifdef WANT_SESSION_SPECIFIC_LOGGING
150 #ifdef WANT_AUTOFORWARDING
151 struct X400msAutoActionParameter *aa_param;
187 "This message was autoforwarded",
192 "This is a cover note", -1);
196 "AutoForwarded:", -1);
202 "Error in RegisterAutoAction: %s\n",
X400msError(status));
207 printf(
"Registered AutoForwarding autoaction (id = 4) OK\n");
216 fprintf(stderr,
"Error in RegisterAutoAction: %s\n",
222 printf(
"Registered AutoAlert autoaction (id = 9) OK\n");
228 fprintf(stderr,
"Error in RegisterAutoAction: %s\n",
234 printf(
"Registered AutoAlert autoaction (id = 10) OK\n");
239 fprintf(stderr,
"Error in DeregisterAutoAction: %s\n",
245 printf(
"Deregistered AutoAlert autoaction (id = 10) OK\n");
248 ms_timeout_period = 20;
251 if (ms_timeout_period == 0) {
252 printf (
"\n\nno messages - looping in msWait(%d) .....\n",
255 printf (
"\n\nno messages - calling msWait(%d) .....\n",
259 printf(
"%d messages waiting\n", nummsg);
268 status =
X400msWait(sp, ms_timeout_period, &nummsg_ready);
270 printf(
"====== Getting next msg ======= (%d)\n", nummsg_ready);
272 max_timeouts = NUM_MSWAIT_TIMEOUTS;
276 fprintf(stderr,
"X400msWait returned error: %s\n",
283 if (max_timeouts-- == 0)
286 if (ms_timeout_period != 0)
295 struct X400msSession *sp
301 struct X400msMessage *mp;
307 printf(
"Getting message\n");
311 fprintf(stderr,
"MsgGet successfully got message\n");
314 fprintf(stderr,
"Error from MsgGet: %s\n",
X400msError(status));
321 status = print_msg(mp, type);
333 fprintf(stderr,
"Failed to get raw message length: error %d\n", status);
335 struct X400msMessage *newmsg;
338 databuf = buf = (
char *)malloc(retlen);
339 printf(
"Data buffer length required = %d\n", (
int)retlen);
342 fprintf(stderr,
"Failed to get raw message: error %d\n", status);
345 FILE *fd = fopen(
"message.dump",
"w");
347 fprintf(stderr,
"Failed to open file message.dump\n");
349 if (fwrite(databuf, 1, retlen, fd) < retlen) {
350 fprintf(stderr,
"Failed to write message to file message.dump\n");
352 fprintf(stdout,
"Dumped message to file message.dump\n");
361 fprintf(stderr,
"Failed to create message from bytes: error %d\n", status);
364 printf(
"************************** Printing cached message ************************\n");
365 print_msg(newmsg, newtype);
373 printf(
"\n+++ got message - deleting it and returning+++\n");
381 static void usage(
void) {
382 printf(
"usage: %s\n", optstr);
383 printf(
"\t where:\n");
384 printf(
"\t -u : Don't prompt to override defaults \n");
385 printf(
"\t -3 : Use P3 connection \n");
386 printf(
"\t -7 : Use P7 connection \n");
387 printf(
"\t -m : OR Address in P7 bind arg \n");
388 printf(
"\t -d : DN in P7 bind arg \n");
389 printf(
"\t -p : Presentation Address of P7 Store \n");
390 printf(
"\t -w : P7 password of P7 user \n");
391 printf(
"\t -M : OR Address in P3 bind arg \n");
392 printf(
"\t -D : DN in P3 bind arg \n");
393 printf(
"\t -P : Presentation Address of P3 server\n");
394 printf(
"\t -W : P3 password of P3 user \n");
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
#define X400_N_STRICT_P7_1988
#define X400_S_LOG_CONFIGURATION_FILE
#define X400_N_DISCLOSURE
int X400msAutoActionParameterAddIntParam(struct X400msAutoActionParameter *aap, int paramtype, int value)
Add integer-valued parameter to the autoaction parameter.
int X400msAutoActionParameterAddRecip(struct X400msAutoActionParameter *aap, int reciptype, struct X400Recipient *recip)
Add a receipient to the autoaction parameter.
#define X400_N_CONTENT_RETURN_REQUEST
#define X400_S_THIS_IPM_PREFIX
int X400msOpen(int type, const char *oraddr, const char *dirname, const char *credentials, const char *pa, int *messages, struct X400msSession **spp)
Open a session to a Message Store (P7) or MTA (P3) in synchronous mode.
#define X400_S_COVER_NOTE
struct X400msAutoActionParameter * X400msNewAutoActionParameter(void)
Create a new (empty) autoaction parameter structure.
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
void X400msFreeAutoActionParameter(struct X400msAutoActionParameter *aa_param)
Free an autoaction parameter.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
int X400msDeregisterAutoAction(struct X400msSession *sp, int type, int id)
Deregister an autoaction from the Message Store.
#define X400_N_OR_CANONICAL
int X400msMsgGet(struct X400msSession *sp, int number, struct X400msMessage **mpp, int *typep, int *seqp)
Get message object for transfer out from MS or MTA via P3.
int X400RecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the recipient.
#define X400_AUTO_FORWARDING
int X400RecipNew(int type, struct X400Recipient **rpp)
Create a new recipient object.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
#define X400_RECIP_STANDARD
#define X400_S_AUTO_FORWARDING_COMMENT
#define X400_S_CONTENT_IDENTIFIER
int X400msWait(struct X400msSession *sp, int seconds, int *count)
Wait for messages to be ready to be read.
#define X400_N_WAIT_INTERVAL
int X400msMsgFromRaw(struct X400msSession *sp, char *buffer, size_t buflen, struct X400msMessage **mpp, int *typep)
Reconstruct a message from a binary representation.
#define X400_N_IMPLICIT_CONVERSION_PROHIBITED
X400 MA/MS (P3/P7) Interface.
int X400msAutoActionParameterAddStrParam(struct X400msAutoActionParameter *aap, int paramtype, const char *value, size_t length)
Add string-valued parameter to the autoaction parameter.
int X400msMsgGetRaw(struct X400msSession *sp, struct X400msMessage *mp, char *buffer, size_t buflen, size_t *buflenp)
Get a binary representation of a message which can be subsequently be used to reconstruct the message...
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer parameter value in a session.
#define X400_N_ALTERNATE_RECIPIENT_ALLOWED
int X400msRegisterAutoAction(struct X400msSession *sp, int type, int id, struct X400msAutoActionParameter *aa_param)
Register an autoaction with the Message Store.
int X400InitializeLogging(const char *myname, const char *xmlfile)
Initialize X.400 API logging. If just the name of the logging configuration file is provided,...
#define X400_S_OR_ADDRESS
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.