
Messaging and Directory Server software used around the world in the
Government, Military, Aviation and Commercial sectors.
|
examples/x400_mttutorial.cThis is a streamlined heavily commented example program, which transfers a message into the MTA, and then transfers the message out of it.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048
00049
00050 #include <x400_mtapi.h>
00051 #include "example.h"
00052 #include <sys/types.h>
00053 #include <sys/stat.h>
00054 #include <fcntl.h>
00055 #include <errno.h>
00056 #include <time.h>
00057
00058 char *orig = "/CN=GatewayUser/OU=Sales/OU=dhcp-164/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00059 char *recip = "/CN=GatewayUser/OU=Sales/OU=dhcp-164/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00060
00061 static void send_hello_world(
00062 struct X400mtSession *sp
00063 );
00064
00065 static void receive_hello_world(
00066 struct X400mtSession *sp
00067 );
00068
00069 int main ()
00070 {
00071 int status;
00072 struct X400mtSession *sp;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 status = X400mtOpen (x400_channel, &sp);
00083 if ( status != X400_E_NOERROR ) {
00084 fprintf (stderr, "Error in Open: %s\n", X400mtError (status));
00085 exit (status);
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 X400mtSetStrDefault(sp, X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", 0);
00106
00107
00108
00109
00110
00111
00112 send_hello_world(sp);
00113
00114
00115
00116
00117 receive_hello_world(sp);
00118
00119 X400mtClose (sp);
00120 if ( status != X400_E_NOERROR ) {
00121 fprintf (stderr, "Error in Close: %s\n", X400mtError (status));
00122 exit (status);
00123 }
00124
00125 exit(0);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 static void send_hello_world(
00146 struct X400mtSession *sp
00147 )
00148 {
00149 int status;
00150
00151
00152 struct X400mtMessage *mp;
00153 struct X400Recipient *rp;
00154
00155
00156 printf("Now sending simple message\n");
00157
00158
00159
00160
00161
00162 status = X400mtMsgNew (sp, X400_MSG_MESSAGE, &mp);
00163
00164 if ( status != X400_E_NOERROR ) {
00165 fprintf (stderr, "Error in MsgNew: %s\n", X400mtError (status));
00166 exit (status);
00167 }
00168
00169
00170
00171
00172
00173
00174 status = X400mtMsgAddStrParam (mp, X400_S_OR_ADDRESS, orig, -1);
00175
00176 if ( status != X400_E_NOERROR ) {
00177 fprintf (stderr, "Error adding orignator: %s\n", X400mtError (status));
00178 exit (status);
00179 }
00180
00181
00182
00183 status = X400mtRecipNew (mp, X400_RECIP_STANDARD, &rp);
00184 if ( status != X400_E_NOERROR ) {
00185 fprintf (stderr, "Error adding recipient: %s\n", X400mtError (status));
00186 exit (status);
00187 }
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00198 if ( status != X400_E_NOERROR ) {
00199 fprintf (stderr, "Error adding recipient address: %s\n",
00200 X400mtError (status));
00201 exit (status);
00202 }
00203
00204
00205
00206
00207
00208
00209
00210 status = X400mtRecipAddIntParam (rp, X400_N_RESPONSIBILITY, 1);
00211 if ( status != X400_E_NOERROR ) {
00212 fprintf (stderr, "Error adding recipient responsibility: %s\n",
00213 X400mtError (status));
00214 exit (status);
00215 }
00216
00217
00218 status = X400mtMsgAddIntParam (mp, X400_N_CONTENT_TYPE, 2);
00219 if ( status != X400_E_NOERROR ) {
00220 fprintf (stderr, "Error adding Content type : %s\n",
00221 X400mtError (status));
00222 exit (status);
00223 }
00224
00225
00226 {
00227 char *content = "Hello World!";
00228 char *subject = "A simple test message";
00229
00230 status = X400mtMsgAddStrParam (mp,X400_T_IA5TEXT, content , -1);
00231 if ( status != X400_E_NOERROR ) {
00232 fprintf (stderr, "Error adding content : %s\n",
00233 X400mtError (status));
00234 exit (status);
00235 }
00236
00237 status = X400mtMsgAddStrParam (mp, X400_S_SUBJECT, subject, -1);
00238 if ( status != X400_E_NOERROR ) {
00239 fprintf (stderr, "Error adding subject : %s\n",
00240 X400mtError (status));
00241 exit (status);
00242 }
00243 }
00244
00245
00246 status = X400mtMsgSend (mp);
00247 if ( status != X400_E_NOERROR ) {
00248 fprintf (stderr, "Error in MsgSend: %s\n", X400mtError (status));
00249 exit (status);
00250 }
00251
00252
00253 status = X400mtMsgDelete (mp);
00254 if ( status != X400_E_NOERROR ) {
00255 fprintf (stderr, "Error in X400mtMsgDelete: %s\n", X400mtError (status));
00256 exit (status);
00257 }
00258
00259 printf("Sent message\n");
00260 }
00261
00262
00263 static void receive_hello_world(
00264 struct X400mtSession *sp
00265 )
00266 {
00267 struct X400mtMessage *mp;
00268 int status;
00269 int type;
00270 char buffer[BUFSIZ];
00271 size_t length;
00272
00273 printf("Now fetching message\n");
00274
00275 status = X400mtMsgGetStart (sp, &mp, &type);
00276 if ( status != X400_E_NOERROR ) {
00277 fprintf (stderr, "Error in X400mtMsgGetStart: %s\n",
00278 X400mtError (status));
00279 exit (status);
00280 }
00281
00282 switch ( type) {
00283 case X400_MSG_REPORT:
00284 printf("Got a report\n");
00285 exit(0);
00286 case X400_MSG_PROBE:
00287 printf("Got a probe\n");
00288 exit(0);
00289 case X400_MSG_MESSAGE:
00290 break;
00291 }
00292
00293
00294 status = X400mtMsgGetStrParam (mp, X400_S_OR_ADDRESS,
00295 buffer, sizeof buffer , &length);
00296 if(status == X400_E_NOERROR) {
00297 printf ("Originator: %.*s\n",(int)length,buffer);
00298 } else if (status == X400_E_NOSPACE) {
00299
00300
00301
00302
00303
00304
00305
00306
00307 char * big_buff = NULL;
00308 big_buff = (char *) malloc((sizeof(char)) * length);
00309 status = X400mtMsgGetStrParam (mp, X400_S_OR_ADDRESS,
00310 big_buff, length , &length);
00311 if (status != X400_E_NOERROR) {
00312 fprintf(stderr, "Error in getting originator address: %s\n",
00313 X400mtError (status));
00314 exit (status);
00315 }
00316 printf("Large Originator: %.*s\n",(int)length,big_buff);
00317 free(big_buff);
00318
00319 } else {
00320 fprintf (stderr, "Error in getting originator address: %s\n",
00321 X400mtError (status));
00322 exit (status);
00323 }
00324
00325 {
00326
00327
00328
00329
00330
00331
00332
00333 int n;
00334 struct X400Recipient *rp;
00335 for ( n = 1; ; n++ ) {
00336
00337
00338
00339
00340
00341
00342 status = X400mtRecipGet (mp, X400_RECIP_ENVELOPE, n, &rp);
00343 if ( status == X400_E_NO_RECIP ) {
00344 printf("Got final recipient\n");
00345 break;
00346 } else if ( status != X400_E_NOERROR ) {
00347 fprintf (stderr, "Error fetching recipients: %s\n",
00348 X400mtError (status));
00349 exit(status);
00350 }
00351
00352
00353
00354
00355
00356 status = X400mtRecipGetStrParam (rp, X400_S_OR_ADDRESS,
00357 buffer, BUFSIZ, &length);
00358 if ( status == X400_E_NOERROR ) {
00359 printf ("%s recipient %d: %.*s\n", buffer, n,
00360 (int)length, buffer);
00361 } else {
00362 fprintf (stderr, "Error fetching OR Address: %s\n",
00363 X400mtError (status));
00364 exit (status);
00365 }
00366
00367
00368
00369
00370
00371 }
00372 }
00373
00374
00375
00376 status = X400mtMsgGetStrParam (mp, X400_S_SUBJECT,
00377 buffer, sizeof buffer , &length);
00378 if ( status == X400_E_NOERROR ) {
00379 printf ("Subject: %.*s\n", (int)length, buffer);
00380 } else {
00381 fprintf (stderr, "Error fetching subject: %s\n",
00382 X400mtError (status));
00383 exit (status);
00384 }
00385
00386
00387
00388
00389
00390 status = X400mtMsgGetStrParam (mp, X400_T_IA5TEXT,
00391 buffer, sizeof buffer , &length);
00392 if ( status == X400_E_NOERROR ) {
00393 printf ("Text:\n%.*s\n", (int)length, buffer);
00394 } else {
00395 fprintf (stderr, "Error fetching ia5-text bodypart: %s\n",
00396 X400mtError (status));
00397 exit (status);
00398 }
00399
00400
00401
00402 status = X400mtMsgGetFinish (mp, X400_E_NOERROR, -1, -1, "");
00403 if ( status != X400_E_NOERROR ) {
00404 printf("X400mtMsgFinish returned error %d\n", status);
00405 fprintf (stderr, "Error in X400mtMsgFinish: %s\n",
00406 X400mtError (status));
00407 }
00408
00409
00410 status = X400mtMsgDelete (mp);
00411 if ( status != X400_E_NOERROR ) {
00412 printf("X400mtMsgDelete returned error %d\n", status);
00413 fprintf (stderr, "Error in X400mtMsgDelete: %s\n",
00414 X400mtError (status));
00415 }
00416
00417 }
00418
|