x400_msraa.c
1 /* Copyright (c) 2005-2009, Isode Limited, London, England.
2  * All rights reserved.
3  *
4  * Acquisition and use of this software and related materials for any
5  * purpose requires a written licence agreement from Isode Limited,
6  * or a written licence from an organisation licenced by Isode Limited
7  * to grant such a licence.
8  *
9  */
10 
11 /*
12  *
13  * @VERSION@
14  * Simple example program for registering an auto-action in the message store
15  */
16 
17 
18 #include <stdio.h>
19 #include <x400_msapi.h>
20 #include "example.h"
21 
22 static void usage(void);
23 
24 static char *optstr = "u37m:d:p:w:M:D:P:W:";
25 
29 int main (
30  int argc,
31  char **argv
32 )
33 {
34  char buffer[BUFSIZ];
35  char pa[BUFSIZ];
36  char orn[BUFSIZ];
37  char password[BUFSIZ];
38  int status;
39  int nummsg;
40  struct X400msSession *sp;
41  struct X400Recipient *rp;
42  int contype;
43  char *def_oraddr;
44  char *def_dn;
45  char *def_pa;
46  char autoaction;
47 
48  if (get_args(argc, argv, optstr)) {
49  usage();
50  exit(-1);
51  }
52 
53  printf("Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
54  contype = ic_fgetc(x400_contype, stdin);
55  if (contype != 10)
56  ic_fgetc(x400_contype, stdin);
57 
58  if ( contype < '0' || '2' < contype )
59  contype = x400_contype;
60  else
61  contype -= '0';
62 
63  if (contype == 0) {
64  def_oraddr = x400_ms_user_addr;
65  def_dn = x400_ms_user_dn;
66  def_pa = x400_ms_presentation_address;
67  } else {
68  def_oraddr = x400_mta_user_addr;
69  def_dn = x400_mta_user_dn;
70  def_pa = x400_mta_presentation_address;
71  }
72 
73  printf("Your ORAddress [%s] > ", def_oraddr);
74  ic_fgets (orn, sizeof orn, stdin);
75 
76  if ( orn[strlen(orn)-1] == '\n' )
77  orn[strlen(orn)-1] = '\0';
78 
79  if (orn[0] == '\0')
80  strcpy(orn, def_oraddr);
81 
82  /* Prompt for password; note: reflected. */
83  printf ("Password [%s]: ",
84  contype == 0 ? x400_p7_password : x400_p3_password);
85  if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
86  exit (1);
87 
88  if (buffer[strlen(buffer)-1] == '\n' )
89  buffer[strlen(buffer)-1] = '\0';
90  if (buffer[0] == '\0')
91  strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
92  strcpy(password, buffer);
93 
94  /* Presentation address */
95  printf("Presentation Address [%s] > ", def_pa);
96  ic_fgets (pa, sizeof pa, stdin);
97 
98  if ( pa[strlen(pa)-1] == '\n' )
99  pa[strlen(pa)-1] = '\0';
100 
101  if (pa[0] == '\0')
102  strcpy(pa, def_pa);
103 
104  /* Register or deregister the autoaction */
105  printf("Register or Deregister the AutoAction ? (R = Register, D = Deregister): ");
106  if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
107  exit (1);
108  autoaction = buffer[0];
109  if ((autoaction != 'R') && (autoaction != 'D'))
110  exit(1);
111 
112  /* open the session */
113  status = X400msOpen (contype, orn, def_dn, password, pa, &nummsg, &sp);
114  if ( status != X400_E_NOERROR ) {
115  fprintf (stderr, "Error in Open: %s\n", X400msError (status));
116  exit (status);
117  }
118 
119  /* setup logging from $(ETCDIR)x400api.xml or $(SHAREDIR)x400api.xml */
120  X400msSetStrDefault(sp, X400_S_LOG_CONFIGURATION_FILE, "x400api.xml", 0);
121 
122  /* If we register the alert auto-action, we will get an alert indication
123  when a message is delivered. So there is no need to poll at
124  short intervals within X400ms_Wait - we can do a slow background
125  poll and rely on the Alert indication to wake the code up instead */
127 
128 
129  if (contype == 0) {
130  struct X400msAutoActionParameter *aa_param;
131 
132  /* Register an Autoforwarding Autoaction. */
133  aa_param = X400msNewAutoActionParameter();
134 
137  0);
138 
139  /* Add mandatory things to AutoAction parameter for auto-forwarding:
140  i.e. recipient address */
141  X400RecipNew(0,&rp);
142 
143  X400RecipAddStrParam(rp, X400_S_OR_ADDRESS, def_oraddr,
144  strlen(def_oraddr));
145 
147  X400_RECIP_STANDARD, rp);
148 
151  "AF contentid",
152  -1);
153 
156  1);
157 
160  1);
161 
164  1);
165 
168  1);
169 
172  2);
173 
176  "This message was autoforwarded",
177  -1);
178 
181  "This is a cover note",
182  -1);
183 
186  "AutoForwarded:",
187  -1);
188 
190  4, aa_param);
191  if ( status != X400_E_NOERROR ) {
192  fprintf (stderr,
193  "Error in RegisterAutoAction: %s\n", X400msError (status));
194  exit (status);
195  }
196  printf("Registered AutoForwarding autoaction (id = 4) OK\n");
198 
199 
200 
201  /* No parameter needed for Alert autoaction - we do not support
202  configuration of requested-attributes in this API yet. */
203  status = X400msRegisterAutoAction (sp, X400_AUTO_ALERT, 9, NULL);
204  if ( status != X400_E_NOERROR ) {
205  fprintf (stderr, "Error in RegisterAutoAction: %s\n",
206  X400msError (status));
207  exit (status);
208  }
209  printf("Registered AutoAlert autoaction (id = 9) OK\n");
210 
211 
212  /* Just test the register and deregister functions */
213  status = X400msRegisterAutoAction (sp, X400_AUTO_ALERT, 10, NULL);
214  if ( status != X400_E_NOERROR ) {
215  fprintf (stderr, "Error in RegisterAutoAction: %s\n",
216  X400msError (status));
217  exit (status);
218  }
219  printf("Registered AutoAlert autoaction (id = 10) OK\n");
220 
221  /* Lets do a deregistration of the action we just registered */
222  status = X400msDeregisterAutoAction (sp, X400_AUTO_ALERT, 10);
223  if ( status != X400_E_NOERROR ) {
224  fprintf (stderr, "Error in DeregisterAutoAction: %s\n",
225  X400msError (status));
226  exit (status);
227  }
228  printf("Deregistered AutoAlert autoaction (id = 10) OK\n");
229  }
230 
231  if ( nummsg == 0 ) {
232  printf("no messages - waiting 60 seconds for a message to be delivered.....\n");
233  } else {
234  printf ("%d messages waiting\n", nummsg);
235  }
236 
237 
238  status = X400msClose (sp);
239  return (status);
240 }
241 
242 static void usage(void) {
243  printf("usage: %s\n", optstr);
244  printf("\t where:\n");
245  printf("\t -u : Don't prompt to override defaults \n");
246  printf("\t -3 : Use P3 connection \n");
247  printf("\t -7 : Use P7 connection \n");
248  printf("\t -m : OR Address in P7 bind arg \n");
249  printf("\t -d : DN in P7 bind arg \n");
250  printf("\t -p : Presentation Address of P7 Store \n");
251  printf("\t -w : P7 password of P7 user \n");
252  printf("\t -M : OR Address in P3 bind arg \n");
253  printf("\t -D : DN in P3 bind arg \n");
254  printf("\t -P : Presentation Address of P3 server\n");
255  printf("\t -W : P3 password of P3 user \n");
256  return;
257 }
258 
void X400msFreeAutoActionParameter(struct X400msAutoActionParameter *aa_param)
Free an autoaction parameter.
#define X400_S_COVER_NOTE
Definition: x400_att.h:1241
struct X400msAutoActionParameter * X400msNewAutoActionParameter(void)
Create a new (empty) autoaction parameter structure.
#define X400_N_IMPLICIT_CONVERSION_PROHIBITED
Definition: x400_att.h:430
int X400msRegisterAutoAction(struct X400msSession *sp, int type, int id, struct X400msAutoActionParameter *aa_param)
Register an autoaction with the Message Store.
#define X400_S_LOG_CONFIGURATION_FILE
Definition: x400_att.h:1091
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
#define X400_N_DELETE_AFTER_AUTO_FORWARDING
Definition: x400_att.h:1234
int X400msAutoActionParameterAddStrParam(struct X400msAutoActionParameter *aap, int paramtype, const char *value, size_t length)
Add string-valued parameter to the autoaction parameter.
#define X400_S_CONTENT_IDENTIFIER
Definition: x400_att.h:414
#define X400_AUTO_ALERT
Definition: x400_att.h:1324
int X400RecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the recipient.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
#define X400_AUTO_FORWARDING
Definition: x400_att.h:1327
#define X400_S_AUTO_FORWARDING_COMMENT
Definition: x400_att.h:1237
int X400msDeregisterAutoAction(struct X400msSession *sp, int type, int id)
Deregister an autoaction from the Message Store.
#define X400_E_NOERROR
Definition: x400_att.h:46
int X400msOpen(int type, const char *oraddr, const char *dirname, const char *credentials, const char *pa, int *messages, struct X400msSession **spp)
Open a session to a Message Store (P7) or MTA (P3) in synchronous mode.
int X400RecipNew(int type, struct X400Recipient **rpp)
Create a new recipient object.
#define X400_S_OR_ADDRESS
Definition: x400_att.h:349
#define X400_RECIP_STANDARD
Definition: x400_att.h:341
#define X400_N_DISCLOSURE
Definition: x400_att.h:427
int X400msAutoActionParameterAddRecip(struct X400msAutoActionParameter *aap, int reciptype, struct X400Recipient *recip)
Add a receipient to the autoaction parameter.
#define X400_S_THIS_IPM_PREFIX
Definition: x400_att.h:1244
#define X400_N_WAIT_INTERVAL
Definition: x400_att.h:1084
X400 MA/MS (P3/P7) Interface.
#define X400_N_PRIORITY
Definition: x400_att.h:422
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer parameter value in a session.
#define X400_N_ALTERNATE_RECIPIENT_ALLOWED
Definition: x400_att.h:433
#define X400_N_CONTENT_RETURN_REQUEST
Definition: x400_att.h:436
int X400msAutoActionParameterAddIntParam(struct X400msAutoActionParameter *aap, int paramtype, int value)
Add integer-valued parameter to the autoaction parameter.