x400_mssend_pure_x400.c
1/*
2 * Copyright (c) 2003-2013, Isode Limited, London, England.
3 * All rights reserved.
4 *
5 * Acquisition and use of this software and related materials for any
6 * purpose requires a written licence agreement from Isode Limited,
7 * or a written licence from an organisation licenced by Isode Limited
8 * to grant such a licence.
9 */
10
11/*
12 * @VERSION@
13 * Simple example program for submitting a message via a message store.
14 */
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19#include <sys/stat.h>
20#include <sys/types.h>
21#ifndef _WIN32
22#include <unistd.h>
23#endif
24#include <fcntl.h>
25#include <errno.h>
26
27#include <x400_msapi.h>
28#include <seclabel_api.h> /* For security labels */
29#include "example.h"
30
31
32static char *optstr = "u371m:d:p:w:M:D:P:W:r:o:O:r:g:G:c:l:R:y:C:iaqsAvf:kK:";
33
34/* These are the data items used to construct the message for submission */
35static char *default_recip = "/CN=P7User1/O=attlee/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
36char *recip;
37static const char text[] = "First line\r\nSecond line\r\n";
38
39static void usage(void) ;
40
41
42int main (
43 int argc,
44 char **argv
45)
46{
47 char buffer[BUFSIZ];
48 char pa[BUFSIZ];
49 char orn[BUFSIZ];
50 char tmp[BUFSIZ];
51 int status;
52 struct X400Message *mp;
53 struct X400Recipient *origp;
54 struct X400Recipient *rp;
55 int contype;
56 char *def_oraddr;
57 char *def_dn;
58 char *def_pa;
59
60 if (get_args(argc, argv, optstr)) {
61 usage();
62 exit(-1);
63 }
64
65 printf("Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
66 contype = ic_fgetc(x400_contype, stdin);
67 if (contype != 10)
68 ic_fgetc(x400_contype, stdin);
69
70 if ( contype < '0' || '2' < contype )
71 contype = x400_contype;
72 else
73 contype -= '0';
74
75 if (contype == 0) {
76 def_oraddr = x400_ms_user_addr;
77 def_dn = x400_ms_user_dn;
78 def_pa = x400_ms_presentation_address;
79 } else {
80 def_oraddr = x400_mta_user_addr;
81 def_dn = x400_mta_user_dn;
82 def_pa = x400_mta_presentation_address;
83 }
84
85 printf("Your ORAddress [%s] > ", def_oraddr);
86 ic_fgets (orn, sizeof orn, stdin);
87
88 if ( orn[strlen(orn)-1] == '\n' )
89 orn[strlen(orn)-1] = '\0';
90
91 if (orn[0] == '\0')
92 strcpy(orn, def_oraddr);
93
94 /* Prompt for password; note: reflected. */
95 printf ("Password [%s]: ",
96 contype == 0 ? x400_p7_password : x400_p3_password);
97 if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
98 exit (1);
99
100 if (buffer[strlen(buffer)-1] == '\n' )
101 buffer[strlen(buffer)-1] = '\0';
102 if (buffer[0] == '\0')
103 strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
104
105 /* Presentation Address */
106 printf("Presentation Address [%s] > ", def_pa);
107 ic_fgets (pa, sizeof pa, stdin);
108
109 if ( pa[strlen(pa)-1] == '\n' )
110 pa[strlen(pa)-1] = '\0';
111
112 if (pa[0] == '\0')
113 strcpy(pa, def_pa);
114
115 if (talking_to_marben_ms)
117
118 /* setup logging */
119 /* X400SetStrDefault(X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", 0); */
120
121 if (x400_default_recipient != NULL)
122 recip = x400_default_recipient;
123 else
124 recip = default_recip;
125
126 printf("Message recipient [%s]: ", recip);
127 ic_fgets (tmp, sizeof tmp, stdin);
128
129 if ( tmp[strlen(tmp)-1] == '\n' )
130 tmp[strlen(tmp)-1] = '\0';
131 if (strlen(tmp) != 0)
132 recip = strdup(tmp);
133
134 printf("Subject [%s]: ", subject);
135 ic_fgets (tmp, sizeof tmp, stdin);
136
137 if ( tmp[strlen(tmp)-1] == '\n' )
138 tmp[strlen(tmp)-1] = '\0';
139 if (strlen(tmp) != 0)
140 subject = strdup(tmp);
141
142 /* X400SetStrDefault(X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", 0); */
143 X400Initialize("test_program");
144
145 status = X400MsgNew (X400_MSG_MESSAGE, &mp);
146 if ( status != X400_E_NOERROR ) {
147 fprintf (stderr, "x400MsgNew returned error: %s\n", X400msError (status));
148 exit (status);
149 }
150
151 /* envelope originator OR address */
152 status = X400MsgAddStrParam (mp, X400_S_OR_ADDRESS, orn, (size_t)-1);
153 if ( status != X400_E_NOERROR ) {
154 fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
155 exit (status);
156 }
157 status = X400MsgAddStrParam (mp, X400_S_DIRECTORY_NAME, def_dn, (size_t)-1);
158 if ( status != X400_E_NOERROR ) {
159 fprintf (stderr, "x400MsgAddStrParam returned error: %s\n", X400msError (status));
160 exit (status);
161 }
162
163 /* add originator into headers */
164 status = X400RecipNew (X400_ORIGINATOR, &origp);
165 if ( status != X400_E_NOERROR ) {
166 fprintf (stderr, "x400RecipNew returned error: %s\n", X400msError (status));
167 exit (status);
168 }
169
170 /* put in DN part of OR Name */
171 status = X400RecipAddStrParam (origp, X400_S_DIRECTORY_NAME, def_dn, -1);
172 if ( status != X400_E_NOERROR ) {
173 fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
174 exit (status);
175 }
176
177 /* put originator into message */
178 status = X400MsgAddRecip (mp, X400_ORIGINATOR, origp);
179 if ( status != X400_E_NOERROR ) {
180 fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
181 exit (status);
182 }
183 printf("Put %s in as originator\n", def_dn);
184
185 /* add a recipient */
186 status = X400RecipNew (X400_RECIP_STANDARD, &rp);
187 if ( status != X400_E_NOERROR ) {
188 fprintf (stderr, "x400msRecipNew returned error: %s\n", X400msError (status));
189 exit (status);
190 }
191
192 status = X400RecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
193 if ( status != X400_E_NOERROR ) {
194 fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
195 exit (status);
196 }
197
198 status = X400RecipAddStrParam (rp, X400_S_DIRECTORY_NAME, "CN=recipient;c=gb", -1);
199 if ( status != X400_E_NOERROR ) {
200 fprintf (stderr, "x400msRecipAddStrParam returned error: %s\n", X400msError (status));
201 exit (status);
202 }
203
204 /* put recipient into message */
205 status = X400MsgAddRecip (mp, X400_RECIP_STANDARD, rp);
206 if ( status != X400_E_NOERROR ) {
207 fprintf (stderr, "X400MsgAddRecip returned error: %s\n", X400msError (status));
208 exit (status);
209 }
210 printf("Put %s in as recipient\n", recip);
211
212
213
214 /* Ask for delivery reports */
215 printf("delivery report request %d ( 1 - No, 2 - Yes)\n", x400_dr_req);
216 status = X400RecipAddIntParam (rp, X400_N_REPORT_REQUEST, x400_dr_req);
217 if ( status != X400_E_NOERROR ) {
218 fprintf (stderr, "x400RecipAddStrParam returned error: %s\n", X400msError (status));
219 exit (status);
220 }
221
222 /* Ask for read receipts */
223 printf("read notification request %d ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n", x400_rn_req);
224 status = X400msRecipAddIntParam (rp, X400_N_NOTIFICATION_REQUEST, x400_rn_req);
225 if ( status != X400_E_NOERROR ) {
226 fprintf (stderr, "x400msRecipAddIntParam returned error: %s\n", X400msError (status));
227 exit (status);
228 }
229
230 if (1) {
231 char *contid = "ContID00001";
232
233 /* Content identifier so we can correlate with submission result */
234 status = X400MsgAddStrParam(mp, X400_S_CONTENT_IDENTIFIER, contid, (size_t)-1);
235 if ( status != X400_E_NOERROR ) {
236 fprintf (stderr, "X400msMsgAddIntParam %d returned error: %s\n",
238 exit (status);
239 }
240 }
241
242 /* content return request on report - 0 = no */
244 if ( status != X400_E_NOERROR ) {
245 fprintf (stderr, "X400msMsgAddIntParam %d returned error: %s\n",
247 exit (status);
248 }
249
250 /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
251 printf("message priority is %d ( 0 - normal, 1 - non-urgent, 2 - urgent)\n",
252 x400_default_priority);
253 status = X400MsgAddIntParam (mp, X400_N_PRIORITY, x400_default_priority);
254 if ( status != X400_E_NOERROR ) return (status);
255
256 /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
257 printf("military message priority is %d ( 0 - low, 1 - high)\n",
258 x400_default_priority);
260 if ( status != X400_E_NOERROR ) return (status);
261
262 /* subject */
263 status = X400MsgAddStrParam (mp, X400_S_SUBJECT, subject, (size_t)-1);
264 if ( status != X400_E_NOERROR ) {
265 fprintf (stderr, "x400msMsgAddStrParam returned error: %s\n", X400msError (status));
266 exit (status);
267 }
268
269 /* 8859-1 attachment */
270 status = X400MsgAddStrParam (mp, X400_T_ISO8859_1, text, (size_t)-1);
271 if ( status != X400_E_NOERROR ) {
272 fprintf (stderr, "x400ms returned error: %s\n", X400msError (status));
273 exit (status);
274 }
275
276 status = X400MsgAddAttachment (mp, X400_T_IA5TEXT, text, strlen(text));
277 if ( status != X400_E_NOERROR ) {
278 printf("failed to add X400_T_IA5TEXT BP\n");
279 return (status);
280 }
281
282 {
283 size_t length = 0;
284
285 /* write content to file */
287 buffer, sizeof buffer, &length);
288
289 if ( status != X400_E_NOERROR ) {
290 fprintf (stderr, "X400MsgGetStrParam returned error: %s\n", X400msError (status));
291 exit (status);
292 } else {
293 printf("X400MsgGetStrParam got %ld bytes of content\n", (long)length);
294 }
295 }
296
297 exit (status);
298 /* NOTREACHED */
299}
300
301static void usage(void) {
302 printf("usage: %s\n", optstr);
303 printf("\t where:\n");
304 printf("\t -u : Don't prompt to override defaults \n");
305 printf("\t -3 : Use P3 connection \n");
306 printf("\t -7 : Use P7 connection \n");
307 printf("\t -m : OR Address in P7 bind arg \n");
308 printf("\t -d : DN in P7 bind arg \n");
309 printf("\t -p : Presentation Address of P7 Store \n");
310 printf("\t -w : P7 password of P7 user \n");
311 printf("\t -M : OR Address in P3 bind arg \n");
312 printf("\t -D : DN in P3 bind arg \n");
313 printf("\t -P : Presentation Address of P3 server\n");
314 printf("\t -W : P3 password of P3 user \n");
315 printf("\t -o : Originator \n");
316 printf("\t -O : Originator Return Address \n");
317 printf("\t -r : Recipient\n");
318 printf("\t -l : Logline\n");
319 printf("\t -y : Priority (0 - normal, 1 - non-urgent, 2 - urgent \n");
320 printf("\t -C : Content Type (2/22/772/OID) \n");
321 printf("\t -i : Implicit conversion prohibited = TRUE \n");
322 printf("\t -a : Alternate Recipient Prohibited = TRUE \n");
323 printf("\t -q : Content Return Request = TRUE \n");
324 printf("\t -s : Disclosure of Recipient = FALSE \n");
325 printf("\t -A : Recipient Reassignment Prohibited = FALSE \n");
326 printf("\t -v : Conversion with Loss Prohibited = FALSE \n");
327 printf("\t -f : Filename to transfer as binary bp\n");
328 printf("\t -k : Request Delivery Report\n");
329 printf("\t -K : Request Read Notification ( 1 - RN, 2 - NRN, 4 - return of IPM with NRN )\n");
330 return;
331}
int X400Initialize(char *myname)
Initialize X.400 API.
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 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 X400MsgGetStrParam(struct X400Message *mp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the message object.
int X400RecipAddIntParam(struct X400Recipient *rp, int paramtype, int value)
Add integer-valued parameter to the recipient.
int X400msRecipAddIntParam(struct X400Recipient *rp, int paramtype, int value)
Add integer-valued parameter to the message.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
#define X400_S_DIRECTORY_NAME
Definition x400_att.h:397
#define X400_S_OR_ADDRESS
Definition x400_att.h:349
#define X400_S_SUBJECT
Definition x400_att.h:749
#define X400_S_CONTENT_STRING
Definition x400_att.h:793
#define X400_T_IA5TEXT
Definition x400_att.h:825
#define X400_T_ISO8859_1
Definition x400_att.h:835
#define X400_N_PRIORITY
Definition x400_att.h:433
#define X400_N_MMTS_PRIORITY_QUALIFIER
Definition x400_att.h:482
#define X400_S_CONTENT_IDENTIFIER
Definition x400_att.h:425
#define X400_N_CONTENT_RETURN_REQUEST
Definition x400_att.h:445
#define X400_E_NOERROR
Definition x400_att.h:46
#define X400_MSG_MESSAGE
Definition x400_att.h:29
#define X400_N_REPORT_REQUEST
Definition x400_att.h:680
#define X400_N_NOTIFICATION_REQUEST
Definition x400_att.h:702
#define X400_RECIP_STANDARD
Definition x400_att.h:341
#define X400_ORIGINATOR
Definition x400_att.h:305
X400 MA/MS (P3/P7) Interface.

All rights reserved © 2002 - 2024 Isode Ltd.