examples/x400_mtsend.c

This is an example program which transfers a message into the MTA.

00001 /*  Copyright (c) 2003-2007, Isode Limited, London, England.
00002  *  All rights reserved.
00003  *                                                                       
00004  *  Acquisition and use of this software and related materials for any      
00005  *  purpose requires a written licence agreement from Isode Limited,
00006  *  or a written licence from an organisation licenced by Isode Limited
00007  *  to grant such a licence.
00008  *
00009  */
00010 
00011 /* $RCSfile: x400_mtsend.c,v $ $Revision: 1.32 $ $Date: 2007/09/25 14:16:15 $ $State: Exp $
00012  *
00013  * $Log: x400_mtsend.c,v $
00014  * Revision 1.32  2007/09/25 14:16:15  paga
00015  * T070925E - #define out dl expansion history and security label code.
00016  *
00017  * Revision 1.31  2007/08/31 07:22:22  paga
00018  * T070830J - Add example security label calls to x400mt api
00019  *
00020  * Revision 1.30  2007/08/28 15:29:55  paga
00021  * T070828E - Add DL Expansion list to submitted message.
00022  *
00023  * Revision 1.29  2007/07/24 12:45:41  dbw
00024  * T070724D - Fix warnings
00025  *
00026  * Revision 1.28  2007/07/17 08:46:41  dbw
00027  * T070716H - Fix warnings
00028  *
00029  * Revision 1.27  2007/05/15 13:11:11  dbw
00030  * T070515D - Update/Add copyright
00031  *
00032  * Revision 1.26  2007/05/09 15:57:10  ir
00033  * T070509P - Open binary for for attachment with binary flag.
00034  *
00035  * Revision 1.25  2007/04/05 12:46:01  brs
00036  * T070405A - Fix some warnings.
00037  *
00038  * Revision 1.24  2006/09/11 09:43:33  ir
00039  * T060825A - Add switch which accepts defaults (as overridden on the command line)
00040  *            stopping the prompts so that the programs can be run unattended.
00041  *            Support extra arguments to specify number of msgs to be sent in each
00042  *            session, and the the size of the message.
00043  *
00044  * Revision 1.23  2006/07/28 09:05:21  ir
00045  * T060728A - Add -u switch to example progs to accept cmd line args without
00046  *            prompting.
00047  *
00048  * Revision 1.22  2005/11/03 11:55:07  tc
00049  * T051103A - Delete unnecessary Doxygen text.
00050  *
00051  * Revision 1.21  2005/10/17 15:59:34  ir
00052  * T051017D - Set recipient correctly. Correct usage func.
00053  *
00054  * Revision 1.20  2005/10/12 10:42:59  ir
00055  * T051012A - Move otherwise unused variable into conditional compilation.
00056  *            Include <stdlib.h> for exit() prototype.
00057  *
00058  * Revision 1.19  2005/10/10 07:57:15  ir
00059  * T051007C - Call get_args() to parse cmdline args.
00060  *
00061  * Revision 1.18  2005/09/08 14:05:50  tc
00062  * T050908C - Add examples of setting external content type and loading
00063  *            content from file or string.
00064  *
00065  * Revision 1.17  2005/08/15 09:55:13  ldv
00066  * T050809J - Remove call to add X400_T_MESSAGE, improve comments in build_content()
00067  *
00068  * Revision 1.16  2005/08/09 14:07:07  ldv
00069  * T050809F - Truncate the sample msg_id value, add a warning and remove duplicated settings
00070  *
00071  * Revision 1.15  2005/05/25 16:23:37  dbw
00072  * T050525C - Files updated in 2004
00073  *
00074  * Revision 1.14  2004/08/16 15:43:33  ir
00075  * T040812E - Tidy up doxygen annotations.
00076  *            Change O/R addresses to work with documenation and x400quick.
00077  *            Change X400_N_NOTIFICATION_REQUEST to valid value (7).
00078  *
00079  * Revision 1.13  2004/06/30 09:31:18  ldv
00080  * T040625G - Improve the examples to use the new API functionality
00081  *
00082  * Revision 1.12  2004/06/03 14:07:35  dbw
00083  * T040603A - Update IPM identifier strings
00084  *
00085  * Revision 1.11  2004/05/27 12:01:43  dbw
00086  * T040527A - Use OR_ADDRESS rather than ORIGINATOR for originator address
00087  *
00088  * Revision 1.10  2004/05/06 09:26:36  tc
00089  * T040505C - Replace use of X400Message with X400msMessage.
00090  *         Call common 'do_tailoring' function to get data from x400tailor file.
00091  *         Call common 'set_defaults' routine.
00092  *            Correct originator name and recipient address strings to be
00093  *            ORName rather than ORAddress strings.
00094  *            Correct lastest delivery time value - it was missing the timezone.
00095  *            Pass tailored x400_channel value into X400mtOpen.
00096  *            Add X400_N_ORIGINAL_RECIPIENT_NUMBER attribute to recipient
00097  *            addresses.
00098  *            Set responsibility bit to 1 for recipients.
00099  *
00100  * Revision 1.9  2004/02/06 15:23:35  ir
00101  * T040205A - Use X400mtMsgAddAttachment() to add attachements.
00102  *
00103  * Revision 1.8  2003/12/11 10:06:15  ir
00104  * T031210A - Reduce content_id to below UB limit of 16. Tidy up comments.
00105  *
00106  * Revision 1.7  2003/10/20 09:14:52  tc-local
00107  * T031017B - Rename amhs->x400 throughout.
00108  *
00109  * Revision 1.6  2003/10/16 15:32:24  ir
00110  * T031016A - Add an invalid recip to force negative DR.
00111  *            Change report request args to request pos and neg reports.
00112  *
00113  * Revision 1.5  2003/10/02 15:49:16  ir
00114  * T031002A - Enable main code to be called more than once.
00115  *
00116  * Revision 1.4  2003/09/29 16:36:33  ir
00117  * T030929C - Add use of all possible attributes.
00118  *
00119  * Revision 1.3  2003/09/11 11:01:24  ir
00120  * T030911A - Use AMHSMessage and AMHSRecipient over AMHS API.
00121  *
00122  * Revision 1.2  2003/09/10 15:59:18  tc-local
00123  * T030910C - Change AMHSmtRecipient to AMHSRecipient.
00124  *
00125  * Revision 1.1  2003/09/04 12:30:39  ir
00126  * T030904B - Add amhs-common and initial MT support files.
00127  *
00128  *
00129  * Simple example program for transferring a message into the MTA
00130  */
00131 
00132 /* If you want to use raw content, remove the undef.
00133  * NB you will then need to put some content into <cwd>/p22
00134  */
00135 #define USE_RAW_CONTENT 1
00136 #undef USE_RAW_CONTENT
00137 
00138 #include <stdio.h>
00139 #include <stdlib.h>
00140 
00141 
00142 #include <x400_mtapi.h>
00143 #include <seclabel_api.h> /* For security labels */
00144 #include "example.h"
00145 #include <sys/types.h>
00146 #include <sys/stat.h>
00147 #include <fcntl.h>
00148 #include <errno.h>
00149 #include <time.h>
00150 
00151 
00152 /* local functions */
00153 static int send_msgs(
00154     int         argc,
00155     char      **argv
00156 ) ;
00157 static int send_msg(
00158     struct X400mtSession *sp
00159 );
00160 static int add_single_recip(
00161     struct X400mtMessage *mp
00162 );
00163 static int add_exempt_address(
00164     struct X400mtMessage *mp
00165 );
00166 static int add_address_list_indicator(
00167     struct X400mtMessage *mp
00168 );
00169 
00170 static int add_handling_instructions(
00171     struct X400mtMessage *mp
00172 );
00173 
00174 #ifdef add_multi_recips
00175 static int add_multi_recips(
00176     struct X400mtMessage *mp
00177 );
00178 static int add_content_recip_info(
00179     struct X400Recipient     *rp,
00180     const char               *free_form_name
00181 );
00182 #endif
00183 static int build_env(
00184     struct X400mtMessage *mp
00185 );
00186 static int build_content(
00187     struct X400mtMessage *mp
00188 );
00189 static int add_binary_bp(
00190     struct X400mtMessage *mp
00191 );
00192 static int add_env_recip_info(
00193     struct X400Recipient *rp
00194 );
00195 static void usage(void);
00196 
00197 static char * set_latest_del_time(void);
00198 static int rno = 1;
00199 static int fwd_rno = 1;
00200 
00201 static int load_ber(
00202     char *filename,
00203     char **output_buffer,
00204     int *buf_len
00205 );
00206 #define ADD_FWD_BODYPART 1
00207 #ifdef ADD_FWD_BODYPART
00208 static int add_fwd_bodypart(
00209     struct X400mtMessage *mp
00210 );
00211 
00212 static int build_fwd_env (
00213     struct X400Message *mp
00214 );
00215 
00216 static int build_fwd_content (
00217     struct X400Message *mp
00218 );
00219 
00220 static int add_fwd_recip(
00221     struct X400Message *mp,
00222     const char *oraddress,
00223     int type
00224 );
00225 
00226 static int create_fw_message(
00227     struct X400Message *mp
00228 );
00229 
00230 static int add_fwd_content_bodypart (
00231     struct X400mtMessage *mp
00232 );
00233 
00234 static int add_dl_exempted_recip_list (
00235     struct X400mtMessage *mp
00236 );
00237 
00238 #endif
00239 
00240 
00241 /* These are the data items used */
00242 
00243 /* The O/R addresses used are intended to be compatible with those
00244  * used in the quick install scripts mktailor.tcl, and createmhs.tcl.
00245  * (createmhs.tcl is used by x400quick).
00246  * Change this value to the name of your host.  */
00247 #define HOSTNAME "dhcp-165"
00248 
00249 /* define USE_P772_EXTS here, if you want to send a message using P772
00250  * military messaging extensions.
00251  */
00252 #define USE_P772_EXTS  1
00253 #ifdef USE_P772_EXTS
00254 /* P772 extensions use an external content type */
00255 #define WANT_EXTERNAL_CONTENT_TYPE 1
00256 #endif
00257 static char *optstr = "uG:O:r:g:G:c:l:R:y:C:iaqsAvf:X:S:";
00258 
00259 /* this value is used for the originator of the message */
00260 /* static const char orig[] = "/S=x400test-orig/OU="HOSTNAME"/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/"; */
00261 static const char *orig;
00262 
00263 static const char *fwd_orig;
00264 static const char *fwd_recip;
00265 
00266 static const char orig_ret_addr[] = "/S=x400test-orig/OU="HOSTNAME"/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00267 
00268 /* default recipients */
00269 /* static const char recip[] = "/S=x400test-recip/OU="HOSTNAME"/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/"; */
00270 static char *recip;
00271 static char *exemp_recip;
00272 
00273 static const char recip2[] = "/S=x400test-recip2/OU="HOSTNAME"/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00274 /* This recip will cause a report to be generated */
00275 static const char badrecip[] = "/S=x400test-recip2/OU=badhost/O=TestOrg/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00276 static const char auth_orig[] = "/S=x400test-auth-orig/OU="HOSTNAME"/O=TestOrg/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00277 
00278 /* envelope recip values */
00279 static const char orar[] = "/S=x400test-orig-orar/OU="HOSTNAME"/O=TestOrg/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00280 
00281 /* default envelope integer values */
00282 static int def_content_type = 2;
00283 #ifdef WANT_EXTERNAL_CONTENT_TYPE
00284 static char *def_ext_content_type = "1.3.26.0.4406.0.4.1";
00285 #endif
00286 static int def_bool = 0;
00287 static int def_priority = 2;
00288 
00289 /* default envelope string values */
00290 static const char def_utc[] = "050924120000";
00291 /* Make sure the second part of msg_id (after ";") is less than 32 chars in length */
00292 static const char msg_id[] = "/PRMD=TestPRMD/ADMD=TestADMD/C=GB/;"HOSTNAME".2810401";
00293 static const char content_id[] = "030924.140212";
00294 static const char fwd_msg_id[] = "/PRMD=TestFWDPRMD/ADMD=TestADMD/C=GB/;"HOSTNAME".2810401";
00295 
00296 
00297 /* default content integer types */
00298 static const int importance = 2;
00299 static const int sensitivity = 3;
00300 static const int autoforwarded = 1;
00301 
00302 /* default content string types */
00303 static const char subject[] = "A Test Message";
00304 static const char text[] = "First line\r\nSecond line\r\n";
00305 static const char ipm_id[] = "1064400656.24922*";
00306 static const char ipm_rep_id[] = "1064400656.24923*";
00307 static const char ipm_obs_id[] = "1064400656.24924*";
00308 static const char ipm_rel_id[] = "1064400656.24925*";
00309 static const char orig_ref[] = "orig-ref-val";
00310 
00311 
00312 #define XML_BUFSIZE 1024
00313 #define STRING_BUFSIZE 1024
00314 
00318 int main ( 
00319     int         argc,
00320     char      **argv
00321 ) 
00322 {
00323     return send_msgs (argc, argv);
00324 }
00325 
00326 static int send_msgs (
00327     int         argc,
00328     char      **argv
00329 ) 
00330 {
00331     int status;
00332     struct X400mtSession *sp;
00333 
00334     if (get_args(argc, argv, optstr)) {
00335         usage();
00336         exit(-1);
00337     }
00338 
00339     orig = strdup(x400_default_gw_originator);
00340     recip = strdup(x400_default_gw_recipient);
00341     exemp_recip = strdup(x400_default_exempted_recipient);
00342     fwd_orig = strdup(x400_default_fwd_originator);
00343     fwd_recip = strdup(x400_default_fwd_recipient);
00344         
00345     if (x400_channel == NULL) {
00346         fprintf (stderr, "No x400_channel value set in x400tailor file");
00347         exit(1);
00348     }
00349 
00350     /* open a new session */
00351     status = X400mtOpen (x400_channel, &sp);
00352     if ( status != X400_E_NOERROR ) {
00353         fprintf (stderr, "Error in Open: %s\n", X400mtError (status));
00354         exit (status);
00355     }
00356 
00357     /* setup logging from $(ETCDIR)x400api.xml or $(SHAREDIR)x400api.xml */
00358     X400mtSetStrDefault(sp, X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", 0);
00359 
00360     /* Set the ADatP3 seperator */
00361     X400mtSetStrDefault(sp, X400_ADATP3_SEP,"\r\n",-1);
00362     
00363     
00364     while (num_msgs_to_send-- > 0)
00365     {
00366         status = send_msg(sp);
00367         if ( status != X400_E_NOERROR ) {
00368             fprintf (stderr, "Error in send_msg: %s\n", X400mtError (status));
00369             exit (status);
00370         }
00371     }
00372 
00373     /* close the API session */
00374     return X400mtClose (sp);
00375 }
00376 
00377 static int send_msg(
00378     struct X400mtSession *sp
00379 )
00380 {
00381     int status;
00382     struct X400mtMessage *mp;
00383 
00384     /* start preparing a new message */
00385     status = X400mtMsgNew (sp, X400_MSG_MESSAGE, &mp);
00386     /* Should report all errors as above */
00387     if ( status != X400_E_NOERROR ) exit (status);
00388 
00389     /* setup originator using a single string */
00390     printf("originator of msg is %s\n", orig);
00391     status = X400mtMsgAddStrParam (mp, X400_S_OR_ADDRESS, orig, -1);
00392     if ( status != X400_E_NOERROR ) exit (status);
00393 
00394     /* add various envelope and header recipients into the message */
00395     /* status = add_multi_recips(mp); */
00396     status = add_single_recip(mp);
00397     if ( status != X400_E_NOERROR ) exit (status);
00398    
00399     
00400     /* build rest of the message envelope */
00401     status = build_env(mp);
00402     if ( status != X400_E_NOERROR ) exit (status);
00403 
00404     /* build the message content */
00405     status = build_content(mp);
00406     if ( status != X400_E_NOERROR ) exit (status);
00407 
00408     /* send the message */
00409     status = X400mtMsgSend (mp);
00410     if ( status != X400_E_NOERROR ) {
00411         fprintf (stderr, "Error in MsgSend: %s\n", X400mtError (status));
00412         exit (status);
00413     }
00414 
00415     /* delete the message structure */
00416     status = X400mtMsgDelete (mp);
00417     if ( status != X400_E_NOERROR ) exit (status);
00418 
00419     return status;
00420 }
00421 
00422 static int add_single_recip(
00423     struct X400mtMessage *mp
00424 )
00425 {
00426     struct X400Recipient *rp;
00427     int status;
00428 
00429     printf("Adding single recip %s\n", recip);
00430     /* add new recipient to message */
00431     status = X400mtRecipNew (mp, X400_RECIP_STANDARD, &rp);
00432     if ( status != X400_E_NOERROR ) return  (status);
00433     /* give recip an address */
00434     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00435     if ( status != X400_E_NOERROR ) return  (status);
00436     /* add other values to recip */
00437     status = add_env_recip_info (rp);
00438     if ( status != X400_E_NOERROR ) return  (status);
00439 
00440     /* Add an X.411 DL exempted recipient list */
00441     status = add_dl_exempted_recip_list (mp);
00442     if ( status != X400_E_NOERROR ) return  (status);
00443     
00444 
00445 #define USE_REDIRECTION_HISTORY 1
00446 #ifdef  USE_REDIRECTION_HISTORY
00447  {
00448      struct X400RediHist *hist1; 
00449      struct X400RediHist *hist2; 
00450      int status;
00451 
00452      status = X400RediHistNew(rp,&hist1);
00453      if (status !=X400_E_NOERROR) {
00454          fprintf(stderr,"Failed to allocate new redirection history object \n");
00455          exit(status);
00456      }
00457      
00458      /* Add Redirection History time */
00459      status =  X400RediHistAddStrParam (hist1,
00460                                         X400_S_REDIRECTION_TIME,
00461                                         "071121125704Z",
00462                                         -1);
00463      if (status !=X400_E_NOERROR) {
00464          fprintf(stderr,
00465                  "Failed to add X400_S_REDIRECTION_TIME to Redirection Hist\n");
00466          exit(status);
00467      }
00468 
00469      status =  X400RediHistAddStrParam (hist1,
00470                                         X400_S_OR_ADDRESS,
00471                                         "/cn=redihist/prmd=TestPRMD/admd=TestPRMD/C=gb",
00472                                         -1);
00473      if (status !=X400_E_NOERROR) {
00474          fprintf(stderr,
00475                  "Failed to add  X400_S_OR_ADDRESS to Redirection Hist\n");
00476          exit(status);
00477      }
00478 
00479      status =  X400RediHistAddStrParam (hist1,
00480                                         X400_S_DIRECTORY_NAME,
00481                                         "CN=redihist,c=GB",
00482                                         -1);
00483      if (status !=X400_E_NOERROR) {
00484          fprintf(stderr,
00485                  "Failed to add X400_S_DIRECTORY_NAME to Redirection Hist\n");
00486          exit(status);
00487      }
00488      
00489      
00490      status = X400RediHistAddIntParam(hist1,
00491                                       X400_N_REDIRECTION_REASON,
00492                                       X400_RR_ALIAS);
00493      if (status !=X400_E_NOERROR) {
00494          fprintf(stderr,
00495                  "Failed to add  X400_N_REDIRECTION_REASON to trace info\n");
00496          exit(status);
00497      }
00498 
00499      /*hist2*/
00500      
00501      status = X400RediHistNew(rp,&hist2);
00502      if (status !=X400_E_NOERROR) {
00503          fprintf(stderr,"Failed to allocate new trace info object \n");
00504          exit(status);
00505      }
00506      
00507      /* Add Redirection History time */
00508      status =  X400RediHistAddStrParam (hist2,
00509                                         X400_S_REDIRECTION_TIME,
00510                                         "071121125714Z",
00511                                         -1);
00512      if (status !=X400_E_NOERROR) {
00513          fprintf(stderr,
00514                  "Failed to add X400_S_REDIRECTION_TIME to Redirection Hist\n");
00515          exit(status);
00516      }
00517 
00518      status =  X400RediHistAddStrParam (hist2,
00519                                         X400_S_OR_ADDRESS,
00520                                         "/cn=redihist2/prmd=TestPRMD/admd=TestPRMD/C=gb",
00521                                         -1);
00522      if (status !=X400_E_NOERROR) {
00523          fprintf(stderr,
00524                  "Failed to add  X400_S_OR_ADDRESS to Redirection Hist\n");
00525          exit(status);
00526      }
00527 
00528      status =  X400RediHistAddStrParam (hist2,
00529                                         X400_S_DIRECTORY_NAME,
00530                                         "CN=redihist2,c=GB",
00531                                         -1);
00532      if (status !=X400_E_NOERROR) {
00533          fprintf(stderr,
00534                  "Failed to add X400_S_DIRECTORY_NAME to Redirection Hist\n");
00535          exit(status);
00536      }
00537      
00538      
00539      status = X400RediHistAddIntParam(hist2,
00540                                       X400_N_REDIRECTION_REASON,
00541                                       X400_RR_RECIP_ASSIGNED_ALT_RECIP);
00542      if (status !=X400_E_NOERROR) {
00543          fprintf(stderr,
00544                  "Failed to add  X400_N_REDIRECTION_REASON to "
00545                  "Redirection Hist\n");
00546          exit(status);
00547      }
00548      
00549 }   
00550 #endif
00551 
00552 #ifdef USE_P772_EXTS   
00553   /* Add ACP 127 Notification types */
00554  status = X400mtRecipAddIntParam (rp,
00555                                   X400_N_ACP127_NOTI_TYPE,
00556                                   X400_ACP127_NOTI_TYPE_NEG);
00557  if ( status != X400_E_NOERROR ) return (status);
00558 
00559  
00560  status =  X400mtRecipAddIntParam (rp,
00561                                    X400_N_ACP127_NOTI_TYPE,
00562                                    X400_ACP127_NOTI_TYPE_POS);
00563  if ( status != X400_E_NOERROR ) return (status);
00564 
00565  status =  X400mtRecipAddIntParam (rp,
00566                                    X400_N_ACP127_NOTI_TYPE,
00567                                    X400_ACP127_NOTI_TYPE_TRANS);
00568  if ( status != X400_E_NOERROR ) return (status);
00569 
00570  /*Add ACP127 Notification response */
00571  {
00572      struct X400ACP127Resp *resp = NULL;
00573      struct X400ALI *ali1 = NULL;
00574      struct X400ALI *ali2 = NULL;
00575      
00576      /* Create new ACP127 Response object */
00577      status = X400ACP127RespNew(rp,&resp);
00578      if ( status != X400_E_NOERROR ) return (status);
00579      
00580      
00581      /* Add Response type */
00582      status = X400ACP127RespAddIntParam(resp,X400_ACP127_NOTI_TYPE_NEG);
00583      if ( status != X400_E_NOERROR ) return (status);
00584      
00585         
00586      status = X400ACP127RespAddIntParam(resp,X400_ACP127_NOTI_TYPE_POS);
00587      if ( status != X400_E_NOERROR ) return (status);
00588 
00589      
00590      status = X400ACP127RespAddIntParam(resp,X400_ACP127_NOTI_TYPE_TRANS);
00591      if ( status != X400_E_NOERROR ) return (status);
00592      
00593      
00594      /* Add ACP127 response time*/
00595      status = X400ACP127RespAddStrParam (resp,
00596                                          X400_S_ACP127_NOTI_RESP_TIME,
00597                                          "080101120000+0100",
00598                                          -1);
00599      if ( status != X400_E_NOERROR ) return (status); 
00600      
00601      
00602      /* Add ACP127 response recipient*/
00603      status = X400ACP127RespAddStrParam (resp,
00604                                          X400_S_ACP127_NOTI_RESP_RECIPIENT,
00605                                          "ACP127 Recipient",
00606                                          -1);
00607      if ( status != X400_E_NOERROR ) return (status); 
00608 
00609      /* Add ACP127 supplimentry info*/
00610      status = X400ACP127RespAddStrParam (resp,
00611                                          X400_S_ACP127_NOTI_RESP_SUPP_INFO,
00612                                          "ACP127 supp info",
00613                                          -1);
00614      if ( status != X400_E_NOERROR ) return (status); 
00615      
00616      /* Add ACP127 Address List Indicator */
00617      status = X400ACP127RespNewALI (resp,&ali1);
00618      if ( status != X400_E_NOERROR ) return (status); 
00619 
00620      status = X400ALIAddIntParam (ali1,X400_N_ALI_TYPE,0);
00621      if ( status != X400_E_NOERROR ) return  (status);
00622      
00623      status = X400ALIAddIntParam (ali1,X400_N_ALI_NOTIFICTAION_REQUEST,0);
00624      if ( status != X400_E_NOERROR ) return  (status);
00625      
00626      status = X400ALIAddIntParam (ali1,X400_N_ALI_REPLY_REQUEST,1);
00627      if ( status != X400_E_NOERROR ) return  (status);
00628      
00629      status = X400ALIAddStrParam (ali1, X400_S_IOB_OR_ADDRESS,
00630                   "/cn=acp127ali1/PRMD=TestPRMD/ADMD=TestADMD/C=GB", -1);
00631      if ( status != X400_E_NOERROR ) return  (status);
00632      
00633      status = X400ALIAddStrParam (ali1, X400_S_IOB_DN_ADDRESS,
00634                                   "cn=acp127ali1,c=gb", -1);
00635      if ( status != X400_E_NOERROR ) return  (status);
00636      
00637      status = X400ALIAddStrParam (ali1, X400_S_IOB_FREE_FORM_NAME,
00638                                   "ACP127 Mr Address List Indicator1", -1);
00639      if ( status != X400_E_NOERROR ) return  (status);
00640      
00641      status = X400ALIAddStrParam (ali1, X400_S_IOB_TEL,"1270123456789",-1);
00642      if ( status != X400_E_NOERROR ) return  (status);
00643      
00644      /*Add a second ACP127 Address List indicator */
00645      status = X400ACP127RespNewALI (resp,&ali2);
00646      if ( status != X400_E_NOERROR ) return (status); 
00647      
00648      status = X400ALIAddIntParam (ali2,X400_N_ALI_TYPE,1);
00649      if ( status != X400_E_NOERROR ) return  (status);
00650      
00651      status = X400ALIAddIntParam (ali2,X400_N_ALI_NOTIFICTAION_REQUEST,1);
00652      if ( status != X400_E_NOERROR ) return  (status);
00653      
00654      status = X400ALIAddIntParam (ali2,X400_N_ALI_REPLY_REQUEST,0);
00655      if ( status != X400_E_NOERROR ) return  (status);
00656      
00657      status = X400ALIAddStrParam (ali2, X400_S_IOB_OR_ADDRESS,
00658                  "/cn=acp127ali2/PRMD=TestPRMD/ADMD=TestADMD/C=GB", -1);
00659      if ( status != X400_E_NOERROR ) return  (status);
00660      
00661      status = X400ALIAddStrParam (ali2, X400_S_IOB_DN_ADDRESS,
00662                                   "cn=acp127ali2,c=gb", -1);
00663      if ( status != X400_E_NOERROR ) return  (status);
00664      
00665      status = X400ALIAddStrParam (ali2, X400_S_IOB_FREE_FORM_NAME,
00666                                   "ACP127 Mr Address List Indicator2", -1);
00667      if ( status != X400_E_NOERROR ) return  (status);
00668      
00669      status = X400ALIAddStrParam (ali2, X400_S_IOB_TEL,"1270123456789",-1);
00670      if ( status != X400_E_NOERROR ) return  (status);
00671      
00672  }
00673  
00674 #endif
00675     
00676     return X400_E_NOERROR;
00677 }
00678 
00679 static int add_exempt_address(
00680     struct X400mtMessage *mp
00681 )
00682 {
00683     struct X400Recipient *rp;
00684     struct X400Recipient *rp2;
00685     int status;
00686      printf("Adding exempted recip %s\n", exemp_recip);
00687     /* add new recipient to message */
00688     status = X400mtRecipNew (mp, X400_EXEMPTED_ADDRESS, &rp);
00689     if ( status != X400_E_NOERROR ) return  (status);
00690     /* give exempted recip an address */
00691     status = X400mtRecipAddStrParam (rp, X400_S_IOB_OR_ADDRESS,
00692                                      exemp_recip, -1);
00693     if ( status != X400_E_NOERROR ) return  (status);
00694 
00695     status = X400mtRecipAddStrParam (rp, X400_S_IOB_DN_ADDRESS,
00696                                      "cn=exemprecip,c=gb", -1);
00697     if ( status != X400_E_NOERROR ) return  (status);
00698 
00699     status = X400mtRecipAddStrParam (rp, X400_S_IOB_FREE_FORM_NAME,
00700                                      "Mr Exempted", -1);
00701     if ( status != X400_E_NOERROR ) return  (status);
00702 
00703     status = X400mtRecipAddStrParam (rp, X400_S_IOB_TEL,
00704                                      "0123456789", -1);
00705     if ( status != X400_E_NOERROR ) return  (status);
00706 
00707     /* Add second exempted recipient */
00708     status = X400mtRecipNew (mp, X400_EXEMPTED_ADDRESS, &rp2);
00709     if ( status != X400_E_NOERROR ) return  (status);
00710     
00711     status = X400mtRecipAddStrParam (rp2, X400_S_IOB_OR_ADDRESS,
00712                                      "/CN=exemp2/PRMD=TestPRMD/ADMD=TestADMD/C=GB", -1);
00713     if ( status != X400_E_NOERROR ) return  (status);
00714     
00715     return X400_E_NOERROR;
00716 }
00717 static int add_address_list_indicator(
00718     struct X400mtMessage *mp
00719 )
00720 {
00721     struct X400ALI *ali  = NULL;
00722     struct X400ALI *ali2 = NULL;
00723     int status;
00724     
00725     printf("Adding address list indicators\n");
00726     
00727     /* add new Address List Indicator to message */
00728     status = X400mtALINew (mp,&ali);
00729     if ( status != X400_E_NOERROR ) return  (status);
00730     
00731     status = X400ALIAddIntParam (ali,X400_N_ALI_TYPE,0);
00732     if ( status != X400_E_NOERROR ) return  (status);
00733 
00734     status = X400ALIAddIntParam (ali,X400_N_ALI_NOTIFICTAION_REQUEST,0);
00735     if ( status != X400_E_NOERROR ) return  (status);
00736     
00737     status = X400ALIAddIntParam (ali,X400_N_ALI_REPLY_REQUEST,1);
00738     if ( status != X400_E_NOERROR ) return  (status);
00739     
00740     status = X400ALIAddStrParam (ali, X400_S_IOB_OR_ADDRESS,
00741                                      "/cn=ALI1/PRMD=TestPRMD/ADMD=TestADMD/C=GB", -1);
00742     if ( status != X400_E_NOERROR ) return  (status);
00743 
00744     status = X400ALIAddStrParam (ali, X400_S_IOB_DN_ADDRESS,
00745                                      "cn=ali1,c=gb", -1);
00746     if ( status != X400_E_NOERROR ) return  (status);
00747 
00748     status = X400ALIAddStrParam (ali, X400_S_IOB_FREE_FORM_NAME,
00749                                      "Mr Address List Indicator1", -1);
00750     if ( status != X400_E_NOERROR ) return  (status);
00751 
00752     status = X400ALIAddStrParam (ali, X400_S_IOB_TEL,"0123456789", -1);
00753     if ( status != X400_E_NOERROR ) return  (status);
00754 
00755     /* Add second exempted recipient */
00756     status = X400mtALINew (mp, &ali2);
00757     if ( status != X400_E_NOERROR ) return  (status);
00758     
00759     status = X400ALIAddStrParam (ali2, X400_S_IOB_OR_ADDRESS,
00760                                  "/CN=ALI2/PRMD=TestPRMD/ADMD=TestADMD/C=GB", -1);
00761     if ( status != X400_E_NOERROR ) return  (status);
00762     
00763     status = X400ALIAddIntParam (ali2,X400_N_ALI_TYPE,1);
00764     if ( status != X400_E_NOERROR ) return  (status);
00765     status = X400ALIAddStrParam (ali2, X400_S_IOB_OR_ADDRESS,
00766                                      "/cn=ALI2/PRMD=TestPRMD/ADMD=TestADMD/C=GB", -1);
00767     if ( status != X400_E_NOERROR ) return  (status);
00768 
00769     status = X400ALIAddStrParam (ali2, X400_S_IOB_DN_ADDRESS,
00770                                      "cn=ali2,c=gb", -1);
00771     if ( status != X400_E_NOERROR ) return  (status);
00772     
00773    
00774     
00775     return X400_E_NOERROR;
00776 }
00777 
00778 static int add_handling_instructions(
00779     struct X400mtMessage *mp
00780 )
00781 {
00782     struct X400PSS *pss  = NULL; /* Printable String Sequence object */
00783     struct X400PSS *pss2 = NULL;
00784     int status;
00785     
00786     printf("Adding handling instructions\n");
00787     
00788     /* add new Address List Indicator to message */
00789     status = X400mtPSSNew (mp,X400_S_HANDLING_INSTRUCTIONS,&pss);
00790     if ( status != X400_E_NOERROR ) return  (status);
00791     
00792     
00793     status = X400PSSAddStrParam (pss,
00794                                  "Handling instruction1",
00795                                  -1);
00796     if ( status != X400_E_NOERROR ) return  (status);
00797 
00798 
00799     status = X400mtPSSNew (mp,X400_S_HANDLING_INSTRUCTIONS,&pss2);
00800     if ( status != X400_E_NOERROR ) return  (status);
00801     
00802     
00803     status = X400PSSAddStrParam (pss2,
00804                                  "Handling instruction2",
00805                                  -1);
00806     if ( status != X400_E_NOERROR ) return  (status);
00807     
00808     
00809     return X400_E_NOERROR;
00810 }
00811 
00812 static int add_message_instructions(
00813     struct X400mtMessage *mp
00814 )
00815 {
00816     struct X400PSS *pss  = NULL; /* Printable String Sequence object */
00817     struct X400PSS *pss2 = NULL;
00818     int status;
00819     
00820     printf("Adding Message instructions\n");
00821     
00822     /* add new Address List Indicator to message */
00823     status = X400mtPSSNew (mp,X400_S_MESSAGE_INSTRUCTIONS,&pss);
00824     if ( status != X400_E_NOERROR ) return  (status);
00825     
00826     
00827     status = X400PSSAddStrParam (pss,
00828                                  "Message instruction1",
00829                                  -1);
00830     if ( status != X400_E_NOERROR ) return  (status);
00831 
00832 
00833     status = X400mtPSSNew (mp,X400_S_MESSAGE_INSTRUCTIONS,&pss2);
00834     if ( status != X400_E_NOERROR ) return  (status);
00835     
00836     
00837     status = X400PSSAddStrParam (pss2,
00838                                  "Message instruction2",
00839                                  -1);
00840     if ( status != X400_E_NOERROR ) return  (status);
00841     
00842     
00843     return X400_E_NOERROR;
00844 }
00845 
00846 static int add_dist_codes_sic(
00847     struct X400mtMessage *mp
00848 )
00849 {
00850     struct X400PSS *pss  = NULL; /* Printable String Sequence object */
00851     struct X400PSS *pss2 = NULL;
00852     struct X400DistField *distfield1 = NULL;
00853     struct X400DistField *distfield2 = NULL;
00854     int status;
00855     
00856     printf("Adding Distribution Codes\n");
00857     
00858     /* Add new SIC */
00859     status = X400mtPSSNew (mp,X400_S_DIST_CODES_SIC,&pss);
00860     if ( status != X400_E_NOERROR ) return  (status);
00861     
00862     
00863     status = X400PSSAddStrParam (pss,
00864                                  "dist code 1",
00865                                  -1);
00866     if ( status != X400_E_NOERROR ) return  (status);
00867 
00868     /* Add second SIC */
00869     status = X400mtPSSNew (mp,X400_S_DIST_CODES_SIC,&pss2);
00870     if ( status != X400_E_NOERROR ) return  (status);
00871     
00872     
00873     status = X400PSSAddStrParam (pss2,
00874                                  "dist code 2",
00875                                  -1);
00876     if ( status != X400_E_NOERROR ) return  (status);
00877     
00878     /* Add new Distribution Extension Field */
00879     status = X400mtDistFieldNew (mp,&distfield1);
00880     if ( status != X400_E_NOERROR ) return  (status);
00881     
00882     
00883     status = X400DistFieldAddStrParam (distfield1,
00884                                        X400_S_DIST_CODES_EXT_OID,
00885                                        "1.2.3.4.5",
00886                                        -1);
00887     if ( status != X400_E_NOERROR ) return  (status);
00888 
00889     status = X400DistFieldAddStrParam (distfield1,
00890                                        X400_S_DIST_CODES_EXT_VALUE,
00891                                        "Some value1",
00892                                        -1);
00893     if ( status != X400_E_NOERROR ) return  (status);
00894 
00895     /* Add second SIC */
00896      status = X400mtDistFieldNew (mp,&distfield2);
00897     if ( status != X400_E_NOERROR ) return  (status);
00898     
00899     
00900     status = X400DistFieldAddStrParam (distfield2,
00901                                        X400_S_DIST_CODES_EXT_OID,
00902                                        "1.2.3.4.5.6",
00903                                        -1);
00904     if ( status != X400_E_NOERROR ) return  (status);
00905 
00906     status = X400DistFieldAddStrParam (distfield2,
00907                                        X400_S_DIST_CODES_EXT_VALUE,
00908                                        "Some value2",
00909                                        -1);
00910     if ( status != X400_E_NOERROR ) return  (status);
00911 
00912     
00913     return X400_E_NOERROR;
00914 }
00915 
00916 static int add_other_recipient_indicator(
00917     struct X400mtMessage *mp
00918 )
00919 {
00920     struct X400OtherRecip *recip  = NULL; 
00921     struct X400OtherRecip *recip2 = NULL;
00922     int status;
00923     
00924     printf("Adding Other Recipient Indicators\n");
00925     
00926     /* Add new Other recipient */
00927     status = X400mtOtherRecipNew (mp,&recip);
00928     if ( status != X400_E_NOERROR ) return  (status);
00929     
00930     
00931     status = X400OtherRecipAddStrParam (recip,"other recip 1",-1);
00932     if ( status != X400_E_NOERROR ) return  (status);
00933 
00934     
00935     status = X400OtherRecipAddIntParam (recip,1);
00936     if ( status != X400_E_NOERROR ) return  (status);
00937 
00938     
00939     /* Add second Other recipient */
00940     status = X400mtOtherRecipNew (mp,&recip2);
00941     if ( status != X400_E_NOERROR ) return  (status);
00942     
00943     
00944     status = X400OtherRecipAddStrParam (recip2,"other recip 2",-1);
00945     if ( status != X400_E_NOERROR ) return  (status);
00946 
00947     
00948     status = X400OtherRecipAddIntParam (recip2,0);
00949     if ( status != X400_E_NOERROR ) return  (status);
00950     
00951     
00952     
00953     return X400_E_NOERROR;
00954 }
00955 #ifdef add_multi_recips
00956 static int add_multi_recips(
00957     struct X400mtMessage *mp
00958 )
00959 {
00960     struct X400Recipient *rp;
00961     int status;
00962 
00963     printf("Adding multiple recips\n");
00964     /* add new recipient to message */
00965     status = X400mtRecipNew (mp, X400_RECIP_STANDARD, &rp);
00966     if ( status != X400_E_NOERROR ) return  (status);
00967     /* give recip an address */
00968     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00969     if ( status != X400_E_NOERROR ) return  (status);
00970     /* add other values to recip */
00971     status = add_env_recip_info (rp);
00972     if ( status != X400_E_NOERROR ) return  (status);
00973 
00974     /* add second recipient to message */
00975     status = X400mtRecipNew (mp, X400_RECIP_STANDARD, &rp);
00976     if ( status != X400_E_NOERROR ) exit (status);
00977     /* give recip an address */
00978     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip2, -1);
00979     if ( status != X400_E_NOERROR ) return  (status);
00980     status = X400mtRecipAddIntParam (rp, X400_N_ORIGINAL_RECIPIENT_NUMBER, rno);
00981     rno++;
00982     if ( status != X400_E_NOERROR ) return  (status);
00983 
00984     /* add bad recipient to message */
00985     status = X400mtRecipNew (mp, X400_RECIP_STANDARD, &rp);
00986     if ( status != X400_E_NOERROR ) exit (status);
00987     /* give recip an address */
00988     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, badrecip, -1);
00989     if ( status != X400_E_NOERROR ) return  (status);
00990     status = X400mtRecipAddIntParam (rp, X400_N_ORIGINAL_RECIPIENT_NUMBER, rno);
00991     rno++;
00992     if ( status != X400_E_NOERROR ) return  (status);
00993 
00994     /* add cc recipient to message */
00995     status = X400mtRecipNew (mp, X400_RECIP_CC, &rp);
00996     if ( status != X400_E_NOERROR ) exit (status);
00997     /* give recip an address */
00998     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00999     if ( status != X400_E_NOERROR ) return  (status);
01000     /* add other values to recip */
01001     status = add_content_recip_info (rp, recip);
01002     if ( status != X400_E_NOERROR ) return  (status);
01003 
01004     /* add second cc recipient to message */
01005     status = X400mtRecipNew (mp, X400_RECIP_CC, &rp);
01006     if ( status != X400_E_NOERROR ) exit (status);
01007     /* give recip an address */
01008     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip2, -1);
01009     if ( status != X400_E_NOERROR ) return  (status);
01010     /* add other values to recip */
01011     status = add_content_recip_info (rp, recip2);
01012     if ( status != X400_E_NOERROR ) return  (status);
01013 
01014     /* add bcc recipient to message */
01015     status = X400mtRecipNew (mp, X400_RECIP_BCC, &rp);
01016     if ( status != X400_E_NOERROR ) exit (status);
01017     /* give recip an address */
01018     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip2, -1);
01019     if ( status != X400_E_NOERROR ) return  (status);
01020 
01021     /* add reply recipient to message */
01022     status = X400mtRecipNew (mp, X400_RECIP_REPLY, &rp);
01023     if ( status != X400_E_NOERROR ) exit (status);
01024     /* give recip an address */
01025     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip2, -1);
01026     if ( status != X400_E_NOERROR ) return  (status);
01027 
01028     /* add auth user to message */
01029     status = X400mtRecipNew (mp, X400_AUTH_ORIG, &rp);
01030     if ( status != X400_E_NOERROR ) return (status);
01031     /* give auth user an address */
01032     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, auth_orig, -1);
01033     if ( status != X400_E_NOERROR ) return  (status);
01034 
01035     return X400_E_NOERROR;
01036 }
01037 #endif
01038 
01039 static int build_env(
01040     struct X400mtMessage *mp
01041 )
01042 {
01043     int status;
01044 
01045     /* Envelope Attributes */
01046 
01047     /* Content Type: 2 or 22 */
01048     status = X400mtMsgAddIntParam (mp, X400_N_CONTENT_TYPE, def_content_type);
01049     if ( status != X400_E_NOERROR ) return (status);
01050 
01051 #ifdef WANT_EXTERNAL_CONTENT_TYPE
01052     status = X400mtMsgAddStrParam (mp, X400_S_EXTERNAL_CONTENT_TYPE, 
01053                                    def_ext_content_type, -1);
01054     if ( status != X400_E_NOERROR ) return (status);
01055 #endif
01056     
01057 #ifdef WANT_DL_EXP_HIST
01058     /*Add a DL expansion history*/
01059     {
01060         struct X400DLExpHist *hist;
01061         status = X400mtDLExpHistNew (mp, &hist);
01062         if ( status != X400_E_NOERROR ) return (status);
01063 
01064         status = X400DLExpHistAddStrParam (hist,
01065                                            X400_S_OR_ADDRESS,
01066                                            x400_default_gw_dlexphist1_or,
01067                                            -1);
01068         if ( status != X400_E_NOERROR ) return  (status);
01069 
01070         status = X400DLExpHistAddStrParam (hist,
01071                                            X400_S_DIRECTORY_NAME,
01072                                            x400_default_gw_dlexphist1_dn,
01073                                            -1);
01074         if ( status != X400_E_NOERROR ) return  (status);
01075         
01076         status = X400DLExpHistAddStrParam (hist,
01077                                            X400_S_DLEXP_TIME,
01078                                            "070801120000+0100",
01079                                            -1);
01080         if ( status != X400_E_NOERROR ) return  (status);
01081 
01082         
01083         status = X400mtDLExpHistNew (mp, &hist);
01084         if ( status != X400_E_NOERROR ) return (status);
01085 
01086         status = X400DLExpHistAddStrParam (hist,
01087                                            X400_S_OR_ADDRESS,
01088                                            x400_default_gw_dlexphist2_or,
01089                                            -1);
01090         if ( status != X400_E_NOERROR ) return  (status);
01091 
01092         status = X400DLExpHistAddStrParam (hist,
01093                                            X400_S_DIRECTORY_NAME,
01094                                            x400_default_gw_dlexphist2_dn,
01095                                            -1);
01096         if ( status != X400_E_NOERROR ) return  (status);
01097         
01098         status = X400DLExpHistAddStrParam (hist,
01099                                            X400_S_DLEXP_TIME,
01100                                            "070801120000+0100",
01101                                            -1);
01102         if ( status != X400_E_NOERROR ) return  (status);
01103         
01104         
01105     }
01106 #endif
01107     
01108 
01109 #ifdef USE_SEC_LABEL
01110     {
01111 
01112         /*If you are going to use security labels,
01113          *make sure the following variable points to the relevant xml file
01114          */
01115         const char* xml_filename = "seclabel.xml";
01116         char xml_content[XML_BUFSIZE];
01117         char str_content[STRING_BUFSIZE];
01118         int str_len = STRING_BUFSIZE;
01119         FILE *fd = NULL;
01120         
01121         /* Read in the security label XML file */
01122         fd = fopen(xml_filename,"r");
01123         if(fd == NULL) {
01124             fprintf(stderr,"Failed to open %s : %s\n",
01125                     xml_filename,strerror(errno));
01126         }
01127         
01128         fread(&xml_content,XML_BUFSIZE,1,fd);
01129 
01130         fclose(fd);
01131 
01132         status = SecLabelInit("Example program");
01133         if (status != SECLABEL_E_NOERROR) {
01134             fprintf(stderr, "SecLabelInit returned error %d\n", status);
01135             exit(1);
01136         }
01137         
01138         /* Use SecLabelParse to turn the XML into an octect string */
01139         status = SecLabelParse(xml_content,
01140                                str_content,
01141                                STRING_BUFSIZE,
01142                                &str_len);
01143         
01144         if (status != SECLABEL_E_NOERROR) {
01145             fprintf(stderr, "SecLabelParse returned error %d\n", status);
01146             exit(1);
01147         }
01148             
01149         /* Add the octect string to the message pointer */
01150         status = X400mtMsgAddStrParam (mp, X400_S_SECURITY_LABEL,
01151                                        str_content,str_len);
01152         if ( status != X400_E_NOERROR ) {
01153             fprintf (stderr, "x400mtMsgAddStrParam returned error: %s\n", X400mtError (status));
01154             exit (status);
01155         }
01156         
01157     }
01