28#include <seclabel_api.h>
30#include "ms_example.h"
34static char *optstr =
"u371m:d:p:w:M:D:P:W:o:O:r:l:R:y:C:iaqsAvf:kK:B:";
37static char *default_recip =
"/CN=P7User1/O=attlee/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
39static const char text[] =
"First line\r\nSecond line\r\n";
40static char *binary_data;
42static char *fwd_subject =
"Forwarded message subject";
44static int add_binary_attachment (
45 struct X400msMessage *mp,
46 char * filename_to_send
48static int add_fwd_bp (
49 struct X400msMessage *mp,
54 struct X400msMessage *mp
56static void usage(
void) ;
69 struct X400msSession *sp;
70 struct X400msMessage *mp;
71 struct X400Recipient *rp;
77 if (get_args(argc, argv, optstr)) {
82 printf(
"Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
83 contype = ic_fgetc(x400_contype, stdin);
85 ic_fgetc(x400_contype, stdin);
87 if ( contype <
'0' ||
'2' < contype )
88 contype = x400_contype;
93 def_oraddr = x400_ms_user_addr;
94 def_dn = x400_ms_user_dn;
95 def_pa = x400_ms_presentation_address;
97 def_oraddr = x400_mta_user_addr;
98 def_dn = x400_mta_user_dn;
99 def_pa = x400_mta_presentation_address;
102 printf(
"Your ORAddress [%s] > ", def_oraddr);
103 ic_fgets (orn,
sizeof orn, stdin);
105 if ( (strlen(orn) > 0) && (orn[strlen(orn)-1] ==
'\n') )
106 orn[strlen(orn)-1] =
'\0';
109 strcpy(orn, def_oraddr);
112 printf (
"Password [%s]: ",
113 contype == 0 ? x400_p7_password : x400_p3_password);
114 if ( ic_fgets (buffer,
sizeof buffer, stdin) == NULL )
117 if ((strlen(buffer) > 0) && (buffer[strlen(buffer)-1] ==
'\n') )
118 buffer[strlen(buffer)-1] =
'\0';
119 if (buffer[0] ==
'\0')
120 strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
123 printf(
"Presentation Address [%s] > ", def_pa);
124 ic_fgets (pa,
sizeof pa, stdin);
126 if ( (strlen(pa) > 0) && (pa[strlen(pa)-1] ==
'\n'))
127 pa[strlen(pa)-1] =
'\0';
132 if (talking_to_marben_ms)
136 status =
X400msOpen (contype, orn, def_dn, buffer, pa, NULL, &sp);
138 fprintf (stderr,
"Error in Open: %s\n",
X400msError (status));
142 if (talking_to_marben_ms)
167 if (x400_default_recipient != NULL)
168 recip = x400_default_recipient;
170 recip = default_recip;
172 printf(
"Message recipient [%s]: ", recip);
173 ic_fgets (tmp,
sizeof tmp, stdin);
175 if ( (strlen(tmp) > 0) && (tmp[strlen(tmp)-1] ==
'\n') )
176 tmp[strlen(tmp)-1] =
'\0';
177 if (strlen(tmp) != 0)
180 printf(
"Subject [%s]: ", subject);
181 ic_fgets (tmp,
sizeof tmp, stdin);
183 if ( (strlen(tmp) > 0) && (tmp[strlen(tmp)-1] ==
'\n') )
184 tmp[strlen(tmp)-1] =
'\0';
185 if (strlen(tmp) != 0)
186 subject = strdup(tmp);
190 fprintf (stderr,
"x400msMsgNew returned error: %s\n",
X400msError (status));
196 fprintf (stderr,
"x400msRecipNew returned error: %s\n",
X400msError (status));
202 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
208 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
214 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
220 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
225 printf(
"delivery report request %d ( 1 - No, 2 - Yes)\n", x400_dr_req);
228 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
233 printf(
"read notification request %d ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n", x400_rn_req);
236 fprintf (stderr,
"x400msRecipAddIntParam returned error: %s\n",
X400msError (status));
241 char *contid =
"ContID00001";
246 fprintf (stderr,
"X400msMsgAddIntParam %d returned error: %s\n",
255 fprintf (stderr,
"X400msMsgAddIntParam %d returned error: %s\n",
261 printf(
"message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
262 x400_default_priority);
267 printf(
"military message priority is %d ( 0 - low, 1 - high)\n",
268 x400_default_priority);
276 char tmp_buffer[255];
278 snprintf(tmp_buffer, 244,
"%s '%s' '%.19s'",
279 subject, get_x400_pty_str_from_4406(x400_default_priority), ctime(&t));
280 printf(
"Subject is '%s'\n", tmp_buffer);
283 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
289 status = add_sec_label (mp);
291 fprintf (stderr,
"Failed to add Security Label: %s\n",
295 fprintf (stderr,
"added Security Label\n");
301 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
307 fprintf (stderr,
"x400ms returned error: %s\n",
X400msError (status));
314 printf(
"failed to add X400_T_IA5TEXT BP\n");
319 if (filename_to_send != NULL) {
320 status = add_binary_attachment (mp, filename_to_send);
322 printf(
"failed to add X400_T_BINARY BP\n");
325 status = add_fwd_bp (mp, orn, def_dn);
327 printf(
"failed to add forwarded BP\n");
331 printf(
"no binary file set - not sending X400_T_BINARY\n");
332 printf(
"no binary file set - not sending forwarded BP\n");
336 status = add_ftbp(mp);
338 printf(
"failed to add X400_T_BINARY BP\n");
345#define XML_BUFSIZE 1024
346#define STRING_BUFSIZE 1024
348 const char* xml_filename =
"seclabel.xml";
349 char xml_content[XML_BUFSIZE];
350 char str_content[STRING_BUFSIZE];
351 int str_len = STRING_BUFSIZE;
355 fd = fopen(xml_filename,
"r");
357 fprintf(stderr,
"Failed to open %s : %s\n",
358 xml_filename,strerror(errno));
361 fread(&xml_content,XML_BUFSIZE,1,fd);
365 status = SecLabelInit(
"Example program");
366 if (status != SECLABEL_E_NOERROR) {
367 fprintf(stderr,
"SecLabelInit returned error %d\n", status);
372 status = SecLabelParse(xml_content,
377 if (status != SECLABEL_E_NOERROR) {
378 fprintf(stderr,
"SecLabelParse returned error %d\n", status);
384 str_content,str_len);
386 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
395 fprintf (stderr,
"x400msMsgSend returned error: %s\n",
X400msError (status));
399 struct X400Recipient *irp;
409 fprintf(stderr,
"A recipient with ");
414 fprintf (stderr,
"ORAddress %s ", buf);
420 fprintf (stderr,
" and DN %s", buf);
422 fprintf (stderr,
" was rejected\n");
433 printf(
"Message submitted successfully\n");
437 fprintf(stderr,
"No MessageId present from submission result: error %d\n", status);
440 printf(
"MessageId from Submission Result = %s\n", buf);
445 fprintf(stderr,
"No MessageSubmissionTime present from submission result: error %d\n", status);
448 printf(
"MessageSubmissionTime from Submission Result = %s\n", buf);
453 fprintf(stderr,
"No ContentIdentifier present from submission result: error %d\n", status);
456 printf(
"ContentIdentifier from Submission Result = %s\n", buf);
464 fprintf(stderr,
"Failed to get raw message length: error %d\n", status);
466 struct X400msMessage *newmsg;
469 databuf = (
char *)malloc(retlen);
470 printf(
"Data buffer length required = %d\n", (
int)retlen);
473 fprintf(stderr,
"Failed to get raw message: error %d\n", status);
476 FILE *fd = fopen(
"message.dump",
"w");
478 fprintf(stderr,
"Failed to open file message.dump\n");
480 if (fwrite(databuf, 1, retlen, fd) < retlen) {
481 fprintf(stderr,
"Failed to write message to file message.dump\n");
483 fprintf(stdout,
"Dumped message to file message.dump\n");
492 fprintf(stderr,
"Failed to create message from bytes: error %d\n", status);
501 fprintf (stderr,
"x400msMsgDelete returned error: %s\n",
X400msError (status));
513static int add_binary_attachment (
514 struct X400msMessage *mp,
524 printf(
"sending file %s\n", filename);
525 if ((fd = open (filename_to_send, O_RDONLY)) == -1) {
526 printf(
"Failed to open content file %s: ", filename);
531 if (fstat(fd, &buf) != 0) {
533 printf(
"Can't fstat file %s %d", filename, errno);
537 file_size = buf.st_size;
538 printf(
"Content file size = %d\n", file_size);
540 binary_data = (
char *) malloc(file_size);
541 if ( binary_data == NULL )
544 if ((fs = read(fd, binary_data, file_size) ) == -1) {
545 printf(
"Cannot read from binary file %d\n", errno);
552 printf(
"failed to add X400_T_BINARY BP\n");
558static int add_fwd_bp (
559 struct X400msMessage *mp,
564 struct X400Message *x400_mp;
565 struct X400Recipient *rp;
569 printf(
"sending fwd bp \n");
573 fprintf (stderr,
"x400MsgNew returned error: %s\n",
X400msError (status));
578 "090909090909Z", (
size_t)-1);
580 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
585 "090909090909Z", (
size_t)-1);
587 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
594 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
599 fprintf (stderr,
"x400MsgAddStrParam returned error: %s\n",
X400msError (status));
606 fprintf (stderr,
"x400RecipNew returned error: %s\n",
X400msError (status));
613 fprintf (stderr,
"x400RecipAddStrParam returned error: %s\n",
X400msError (status));
620 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
627 fprintf (stderr,
"X400MsgAddRecip returned error: %s\n",
X400msError (status));
630 printf(
"Put %s in as originator\n", orig_orn);
635 fprintf (stderr,
"x400RecipNew returned error: %s\n",
X400msError (status));
641 fprintf (stderr,
"x400RecipAddStrParam returned error: %s\n",
X400msError (status));
647 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
653 fprintf (stderr,
"X400MsgAddRecip returned error: %s\n",
X400msError (status));
656 printf(
"Put %s in as reipient\n", recip);
662 fprintf (stderr,
"x400RecipNew returned error: %s\n",
X400msError (status));
668 fprintf (stderr,
"x400RecipAddStrParam returned error: %s\n",
X400msError (status));
674 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
X400msError (status));
682 fprintf (stderr,
"X400MsgAddRecip returned error: %s\n",
X400msError (status));
685 printf(
"Put %s in as reipient\n", recip);
691 printf(
"message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
692 x400_default_priority);
697 printf(
"military message priority is %d ( 0 - low, 1 - high)\n",
698 x400_default_priority);
706 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
X400msError (status));
713 printf(
"failed to add X400_T_IA5TEXT BP\n");
721 fprintf (stderr,
"x400ms returned error: %s\n",
X400msError (status));
732 fprintf (stderr,
"X400msMsgAddMessageBody returned error: %s\n",
X400msError (status));
741 struct X400msMessage *mp
748 struct X400Bodypart *bp;
751 if (filename_to_send == NULL) {
752 printf(
"no file set - not sending X400_T_FTBP\n");
755 fp = fopen(filename_to_send,
"rb");
756 if (fp == (FILE *)NULL) {
757 printf(
"Cannot open binary file\n");
760 binary_data = (
char *) malloc(bin_bp_size);
761 if ( binary_data == NULL )
763 if ((fs = fread (binary_data,
sizeof(
char),
764 bin_bp_size/
sizeof(
char), fp) ) == -1) {
765 printf(
"Cannot read from binary file\n");
771 if (fs < bin_bp_size) {
772 printf(
"Cannot read %d bytes from binary file (got %d)\n",
781 "Test FTBP File", -1);
786 "20230801060101.0Z", -1);
788 "20230801060202.0Z", -1);
794 printf(
"failed to add X400_T_FTBP BP\n");
797 printf(
"Sent %d bytes as X400_T_FTBP BP\n", fs);
801static void usage(
void) {
802 printf(
"usage: %s\n", optstr);
803 printf(
"\t where:\n");
804 printf(
"\t -u : Don't prompt to override defaults \n");
805 printf(
"\t -3 : Use P3 connection \n");
806 printf(
"\t -7 : Use P7 connection \n");
807 printf(
"\t -1 : Use Marben-compatibility mode for P7 connection \n");
808 printf(
"\t -m : OR Address in P7 bind arg \n");
809 printf(
"\t -d : DN in P7 bind arg \n");
810 printf(
"\t -p : Presentation Address of P7 Store \n");
811 printf(
"\t -w : P7 password of P7 user \n");
812 printf(
"\t -M : OR Address in P3 bind arg \n");
813 printf(
"\t -D : DN in P3 bind arg \n");
814 printf(
"\t -P : Presentation Address of P3 server\n");
815 printf(
"\t -W : P3 password of P3 user \n");
816 printf(
"\t -o : Originator \n");
817 printf(
"\t -O : Originator Return Address \n");
818 printf(
"\t -r : Recipient\n");
819 printf(
"\t -l : Logline\n");
820 printf(
"\t -R : Report setting: 0=none, 1=-ve, 2=+ve\n");
821 printf(
"\t -y : Military Priority \n");
822 printf(
"\t\t 0 - deferred, 1 - routine, 2 - priority \n");
823 printf(
"\t\t 3 - immediate, 4 - flash, 5 - override \n");
824 printf(
"\t -C : Content Type (2/22/772/OID) \n");
825 printf(
"\t -i : Implicit conversion prohibited = TRUE \n");
826 printf(
"\t -a : Alternate Recipient Prohibited = TRUE \n");
827 printf(
"\t -q : Content Return Request = TRUE \n");
828 printf(
"\t -s : Disclosure of Recipient = FALSE \n");
829 printf(
"\t -A : Recipient Reassignment Prohibited = FALSE \n");
830 printf(
"\t -v : Conversion with Loss Prohibited = FALSE \n");
831 printf(
"\t -f : Filename to transfer as binary bp\n");
832 printf(
"\t -k : Request Delivery Report\n");
833 printf(
"\t -K : Request Read Notification ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n");
834 printf(
"\t -B : Set alternative subject line \n");
int X400RecipNew(int type, struct X400Recipient **rpp)
Create a new recipient object.
int X400MsgAddRecip(struct X400Message *mp, int reciptype, struct X400Recipient *recip)
Add a recipient object to the message.
int X400RecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the recipient.
int X400MsgAddIntParam(struct X400Message *mp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400BodypartAddStrParam(struct X400Bodypart *bp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the body part.
int X400BodypartAddIntParam(struct X400Bodypart *bp, int paramtype, int value)
Add integer-valued parameter to the body part.
int X400MsgNew(int type, struct X400Message **mpp)
Creates new message.
int X400MsgAddAttachment(struct X400Message *mp, int type, const char *string, size_t length)
Add an attachment to the message.
int X400MsgAddStrParam(struct X400Message *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400BodypartNew(int type, struct X400Bodypart **bpp)
Create a new body part object.
int X400msMsgAddStrParam(struct X400msMessage *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msMsgFromRaw(struct X400msSession *sp, char *buffer, size_t buflen, struct X400msMessage **mpp, int *typep)
Reconstruct a message from a binary representation.
int X400msMsgAddBodypart(struct X400msMessage *mp, struct X400Bodypart *bp)
int X400msRecipGet(struct X400msMessage *mp, int type, int number, struct X400Recipient **rpp)
Get recipient object from message.
int X400msRecipAddIntParam(struct X400Recipient *rp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msMsgAddIntParam(struct X400msMessage *mp, int paramtype, int value)
Add integer-valued parameter to the message.
int X400msMsgGetStrParam(struct X400msMessage *mp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the message object.
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 X400msRecipGetStrParam(struct X400Recipient *rp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the recipient object.
int X400msRecipNew(struct X400msMessage *mp, int type, struct X400Recipient **rpp)
Add new recipient to a message.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
int X400msRecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer parameter value in a session.
int X400msMsgSend(struct X400msMessage *mp)
Send message object.
int X400msMsgAddMessageBody(struct X400msMessage *mp, struct X400Message *mbp)
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.
int X400msMsgAddAttachment(struct X400msMessage *mp, int type, const char *string, size_t length)
Add attachment to the message.
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
int X400msMsgNew(struct X400msSession *sp, int type, struct X400msMessage **mpp)
Creates new message.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
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_DIRECTORY_NAME
#define X400_S_OR_ADDRESS
#define X400_N_FTBP_OBJECT_SIZE
#define X400_S_FTBP_FILENAME
#define X400_S_FTBP_MODIFICATION_DATE
#define X400_S_FTBP_CREATION_DATE
#define X400_S_FTBP_CONTENT_DESCRIPTION
#define X400_N_NUM_ATTACHMENTS
#define X400_S_GRAPHIC_CHARSETS
#define X400_S_TELETEX_CHARSETS
#define X400_S_LOG_CONFIGURATION_FILE
#define X400_S_MESSAGE_DELIVERY_TIME
#define X400_N_MMTS_PRIORITY_QUALIFIER
#define X400_S_CONTENT_IDENTIFIER
#define X400_N_CONTENT_RETURN_REQUEST
#define X400_S_MESSAGE_SUBMISSION_TIME
#define X400_S_EXTERNAL_CONTENT_TYPE
#define X400_S_MESSAGE_IDENTIFIER
#define X400_S_SECURITY_LABEL
#define X400_E_RECIPIENT_ERROR
#define X400_N_ERROR_DUPLICATE_ATTRIBUTE
#define X400_N_STRICT_P7_1988
#define X400_N_USE_EXTENDED_SUBJECT
#define X400_N_REPORT_REQUEST
#define X400_N_NOTIFICATION_REQUEST
#define X400_RECIP_STANDARD
#define X400_RECIP_INVALID
X400 MA/MS (P3/P7) Interface.