examples/x400_mtsend_rep.c

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

00001 /*  Copyright (c) 2004-2006, 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_rep.c,v $ $Revision: 1.14 $ $Date: 2007/08/14 16:46:18 $ $State: Exp $
00012  *
00013  * $Log: x400_mtsend_rep.c,v $
00014  * Revision 1.14  2007/08/14 16:46:18  ldv
00015  * T070814B - Move X400_S_ARRIVAL_TIME to build_env, and use 2007 instead of 2004
00016  *
00017  * Revision 1.13  2007/08/14 15:48:58  ldv
00018  * T070814B - Move X400_S_ARRIVAL_TIME to build_env, and use 2007 instead of 2004
00019  *
00020  * Revision 1.12  2007/07/24 12:45:42  dbw
00021  * T070724D - Fix warnings
00022  *
00023  * Revision 1.11  2007/07/17 08:46:42  dbw
00024  * T070716H - Fix warnings
00025  *
00026  * Revision 1.10  2007/05/15 13:11:12  dbw
00027  * T070515D - Update/Add copyright
00028  *
00029  * Revision 1.9  2006/09/11 09:43:31  ir
00030  * T060825A - Add switch which accepts defaults (as overridden on the command line)
00031  *            stopping the prompts so that the programs can be run unattended.
00032  *
00033  * Revision 1.8  2006/07/28 09:05:22  ir
00034  * T060728A - Add -u switch to example progs to accept cmd line args without
00035  *            prompting.
00036  *
00037  * Revision 1.7  2005/11/03 11:55:08  tc
00038  * T051103A - Delete unnecessary Doxygen text.
00039  *
00040  * Revision 1.6  2005/10/12 10:43:01  ir
00041  * T051012A - Include <stdlib.h> for exit() prototype.
00042  *            Remove unused functions and prototypes.
00043  *            Remove unused variables.
00044  *
00045  * Revision 1.5  2005/10/10 07:57:16  ir
00046  * T051007C - Call get_args() to parse cmdline args.
00047  *
00048  * Revision 1.4  2005/09/23 12:30:09  ldv
00049  * T050922E - Move forward in time the latest_delivery_time to avoid problems
00050  *
00051  * Revision 1.3  2005/08/16 14:48:17  ldv
00052  * T050815V - Remove duplicate setting of X400_att.X400_S_MESSAGE_IDENTIFIER
00053  *
00054  * Revision 1.2  2004/08/16 15:43:34  ir
00055  * T040812E - Tidy up doxygen annotations.
00056  *
00057  * Revision 1.1  2004/07/09 09:20:27  ldv
00058  * T040708C - New file
00059  *
00060  *
00061  * Simple example program for transferring a report into the MTA
00062  *
00063  */
00064 
00065 #include <stdio.h>
00066 #include <stdlib.h>
00067 
00068 #include <x400_mtapi.h>
00069 #include "example.h"
00070 
00071 /* local functions */
00072 static int send_report (
00073     int         drtype 
00074 );
00075 static int add_recips_positive(
00076     struct X400mtMessage *mp
00077 );
00078 static int add_recips_negative(
00079     struct X400mtMessage *mp
00080 );
00081 static int build_env(
00082     struct X400mtMessage *mp
00083 );
00084 static int add_env_recip_info(
00085     struct X400Recipient *rp
00086 );
00087 static void usage(void);
00088 
00089 static int rno = 1;
00090 
00091 static int do_redi_hist(
00092     struct X400Recipient *rp
00093 );
00094 
00095 static int do_redi_hist_env(
00096     struct X400mtMessage *msg
00097 );
00098 
00099 static void do_origandl(
00100     struct X400mtMessage *msg
00101 );
00102 
00103 static int add_reporting_dl_name(
00104     struct X400mtMessage *mp
00105 );
00106 
00107 /* These are the data items used */
00108 
00109 /* The O/R addresses used are intended to be compatible with those
00110  * used in the quick install scripts mktailor.tcl, and createmhs.tcl.
00111  * Change this value to the name of your host.  */
00112 #define HOSTNAME "dhcp-164"
00113 
00114 static char *optstr = "uo:O:r:g:G:c:l:R:y:C:iaqsAv";
00115 
00116 /* this value is used for the originator of the message */
00117 static const char orig_s[] = "/S=x400test-orig/OU="HOSTNAME"/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00118 static const char *orig = orig_s;
00119 
00120 /* default recipients */
00121 static const char recip_s[] = "/S=x400test-recip2/OU="HOSTNAME"/O=GatewayMTA/PRMD=TestPRMD/ADMD=TestADMD/C=GB/";
00122 static const char *recip = recip_s;
00123 
00124 
00125 /* default envelope integer values */
00126 static int def_content_type = 2;
00127 static int def_bool = 0;
00128 static int def_priority = 2;
00129 
00130 /* default envelope string values */
00131 static const char def_utc[] = "080924120000";
00132 static const char msg_id[] = "/PRMD=TestPRMD/ADMD=TestADMD/C=GB/;"HOSTNAME".2810401-030924.140212";
00133 static const char content_id[] = "030924.140212";
00134 static const char latest_del_time[] = "080927120000Z";
00135 
00136 /* default content integer types */
00137 static const int importance = 2;
00138 static const int sensitivity = 3;
00139 static const int autoforwarded = 1;
00140 
00141 /* default content string types */
00142 static const char subject[] = "A Test Message";
00143 static const char text[] = "First line\r\nSecond line\r\n";
00144 static const char ipm_id[] = "1064400656.24922*";
00145 static const char ipm_rep_id[] = "1064400656.24923*";
00146 static const char ipm_obs_id[] = "1064400656.24924*";
00147 static const char ipm_rel_id[] = "1064400656.24925*";
00148 static const char orig_ref[] = "orig-ref-val";
00149 
00153 int main( 
00154     int         argc,
00155     char      **argv
00156 ) 
00157 {
00158     int drtype;
00159 
00160     orig = strdup(x400_default_gw_originator);
00161     recip = strdup(x400_default_gw_recipient);
00162 
00163     if (get_args(argc, argv, optstr)) {
00164         usage();
00165         exit(-1);
00166     }
00167 
00168     if (x400_channel == NULL) {
00169         printf("You must specify an X.400 channel\n");
00170         usage();
00171         exit(-1);
00172     }
00173 
00174     printf("Delivery Report type (0 = Positive, 1 = Negative): ");
00175     drtype = ic_fgetc(x400_contype, stdin);
00176     if ((drtype != '0') && (drtype != '1'))
00177       exit(1);
00178     
00179     drtype -= '0';
00180 
00181     return send_report(drtype);
00182 }
00183 
00184 static int send_report (
00185     int         drtype 
00186 ) 
00187 {
00188     int status;
00189     struct X400mtSession *sp;
00190     struct X400mtMessage *mp;
00191 
00192     if (x400_channel == NULL) {
00193         fprintf (stderr, "No x400_channel value set in x400tailor file");
00194     exit(1);
00195     }
00196 
00197     /* open a new session */
00198     status = X400mtOpen (x400_channel, &sp);
00199     if ( status != X400_E_NOERROR ) {
00200         fprintf (stderr, "Error in Open: %s\n", X400mtError (status));
00201         exit (status);
00202     }
00203 
00204     /* start preparing a new report */
00205     status = X400mtMsgNew (sp, X400_MSG_REPORT, &mp);
00206     /* Should report all errors as above */
00207     if ( status != X400_E_NOERROR ) exit (status);
00208 
00209     /* setup originator using a single string */
00210      status = X400mtMsgAddStrParam (mp, X400_S_OR_ADDRESS, orig, -1);
00211     if ( status != X400_E_NOERROR ) exit (status);
00212 
00213 
00214     status = add_reporting_dl_name(mp);
00215     if ( status != X400_E_NOERROR ) exit (status);
00216     
00217     /* add various envelope and header recipients into the report */
00218     if (drtype == 0)
00219       status = add_recips_positive(mp);
00220     else
00221       status = add_recips_negative(mp);
00222     if ( status != X400_E_NOERROR ) exit (status);
00223 
00224 #define ADD_TRACE_INFO 1
00225 #ifdef  ADD_TRACE_INFO
00226  {
00227      struct X400TraceInfo *info1; /*Will contain all trace information */
00228  
00229      int status;
00230 
00231      status = X400mtTraceInfoNew(mp,&info1,X400_SUBJECT_TRACE_INFO);
00232      if (status !=X400_E_NOERROR) {
00233          fprintf(stderr,"Failed to allocate new trace info object \n");
00234          exit(status);
00235      }
00236      
00237      
00238      status =  X400TraceInfoAddStrParam (info1,
00239                                          X400_S_GLOBAL_DOMAIN_ID,
00240                                          "/PRMD=wibble/ADMD=TestADMD/C=GB/",
00241                                          -1);
00242      if (status !=X400_E_NOERROR) {
00243          fprintf(stderr,
00244                  "Failed to add X400_S_GLOBAL_DOMAIN_ID to trace info\n");
00245          exit(status);
00246      }
00247 
00248      status =  X400TraceInfoAddStrParam (info1,
00249                                          X400_S_DSI_ARRIVAL_TIME,
00250                                          "071121125704Z",
00251                                          -1);
00252      if (status !=X400_E_NOERROR) {
00253          fprintf(stderr,
00254                  "Failed to add X400_S_DSI_ARRIVAL_TIME to trace info\n");
00255          exit(status);
00256      }
00257      
00258      /*Add optional*/
00259      status =  X400TraceInfoAddStrParam (info1,
00260                                          X400_S_DSI_ATTEMPTED_DOMAIN,
00261                                          "/PRMD=atmpdom/ADMD=TestADMD/C=GB/",
00262                                          -1);
00263      if (status !=X400_E_NOERROR) {
00264          fprintf(stderr,
00265                  "Failed to add X400_S_DSI_ATTEMPTED_DOMAIN to trace info\n");
00266          exit(status);
00267      }
00268      
00269      
00270      /*Add optional*/
00271      status =  X400TraceInfoAddStrParam (info1,
00272                                          X400_S_DSI_AA_DEF_TIME,
00273                                          "071122125704Z",
00274                                          -1);
00275      if (status !=X400_E_NOERROR) {
00276          fprintf(stderr,
00277                  "Failed to add X400_S_DSI_AA_DEF_TIME to trace info\n");
00278          exit(status);
00279      }
00280  }
00281 #endif
00282 
00283  
00284  
00285     /* build rest of the report envelope */
00286     status = build_env(mp);
00287     if ( status != X400_E_NOERROR ) exit (status);
00288 
00289     
00290     /* send the report */
00291     status = X400mtMsgSend (mp);
00292     if ( status != X400_E_NOERROR ) {
00293         fprintf (stderr, "Error in MsgSend: %s\n", X400mtError (status));
00294         exit (status);
00295     }
00296 
00297     /* delete the message structure */
00298     status = X400mtMsgDelete (mp);
00299     if ( status != X400_E_NOERROR ) exit (status);
00300 
00301     mp = NULL;
00302 
00303     /* close the API session */
00304     return X400mtClose (sp);
00305 }
00306 
00307 static int add_recips_positive(
00308     struct X400mtMessage *mp
00309 )
00310 {
00311     struct X400Recipient *rp;
00312     int status;
00313 
00314     /* add new recipient to the report envelope */
00315     status = X400mtRecipNew (mp, X400_RECIP_ENVELOPE, &rp);
00316     if ( status != X400_E_NOERROR ) return  (status);
00317     /* give recip an address */
00318     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00319     if ( status != X400_E_NOERROR ) return  (status);
00320     /* add other values to recip */
00321     status = add_env_recip_info (rp);
00322     if ( status != X400_E_NOERROR ) return  (status);
00323 
00324     /* add new recipient to the report content */
00325     status = X400mtRecipNew (mp, X400_RECIP_REPORT, &rp);
00326     if ( status != X400_E_NOERROR ) return  (status);
00327     /* give recip an address */
00328     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00329     if ( status != X400_E_NOERROR ) return  (status);
00330     /* add other values to recip */
00331     status = add_env_recip_info (rp);
00332     if ( status != X400_E_NOERROR ) return  (status);
00333 
00334     /* add the arrival time for this recipient */
00335     status = X400mtRecipAddStrParam (rp, X400_S_ARRIVAL_TIME, "070701140026+0100", -1);
00336     if ( status != X400_E_NOERROR ) {
00337         fprintf (stderr, "X400mtMsgAddStrParam returned error: %s\n", X400mtError (status));
00338         return (status);
00339     }
00340 
00341     /* add the delivery time for this recipient (positive dr) */
00342     status = X400mtRecipAddStrParam (rp, X400_S_MESSAGE_DELIVERY_TIME, "040701140026+0100", -1);
00343     if ( status != X400_E_NOERROR ) {
00344         fprintf (stderr, "X400mtMsgAddStrParam returned error: %s\n", X400mtError (status));
00345         return (status);
00346     }
00347     
00348     /* add the CEIT for this recipient  */
00349     status = X400mtRecipAddStrParam (rp,X400_S_CONVERTED_ENCODED_INFORMATION_TYPES, "ia5-text", -1);
00350     if ( status != X400_E_NOERROR ) {
00351         fprintf (stderr, "X400mtMsgAddStrParam returned error: %s\n", X400mtError (status));
00352         return (status);
00353     }
00354 #define USE_REDIRECTION_HISTORY 1
00355 #ifdef  USE_REDIRECTION_HISTORY
00356     /* Add redirection history for this recipient (8.3.1.1.1.5)*/
00357     do_redi_hist(rp);
00358 
00359    
00360 #endif
00361 
00362     return X400_E_NOERROR;
00363 }
00364 
00365 
00366 static int add_recips_negative(
00367     struct X400mtMessage *mp
00368 )
00369 {
00370     struct X400Recipient *rp;
00371     int status;
00372 
00373     /* add new recipient to the report envelope */
00374     status = X400mtRecipNew (mp, X400_RECIP_ENVELOPE, &rp);
00375     if ( status != X400_E_NOERROR ) return  (status);
00376     /* give recip an address */
00377     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00378     if ( status != X400_E_NOERROR ) return  (status);
00379     /* add other values to recip */
00380     status = add_env_recip_info (rp);
00381     if ( status != X400_E_NOERROR ) return  (status);
00382 
00383     /* add new recipient to the report content */
00384     status = X400mtRecipNew (mp, X400_RECIP_REPORT, &rp);
00385     if ( status != X400_E_NOERROR ) return  (status);
00386     /* give recip an address */
00387     status = X400mtRecipAddStrParam (rp, X400_S_OR_ADDRESS, recip, -1);
00388     if ( status != X400_E_NOERROR ) return  (status);
00389     /* add other values to recip */
00390     status = add_env_recip_info (rp);
00391     if ( status != X400_E_NOERROR ) return  (status);
00392 
00393     /* add the arrival time for this recipient */
00394     status = X400mtRecipAddStrParam (rp, X400_S_ARRIVAL_TIME, "070701140026+0100", -1);
00395     if ( status != X400_E_NOERROR ) {
00396         fprintf (stderr, "X400mtMsgAddStrParam returned error: %s\n", X400mtError (status));
00397         return (status);
00398     }
00399 
00400     /* add the supplementary info for this recipient (negative dr) */
00401     status = X400mtRecipAddStrParam (rp, X400_S_SUPPLEMENTARY_INFO, "Couldn't delivery message", -1);
00402     if ( status != X400_E_NOERROR ) {
00403         fprintf (stderr, "X400mtMsgAddStrParam returned error: %s\n", X400mtError (status));
00404         return (status);
00405     }
00406 
00407     /* add the non-delivery reason for this recipient (negative dr) */
00408     status = X400mtRecipAddIntParam (rp, X400_N_NON_DELIVERY_REASON, 1);
00409     if ( status != X400_E_NOERROR ) {
00410         fprintf (stderr, "X400mtMsgAddIntParam returned error: %s\n", X400mtError (status));
00411         return (status);
00412     }
00413 
00414     /* add the non-delivery diagnostic for this recipient (negative dr) */
00415     status = X400mtRecipAddIntParam (rp, X400_N_NON_DELIVERY_DIAGNOSTIC, 2);
00416     if ( status != X400_E_NOERROR ) {
00417         fprintf (stderr, "X400mtMsgAddIntParam returned error: %s\n", X400mtError (status));
00418         return (status);
00419     }
00420 
00421     return X400_E_NOERROR;   
00422 }
00423 
00424 static int build_env(
00425     struct X400mtMessage *mp
00426 )
00427 {
00428     int status;
00429 
00430     /* Envelope Attributes */
00431 
00432     /* Content Type: 2 or 22 */
00433     status = X400mtMsgAddIntParam (mp, X400_N_CONTENT_TYPE, def_content_type);
00434     if ( status != X400_E_NOERROR ) return (status);
00435 
00436     /* X400_N_CONTENT_LENGTH is probe only */
00437 
00438     /* Priority: 0 - normal, 1 - non-urgent, 2 - urgent */
00439     status = X400mtMsgAddIntParam (mp, X400_N_PRIORITY, def_priority);
00440     if ( status != X400_E_NOERROR ) return (status);
00441 
00442     /*  Disclosure of recipients: 0 - no, 1 - yes */
00443     status = X400mtMsgAddIntParam (mp, X400_N_DISCLOSURE, 1);
00444     if ( status != X400_E_NOERROR ) return (status);
00445 
00446     /* Implicit conversion prohibited: 0 - no, 1 - yes */
00447     status = X400mtMsgAddIntParam (mp, X400_N_IMPLICIT_CONVERSION_PROHIBITED, def_bool);
00448     if ( status != X400_E_NOERROR ) return (status);
00449 
00450     /* Alternate recipient allowed: 0 - no, 1 - yes */
00451     status = X400mtMsgAddIntParam (mp, X400_N_ALTERNATE_RECIPIENT_ALLOWED, def_bool);
00452     if ( status != X400_E_NOERROR ) return (status);
00453 
00454     /* Content return request: 0 - no, 1 - yes */
00455     /* hmm - 1 is headers - what does that do in X.400 ? */
00456     status = X400mtMsgAddIntParam (mp, X400_N_CONTENT_RETURN_REQUEST, 1);
00457     if ( status != X400_E_NOERROR ) return (status);
00458 
00459     /* Recipient reassignment prohibited: 0 - no, 1 - yes */
00460     status = X400mtMsgAddIntParam (mp, X400_N_RECIPIENT_REASSIGNMENT_PROHIBITED, def_bool);
00461     if ( status != X400_E_NOERROR ) return (status);
00462 
00463     /* Distribution List expansion prohibited: 0 - no, 1 - yes */
00464     status = X400mtMsgAddIntParam (mp, X400_N_DL_EXPANSION_PROHIBITED, def_bool);
00465     if ( status != X400_E_NOERROR ) return (status);
00466 
00467     /* Conversion with loss prohibited: 0 - no, 1 - yes */
00468     status = X400mtMsgAddIntParam (mp, X400_N_CONVERSION_WITH_LOSS_PROHIBITED, def_bool);
00469     if ( status != X400_E_NOERROR ) return (status);
00470 
00471     /* string params */
00472 
00473     /* Message Identifier. In RFC 2156 String form */
00474     status = X400mtMsgAddStrParam (mp, X400_S_MESSAGE_IDENTIFIER, msg_id, -1);
00475     if ( status != X400_E_NOERROR ) return (status);
00476 
00477     /* Content Identifier */
00478     status = X400mtMsgAddStrParam (mp, X400_S_CONTENT_IDENTIFIER, content_id, -1);
00479     if ( status != X400_E_NOERROR ) return (status);
00480 
00481     /*  Subject Identifier, the Message Identifier of the original message */
00482     status = X400mtMsgAddStrParam (mp, X400_S_SUBJECT_IDENTIFIER, msg_id, -1);
00483     if ( status != X400_E_NOERROR ) return (status);
00484 
00485     /* 
00486      * X400_S_ORIGINAL_ENCODED_INFORMATION_TYPES 
00487      * X400_S_MESSAGE_SUBMISSION_TIME 
00488      * X400_S_MESSAGE_DELIVERY_TIME 
00489      * are read only, so don't add them 
00490      */
00491 
00492     /*  Latest Delivery Time: UTCTime format YYMMDDHHMMSS<zone> */
00493     status = X400mtMsgAddStrParam (mp, X400_S_LATEST_DELIVERY_TIME, latest_del_time, -1);
00494     if ( status != X400_E_NOERROR ) return (status);
00495     
00496 
00497 #ifdef  USE_REDIRECTION_HISTORY
00498     /*Add redirection history for the envelope (8.3.1.2.1.5) */
00499     do_redi_hist_env(mp);
00500 #endif
00501 
00502     do_origandl(mp);
00503     
00504     /* all OK */
00505     return X400_E_NOERROR;
00506 }
00507 
00508 
00509 static int add_env_recip_info(
00510     struct X400Recipient *rp
00511 )
00512 {
00513     int status;
00514 
00515     /* add attributes to recipient in envelope */
00516     status = X400mtRecipAddIntParam (rp, X400_N_RESPONSIBILITY, 1);
00517     if ( status != X400_E_NOERROR ) return  (status);
00518 
00519     status = X400mtRecipAddIntParam (rp, X400_N_MTA_REPORT_REQUEST, 3);
00520     if ( status != X400_E_NOERROR ) return  (status);
00521 
00522     status = X400mtRecipAddIntParam (rp, X400_N_REPORT_REQUEST, 2);
00523     if ( status != X400_E_NOERROR ) return  (status);
00524 
00525     status = X400mtRecipAddIntParam (rp, X400_N_ORIGINAL_RECIPIENT_NUMBER, rno);
00526     rno++;
00527     if ( status != X400_E_NOERROR ) return  (status);
00528 
00529     return X400_E_NOERROR;
00530 }
00531 
00532 
00533 static void usage(void) {
00534     printf("usage: %s\n", optstr);
00535     printf("\t where:\n");
00536     printf("\t -u : Don't prompt to override defaults \n");
00537     printf("\t -o : Originator \n");
00538     printf("\t -O : Originator Return Address \n");
00539     printf("\t -r : Recipient\n");
00540     printf("\t -c : X.400 passive channel\n");
00541     printf("\t -l : Logline\n");
00542     printf("\t -R : Reports (0 - never, 1 - always, 2 - always NDR \n");
00543     printf("\t -y : Priority (0 - normal, 1 - non-urgent, 2 - urgent \n");
00544     printf("\t -C : Content Type (2/22/772/OID) \n");
00545     printf("\t -i : Implicit conversion prohibited = TRUE \n");
00546     printf("\t -a : Alternate Recipient Prohibited = TRUE \n");
00547     printf("\t -q : Content Return Request = TRUE \n");
00548     printf("\t -s : Disclosure of Recipient = FALSE \n");
00549     printf("\t -A : Recipient Reassignment Prohibited = FALSE \n");
00550     printf("\t -v : Conversion with Loss Prohibited = FALSE \n");
00551     return;
00552 }
00553 
00554 
00555 static int do_redi_hist(
00556     struct X400Recipient *rp
00557 )
00558  {
00559      struct X400RediHist *hist1; 
00560      struct X400RediHist *hist2; 
00561      int status;
00562 
00563      status = X400RediHistNew(rp,&hist1);
00564      if (status !=X400_E_NOERROR) {
00565          fprintf(stderr,"Failed to allocate new trace info object \n");
00566          exit(status);
00567      }
00568      
00569      /* Add Redirection History time */
00570      status =  X400RediHistAddStrParam (hist1,
00571                                         X400_S_REDIRECTION_TIME,
00572                                         "071121125704Z",
00573                                         -1);
00574      if (status !=X400_E_NOERROR) {
00575          fprintf(stderr,
00576                  "Failed to add X400_S_REDIRECTION_TIME to Redirection Hist\n");
00577          exit(status);
00578      }
00579 
00580      status =  X400RediHistAddStrParam (hist1,
00581                                         X400_S_OR_ADDRESS,
00582                                         "/cn=redihist/prmd=TestPRMD/admd=TestPRMD/C=gb",
00583                                         -1);
00584      if (status !=X400_E_NOERROR) {
00585          fprintf(stderr,
00586                  "Failed to add  X400_S_OR_ADDRESS to Redirection Hist\n");
00587          exit(status);
00588      }
00589 
00590      status =  X400RediHistAddStrParam (hist1,
00591                                         X400_S_DIRECTORY_NAME,
00592                                         "CN=redihist,c=GB",
00593                                         -1);
00594      if (status !=X400_E_NOERROR) {
00595          fprintf(stderr,
00596                  "Failed to add X400_S_DIRECTORY_NAME to Redirection Hist\n");
00597          exit(status);
00598      }
00599      
00600      
00601      status = X400RediHistAddIntParam(hist1,
00602                                       X400_N_REDIRECTION_REASON,
00603                                       X400_RR_ALIAS);
00604      if (status !=X400_E_NOERROR) {
00605          fprintf(stderr,
00606                  "Failed to add  X400_N_REDIRECTION_REASON to trace info\n");
00607          exit(status);
00608      }
00609 
00610      /*hist2*/
00611      
00612      status = X400RediHistNew(rp,&hist2);
00613      if (status !=X400_E_NOERROR) {
00614          fprintf(stderr,"Failed to allocate new trace info object \n");
00615          exit(status);
00616      }
00617      
00618      /* Add Redirection History time */
00619      status =  X400RediHistAddStrParam (hist2,
00620                                         X400_S_REDIRECTION_TIME,
00621                                         "071121125714Z",
00622                                         -1);
00623      if (status !=X400_E_NOERROR) {
00624          fprintf(stderr,
00625                  "Failed to add X400_S_REDIRECTION_TIME to Redirection Hist\n");
00626          exit(status);
00627      }
00628 
00629      status =  X400RediHistAddStrParam (hist2,
00630                                         X400_S_OR_ADDRESS,
00631                                         "/cn=redihist2/prmd=TestPRMD/admd=TestPRMD/C=gb",
00632                                         -1);
00633      if (status !=X400_E_NOERROR) {
00634          fprintf(stderr,
00635                  "Failed to add  X400_S_OR_ADDRESS to Redirection Hist\n");
00636          exit(status);
00637      }
00638 
00639      status =  X400RediHistAddStrParam (hist2,
00640                                         X400_S_DIRECTORY_NAME,
00641                                         "CN=redihist2,c=GB",
00642                                         -1);
00643      if (status !=X400_E_NOERROR) {
00644          fprintf(stderr,
00645                  "Failed to add X400_S_DIRECTORY_NAME to Redirection Hist\n");
00646          exit(status);
00647      }
00648      
00649      
00650      status = X400RediHistAddIntParam(hist2,
00651                                       X400_N_REDIRECTION_REASON,
00652                                       X400_RR_RECIP_ASSIGNED_ALT_RECIP);
00653      if (status !=X400_E_NOERROR) {
00654          fprintf(stderr,
00655                  "Failed to add  X400_N_REDIRECTION_REASON to "
00656                  "Redirection Hist\n");
00657          exit(status);
00658      }
00659      return X400_E_NOERROR;
00660 }
00661 
00662 static int do_redi_hist_env(
00663     struct X400mtMessage *msg
00664 )
00665  {
00666      struct X400RediHist *hist1; 
00667      struct X400RediHist *hist2; 
00668      int status;
00669 
00670      status = X400mtRediHistNewEnv(msg,&hist1);
00671      if (status !=X400_E_NOERROR) {
00672          fprintf(stderr,"Failed to allocate new trace info object \n");
00673          exit(status);
00674      }
00675      
00676      /* Add Redirection History time */
00677      status =  X400RediHistAddStrParam (hist1,
00678                                         X400_S_REDIRECTION_TIME,
00679                                         "071121125704Z",
00680                                         -1);
00681      if (status !=X400_E_NOERROR) {
00682          fprintf(stderr,
00683                  "Failed to add X400_S_REDIRECTION_TIME to Redirection Hist\n");
00684          exit(status);
00685      }
00686 
00687      status =  X400RediHistAddStrParam (hist1,
00688                                         X400_S_OR_ADDRESS,
00689                                         "/cn=redihist/prmd=TestPRMD/admd=TestPRMD/C=gb",
00690                                         -1);
00691      if (status !=X400_E_NOERROR) {
00692          fprintf(stderr,
00693                  "Failed to add  X400_S_OR_ADDRESS to Redirection Hist\n");
00694          exit(status);
00695      }
00696 
00697      status =  X400RediHistAddStrParam (hist1,
00698                                         X400_S_DIRECTORY_NAME,
00699                                         "CN=redihist,c=GB",
00700                                         -1);
00701      if (status !=X400_E_NOERROR) {
00702          fprintf(stderr,
00703                  "Failed to add X400_S_DIRECTORY_NAME to Redirection Hist\n");
00704          exit(status);
00705      }
00706      
00707      
00708      status = X400RediHistAddIntParam(hist1,
00709                                       X400_N_REDIRECTION_REASON,
00710                                       X400_RR_ALIAS);
00711      if (status !=X400_E_NOERROR) {
00712          fprintf(stderr,
00713                  "Failed to add  X400_N_REDIRECTION_REASON to trace info\n");
00714          exit(status);
00715      }
00716 
00717      /*hist2*/
00718      
00719      status = X400mtRediHistNewEnv(msg,&hist2);
00720      if (status !=X400_E_NOERROR) {
00721          fprintf(stderr,"Failed to allocate new trace info object \n");
00722          exit(status);
00723      }
00724      
00725      /* Add Redirection History time */
00726      status =  X400RediHistAddStrParam (hist2,
00727                                         X400_S_REDIRECTION_TIME,
00728                                         "071121125714Z",
00729                                         -1);
00730      if (status !=X400_E_NOERROR) {
00731          fprintf(stderr,
00732                  "Failed to add X400_S_REDIRECTION_TIME to Redirection Hist\n");
00733          exit(status);
00734      }
00735 
00736      status =  X400RediHistAddStrParam (hist2,
00737                                         X400_S_OR_ADDRESS,
00738                                         "/cn=redihist2/prmd=TestPRMD/admd=TestPRMD/C=gb",
00739                                         -1);
00740      if (status !=X400_E_NOERROR) {
00741          fprintf(stderr,
00742                  "Failed to add  X400_S_OR_ADDRESS to Redirection Hist\n");
00743          exit(status);
00744      }
00745 
00746      status =  X400RediHistAddStrParam (hist2,
00747                                         X400_S_DIRECTORY_NAME,
00748                                         "CN=redihist2,c=GB",
00749                                         -1);
00750      if (status !=X400_E_NOERROR) {
00751          fprintf(stderr,
00752                  "Failed to add X400_S_DIRECTORY_NAME to Redirection Hist\n");
00753          exit(status);
00754      }
00755      
00756      
00757      status = X400RediHistAddIntParam(hist2,
00758                                       X400_N_REDIRECTION_REASON,
00759                                       X400_RR_RECIP_ASSIGNED_ALT_RECIP);
00760      if (status !=X400_E_NOERROR) {
00761          fprintf(stderr,
00762                  "Failed to add  X400_N_REDIRECTION_REASON to "
00763                  "Redirection Hist\n");
00764          exit(status);
00765      }
00766      return X400_E_NOERROR;
00767 }   
00768 
00769 static void do_origandl(
00770     struct X400mtMessage *msg
00771 )
00772 {
00773     struct X400ORandDL *or_and_dl1;
00774     struct X400ORandDL *or_and_dl2;
00775     
00776     const char *origin_or_address = "/cn=origandlorig/prmd=TestPRMD/admd=TestPRMD/C=gb";
00777     const char *origin_dn_address = "CN=origandlorig,c=GB";
00778     int status;
00779     
00780     status = X400mtORandDLNew(msg,&or_and_dl1);
00781     if (status !=X400_E_NOERROR) {
00782         fprintf(stderr,"Failed to allocate new OR Address and DL "
00783                 "expansion object \n");
00784         exit(status);
00785     }
00786      
00787     /* Add Origin or expansion time */
00788     status = X400ORandDLAddStrParam (or_and_dl1,
00789                                      X400_S_ORIG_OR_EXAP_TIME,
00790                                      "071121125704Z",
00791                                      -1);
00792     if (status != X400_E_NOERROR) {
00793         fprintf(stderr,
00794                 "Failed to add X400_S_ORIG_OR_EXAP_TIME "
00795                 "to X400ORandDL\n");
00796         exit(status);
00797     }
00798     
00799     /* originator or dl_name */
00800 
00801     /* Add Origin or expansion time */
00802     status = X400ORandDLAddStrParam (or_and_dl1,
00803                                      X400_S_OR_ADDRESS,
00804                                      origin_or_address,
00805                                      -1);
00806     if (status != X400_E_NOERROR) {
00807         fprintf(stderr,
00808                 "Failed to add X400_S_OR_ADDRESS "
00809                 "to X400ORandDL\n");
00810         exit(status);
00811     }
00812 
00813   
00814     status = X400ORandDLAddStrParam (or_and_dl1,
00815                                      X400_S_DIRECTORY_NAME,
00816                                      origin_dn_address,
00817                                      -1);
00818     if (status != X400_E_NOERROR) {
00819         fprintf(stderr,
00820                 "Failed to add X400_S_DIRECTORY_NAME "
00821                 "to X400ORandDL\n");
00822         exit(status);
00823     }
00824     status = X400mtORandDLNew(msg,&or_and_dl2);
00825     if (status !=X400_E_NOERROR) {
00826         fprintf(stderr,"Failed to allocate new OR Address and DL "
00827                 "expansion object \n");
00828         exit(status);
00829     }
00830      
00831     /* Add Origin or expansion time */
00832     status = X400ORandDLAddStrParam (or_and_dl2,
00833                                      X400_S_ORIG_OR_EXAP_TIME,
00834                                      "091121125704Z",
00835                                      -1);
00836     if (status != X400_E_NOERROR) {
00837         fprintf(stderr,
00838                 "Failed to add X400_S_ORIG_OR_EXAP_TIME "
00839                 "to X400ORandDL\n");
00840         exit(status);
00841     }
00842     
00843     /* originator or dl_name */
00844 
00845     /* Add Origin or expansion time */
00846     status = X400ORandDLAddStrParam (or_and_dl2,
00847                                      X400_S_OR_ADDRESS,
00848                                      origin_or_address,
00849                                      -1);
00850     if (status != X400_E_NOERROR) {
00851         fprintf(stderr,
00852                 "Failed to add X400_S_OR_ADDRESS "
00853                 "to X400ORandDL\n");
00854         exit(status);
00855     }
00856 
00857   
00858     status = X400ORandDLAddStrParam (or_and_dl2,
00859                                      X400_S_DIRECTORY_NAME,
00860                                      origin_dn_address,
00861                                      -1);
00862     if (status != X400_E_NOERROR) {
00863         fprintf(stderr,
00864                 "Failed to add X400_S_DIRECTORY_NAME "
00865                 "to X400ORandDL\n");
00866         exit(status);
00867     }
00868 }
00869    
00870 
00871 static int add_reporting_dl_name(
00872     struct X400mtMessage *mp
00873 )
00874 {
00875     int status;
00876     struct X400Recipient *rp = NULL;
00877     
00878     /* add new recipient to message */
00879     status = X400mtRecipNew (mp, X400_REPORTING_DL_NAME, &rp);
00880     if ( status != X400_E_NOERROR ) return  (status);
00881     
00882     /* give recip an address */
00883     status = X400mtRecipAddStrParam (rp,
00884                                      X400_S_OR_ADDRESS,
00885         "cn=reportdlname/prmd=TestPRMD/admd=TestPRMD/C=gb",
00886                                      -1);
00887     if ( status != X400_E_NOERROR ) return  (status);
00888 
00889       status = X400mtRecipAddStrParam (rp,
00890                                        X400_S_DIRECTORY_NAME,
00891                                        "ou=reportingdlname,C=gb",
00892                                        -1);
00893     if ( status != X400_E_NOERROR ) return  (status);
00894     
00895     
00896     return X400_E_NOERROR;
00897 }
Copyright © 2008 Isode privacy   feedback Subscribe to our rss newsfeed