examples/x400_msraa.c

This is an example program which shows you how to register and deregister autoactions with the Message Store. Supported auto-actions include auto-forward (to automatically forward every received message), and auto-alert (to alert the UA of a new message).

/* Copyright (c) 2005-2009, Isode Limited, London, England.
* All rights reserved.
*
* Acquisition and use of this software and related materials for any
* purpose requires a written licence agreement from Isode Limited,
* or a written licence from an organisation licenced by Isode Limited
* to grant such a licence.
*
*/
/*
*
* @VERSION@
* Simple example program for registering an auto-action in the message store
*/
#include <stdio.h>
#include <x400_msapi.h>
#include "example.h"
static void usage(void);
static char *optstr = "u37m:d:p:w:M:D:P:W:";
int main (
int argc,
char **argv
)
{
char buffer[BUFSIZ];
char pa[BUFSIZ];
char orn[BUFSIZ];
char password[BUFSIZ];
int status;
int nummsg;
struct X400msSession *sp;
struct X400Recipient *rp;
int contype;
char *def_oraddr;
char *def_dn;
char *def_pa;
char autoaction;
if (get_args(argc, argv, optstr)) {
usage();
exit(-1);
}
printf("Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
contype = ic_fgetc(x400_contype, stdin);
if (contype != 10)
ic_fgetc(x400_contype, stdin);
if ( contype < '0' || '2' < contype )
contype = x400_contype;
else
contype -= '0';
if (contype == 0) {
def_oraddr = x400_ms_user_addr;
def_dn = x400_ms_user_dn;
def_pa = x400_ms_presentation_address;
} else {
def_oraddr = x400_mta_user_addr;
def_dn = x400_mta_user_dn;
def_pa = x400_mta_presentation_address;
}
printf("Your ORAddress [%s] > ", def_oraddr);
ic_fgets (orn, sizeof orn, stdin);
if ( orn[strlen(orn)-1] == '\n' )
orn[strlen(orn)-1] = '\0';
if (orn[0] == '\0')
strcpy(orn, def_oraddr);
/* Prompt for password; note: reflected. */
printf ("Password [%s]: ",
contype == 0 ? x400_p7_password : x400_p3_password);
if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
exit (1);
if (buffer[strlen(buffer)-1] == '\n' )
buffer[strlen(buffer)-1] = '\0';
if (buffer[0] == '\0')
strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
strcpy(password, buffer);
/* Presentation address */
printf("Presentation Address [%s] > ", def_pa);
ic_fgets (pa, sizeof pa, stdin);
if ( pa[strlen(pa)-1] == '\n' )
pa[strlen(pa)-1] = '\0';
if (pa[0] == '\0')
strcpy(pa, def_pa);
/* Register or deregister the autoaction */
printf("Register or Deregister the AutoAction ? (R = Register, D = Deregister): ");
if ( ic_fgets (buffer, sizeof buffer, stdin) == NULL )
exit (1);
autoaction = buffer[0];
if ((autoaction != 'R') && (autoaction != 'D'))
exit(1);
/* open the session */
status = X400msOpen (contype, orn, def_dn, password, pa, &nummsg, &sp);
if ( status != X400_E_NOERROR ) {
fprintf (stderr, "Error in Open: %s\n", X400msError (status));
exit (status);
}
/* setup logging from $(ETCDIR)x400api.xml or $(SHAREDIR)x400api.xml */
/* If we register the alert auto-action, we will get an alert indication
when a message is delivered. So there is no need to poll at
short intervals within X400ms_Wait - we can do a slow background
poll and rely on the Alert indication to wake the code up instead */
if (contype == 0) {
struct X400msAutoActionParameter *aa_param;
/* Register an Autoforwarding Autoaction. */
0);
/* Add mandatory things to AutoAction parameter for auto-forwarding:
i.e. recipient address */
X400RecipNew(0,&rp);
strlen(def_oraddr));
"AF contentid",
-1);
1);
1);
1);
1);
2);
"This message was autoforwarded",
-1);
"This is a cover note",
-1);
"AutoForwarded:",
-1);
4, aa_param);
if ( status != X400_E_NOERROR ) {
fprintf (stderr,
"Error in RegisterAutoAction: %s\n", X400msError (status));
exit (status);
}
printf("Registered AutoForwarding autoaction (id = 4) OK\n");
/* No parameter needed for Alert autoaction - we do not support
configuration of requested-attributes in this API yet. */
status = X400msRegisterAutoAction (sp, X400_AUTO_ALERT, 9, NULL);
if ( status != X400_E_NOERROR ) {
fprintf (stderr, "Error in RegisterAutoAction: %s\n",
X400msError (status));
exit (status);
}
printf("Registered AutoAlert autoaction (id = 9) OK\n");
/* Just test the register and deregister functions */
status = X400msRegisterAutoAction (sp, X400_AUTO_ALERT, 10, NULL);
if ( status != X400_E_NOERROR ) {
fprintf (stderr, "Error in RegisterAutoAction: %s\n",
X400msError (status));
exit (status);
}
printf("Registered AutoAlert autoaction (id = 10) OK\n");
/* Lets do a deregistration of the action we just registered */
if ( status != X400_E_NOERROR ) {
fprintf (stderr, "Error in DeregisterAutoAction: %s\n",
X400msError (status));
exit (status);
}
printf("Deregistered AutoAlert autoaction (id = 10) OK\n");
}
if ( nummsg == 0 ) {
printf("no messages - waiting 60 seconds for a message to be delivered.....\n");
} else {
printf ("%d messages waiting\n", nummsg);
}
status = X400msClose (sp);
return (status);
}
static void usage(void) {
printf("usage: %s\n", optstr);
printf("\t where:\n");
printf("\t -u : Don't prompt to override defaults \n");
printf("\t -3 : Use P3 connection \n");
printf("\t -7 : Use P7 connection \n");
printf("\t -m : OR Address in P7 bind arg \n");
printf("\t -d : DN in P7 bind arg \n");
printf("\t -p : Presentation Address of P7 Store \n");
printf("\t -w : P7 password of P7 user \n");
printf("\t -M : OR Address in P3 bind arg \n");
printf("\t -D : DN in P3 bind arg \n");
printf("\t -P : Presentation Address of P3 server\n");
printf("\t -W : P3 password of P3 user \n");
return;
}
#define X400_S_LOG_CONFIGURATION_FILE
Definition: x400_att.h:1092
#define X400_AUTO_ALERT
Definition: x400_att.h:1334
#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.
int X400msAutoActionParameterAddIntParam(struct X400msAutoActionParameter *aap, int paramtype, int value)
Add integer-valued parameter to the autoaction parameter.
#define X400_N_CONTENT_RETURN_REQUEST
Definition: x400_att.h:436
#define X400_S_THIS_IPM_PREFIX
Definition: x400_att.h:1245
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.
#define X400_S_COVER_NOTE
Definition: x400_att.h:1242
struct X400msAutoActionParameter * X400msNewAutoActionParameter(void)
Create a new (empty) autoaction parameter structure.
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
void X400msFreeAutoActionParameter(struct X400msAutoActionParameter *aa_param)
Free an autoaction parameter.
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
int X400msDeregisterAutoAction(struct X400msSession *sp, int type, int id)
Deregister an autoaction from the Message Store.
#define X400_N_PRIORITY
Definition: x400_att.h:422
int X400RecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the recipient.
#define X400_AUTO_FORWARDING
Definition: x400_att.h:1337
int X400RecipNew(int type, struct X400Recipient **rpp)
Create a new recipient object.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
#define X400_RECIP_STANDARD
Definition: x400_att.h:341
#define X400_S_AUTO_FORWARDING_COMMENT
Definition: x400_att.h:1238
#define X400_S_CONTENT_IDENTIFIER
Definition: x400_att.h:414
#define X400_N_WAIT_INTERVAL
Definition: x400_att.h:1085
#define X400_E_NOERROR
Definition: x400_att.h:46
#define X400_N_IMPLICIT_CONVERSION_PROHIBITED
Definition: x400_att.h:430
X400 MA/MS (P3/P7) Interface.
int X400msAutoActionParameterAddStrParam(struct X400msAutoActionParameter *aap, int paramtype, const char *value, size_t length)
Add string-valued parameter to the autoaction parameter.
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_DELETE_AFTER_AUTO_FORWARDING
Definition: x400_att.h:1235
int X400msRegisterAutoAction(struct X400msSession *sp, int type, int id, struct X400msAutoActionParameter *aa_param)
Register an autoaction with the Message Store.
#define X400_S_OR_ADDRESS
Definition: x400_att.h:349