20 int main(
int argc,
char **argv)
22 fprintf(stderr,
"This example is not available on Windows\n");
28 static void usage(
void) ;
34 #include <sys/types.h>
36 #include <sys/select.h>
50 #if defined(__GNUC__) || defined (__GNUG__)
51 #define IC_ATTRIBUTE(x) __attribute__ (x)
53 #define IC_ATTRIBUTE(x)
59 #if (defined(__GNUG__) && __GNUG__ >= 4) || (!defined(__GNUG__) && defined(__GNUC__) && __GNUC__ >= 3)
60 # define ARGNOTUSED IC_ATTRIBUTE((unused))
65 static void connection_established(
struct X400msSession *session,
67 int num_messages_waiting);
69 static void connection_lost(
struct X400msSession *session,
73 static void submission_complete(
struct X400msSession *session,
74 struct X400msMessage *message,
77 static void fetch_complete(
struct X400msSession *session,
78 struct X400msMessage *message,
83 static void delete_complete(
struct X400msSession *session,
87 static void wait_complete(
struct X400msSession *session,
88 int num_messages_waiting,
91 static void list_complete(
struct X400msSession *session,
92 struct X400msListResult *listres,
95 static void register_complete(
struct X400msSession *session,
98 static void alert_event(
struct X400msSession *session);
100 static void event_loop(
void);
102 static int manage_callback(
struct X400msSession *session,
106 static int unmanage_callback(
struct X400msSession *session,
116 struct X400msSession *sp;
119 #define MAX_SESSIONS 10
122 static int dosubmit = 1;
123 int millisecs = 10000;
125 int nummsgs = 9999999;
126 static char *optstr =
"u371m:p:w:l:sc:o:";
129 static void usage(
void) {
130 printf(
"usage: %s\n", optstr);
131 printf(
"\t where:\n");
132 printf(
"\t -u : Don't prompt to override defaults \n");
133 printf(
"\t -3 : P3 connection \n");
134 printf(
"\t -7 : P7 connection \n");
135 printf(
"\t -m : OR Address in P7 bind arg \n");
136 printf(
"\t -p : Presentation Address of P7 Store \n");
137 printf(
"\t -w : P7 password of P7 user \n");
138 printf(
"\t -s : Don't do submission\n");
139 printf(
"\t -l : Sleep time (milliseconds)\n");
140 printf(
"\t -c : Num associations\n");
141 printf(
"\t -o : Exit after retrieving n messages\n");
146 int main(
int argc,
char **argv)
156 x400_default_alternate_recipient_allowed = 1;
158 x400_default_originator =
"1000000";
160 for (i = 0; i <= MAX_SESSIONS; i++)
163 if (get_args(argc, argv, optstr)) {
168 def_oraddr = x400_ms_user_addr;
169 def_pa = x400_ms_presentation_address;
170 if (x400_logline != NULL)
171 millisecs = atoi(x400_logline);
173 dosubmit = x400_default_disclosure_of_recipients;
174 numcons = atoi(x400_channel);
175 nummsgs = atoi(x400_default_originator);
177 printf(
"Connection type (0 = P7, 1 = P3 submit only, 2 = P3 both directions) [%d]: ", x400_contype);
178 contype = ic_fgetc(x400_contype, stdin);
180 ic_fgetc(x400_contype, stdin);
182 if ( contype <
'0' ||
'2' < contype )
183 contype = x400_contype;
187 for (i = 0; i < numcons; i++) {
188 printf(
"ORAddress [%s] > ", def_oraddr);
189 ic_fgets (ora,
sizeof ora, stdin);
191 if ( ora[strlen(ora)-1] ==
'\n' )
192 ora[strlen(ora)-1] =
'\0';
195 strcpy(ora, def_oraddr);
198 printf (
"Password [%s]: ",
199 contype == 0 ? x400_p7_password : x400_p3_password);
200 if ( ic_fgets (buffer,
sizeof buffer, stdin) == NULL )
203 if (buffer[strlen(buffer)-1] ==
'\n' )
204 buffer[strlen(buffer)-1] =
'\0';
205 if (buffer[0] ==
'\0')
206 strcpy(buffer, contype == 0 ? x400_p7_password : x400_p3_password);
208 printf(
"Presentation Address [%s] > ", def_pa);
209 ic_fgets (pa,
sizeof pa, stdin);
211 if ( pa[strlen(pa)-1] ==
'\n' )
212 pa[strlen(pa)-1] =
'\0';
217 st[i].oraddr = strdup(ora);
218 st[i].psw = strdup(buffer);
219 st[i].pa = strdup(pa);
223 if (talking_to_marben_ms)
227 for (i = 0; (st[i].oraddr != NULL) && (i < numcons); i++) {
229 st[i].oraddr, NULL, st[i].psw,
231 connection_established,
245 fprintf (stderr,
"Error in Open for %s: %s\n",
248 printf (
"Sent off connection request for session %p\n",
254 if (talking_to_marben_ms)
267 static int unmanage_callback(
struct X400msSession *session,
273 printf(
"unmanage_callback, session = %p, mask = %d\n", session, eventmask);
275 for (i = 0; st[i].oraddr != NULL; i++) {
276 if (st[i].sp == session) {
277 st[i].eventmask &= ~eventmask;
284 static int manage_callback(
struct X400msSession *session,
290 printf(
"manage_callback, session = %p, fd = %d, eventmask = %d\n",
291 session, fd, eventmask);
293 for (i = 0; st[i].oraddr != NULL; i++) {
294 if (st[i].sp == session) {
295 st[i].eventmask |= eventmask;
303 static void send_messages(
void)
307 struct X400msMessage *mp;
308 struct X400Recipient *rp;
314 for (i = 0; st[i].oraddr != NULL; i++) {
315 if (st[i].fd != -1) {
320 fprintf (stderr,
"x400msMsgNew returned error: %s\n",
327 fprintf (stderr,
"x400msRecipNew returned error: %s\n",
335 fprintf (stderr,
"x400msRecipAddStrParam returned error: %s\n",
340 sprintf(buf,
"Subject for session %p", st[i].sp);
344 fprintf (stderr,
"x400msMsgAddStrParam returned error: %s\n",
351 fprintf (stderr,
"x400ms returned error: %s\n",
355 #define BINSIZE 6000000
356 s = (
char*)malloc(BINSIZE);
361 sprintf(contid,
"CONTID%d", num);
367 fprintf (stderr,
"X400msMsgAddIntParam %d returned error: %s\n",
372 printf(
"Sending message from & to %s\n", st[i].oraddr);
377 fprintf (stderr,
"Error sending message: %d\n", status);
386 static void connection_established(
struct X400msSession *session,
394 printf(
"Connection established for session %p, alert = %d\n",
399 printf(
"Sending Register request\n");
405 "Failed to issue Register for session %p, err = %d\n",
407 printf(
"Registered AutoAlert autoaction (id = 9) OK\n");
409 printf(
"Sending Deregister request\n");
415 "Failed to issue Deregister for session %p, err = %d\n",
417 printf(
"Deegistered AutoAlert autoaction (id = 5) OK\n");
419 printf(
"Sending List request\n");
424 "Failed to issue List for session %p, err = %d\n",
433 "Failed to issue Wait for session %p, err = %d\n",
439 fprintf(stderr,
"Connection failed for session %p\n", session);
440 for (i = 0; st[i].oraddr != NULL; i++) {
441 if (st[i].sp == session) {
449 static void connection_lost(
struct X400msSession *session ARGNOTUSED,
453 fprintf(stderr,
"Connection lost callback, reason = %d, diag = %s\n",
454 reason_code, (diagnostic == NULL) ?
"NULL" : diagnostic);
457 static void submission_complete(
struct X400msSession *session ARGNOTUSED,
458 struct X400msMessage *message,
469 printf(
"Submission successful, identifier = %s\n", buf);
471 fprintf(stderr,
"Submission successful but failed to get ID\n");
475 fprintf(stderr,
"No MessageSubmissionTime present from submission result: error %d\n", status);
478 printf(
"MessageSubmissionTime from Submission Result = %s\n", buf);
483 fprintf(stderr,
"No ContentIdentifier present from submission result: error %d\n", status);
486 printf(
"ContentIdentifier from Submission Result = %s\n", buf);
491 fprintf(stderr,
"Submission failed, errorcode = %d\n", errorcode);
497 static void list_complete(
struct X400msSession *session,
498 struct X400msListResult *lr,
504 printf(
"list_complete, errorcode = %d\n", errorcode);
557 sender = strdup(buf);
573 subjid = strdup(buf);
583 printf(
"S=%d, P=%d, len=%d, stat=%d, type=%s, subj=%s, orig=%s, msgid=%s, subjid=%s\n",
584 seqnum, pri, length, entry_status,
585 (type == NULL) ?
"NULL" : type,
586 (subj == NULL) ?
"NULL": subj,
587 (sender == NULL) ?
"NULL" : sender,
588 (msgid == NULL) ?
"NULL" : msgid,
589 (subjid == NULL) ?
"NULL" : subjid);
606 printf(
"Session %p, issing MsgGet\n", session);
611 fprintf(stderr,
"MsgGet failed !\n");
618 fprintf(stderr,
"List failed, errorcode = %d\n", errorcode);
623 static void fetch_complete(
struct X400msSession *session,
624 struct X400msMessage *message,
629 printf(
"Fetch complete callback, session=%p, seqno=%d, type=%d, errorcode = %d\n",
630 session, seqno, type, errorcode);
641 buffer,
sizeof buffer, &length);
643 printf(
"Read raw content into file %s\n", buffer);
645 fprintf(stderr,
"Failed to read raw content into file, error %d\n", status);
648 buffer,
sizeof buffer , &length);
650 printf(
"Read raw content into buffer, length = %ld\n", (
long)length);
652 fprintf(stderr,
"Failed to read raw content into buffer, error %d\n", status);
657 printf(
"Object type = %s\n", buf);
662 printf(
"Subject = %s\n", buf);
667 fprintf(stderr,
"MsgGetFinish failed !\n");
674 fprintf(stderr,
"MsgDelete failed !\n");
676 printf(
"Session %p, issued MsgDelete for %d\n", session, seqno );
680 fprintf(stderr,
"MsgGet failed !\n");
683 printf(
"Session %p, issued MsgGet\n", session);
686 fprintf(stderr,
"Fetch failed, errcode = %d\n",errorcode);
690 static void delete_complete(
struct X400msSession *session,
695 printf(
"Session %p, - delete complete callback for seqnum %d\n",
698 fprintf(stderr,
"******* SESSION %p, - DELETE FAILED %d **********\n",
703 static void register_complete(
struct X400msSession *session,
707 printf(
"Session %p, - register complete callback\n",
710 fprintf(stderr,
"******* SESSION %p, - REGISTER FAILED %d **********\n",
715 static void wait_complete(
struct X400msSession *session,
716 int num_messages_waiting,
719 printf(
"Wait complete callback, errorcode = %d, num = %d\n",
720 errorcode, num_messages_waiting);
722 if (num_messages_waiting > 0) {
726 printf(
"Session %p, issuing MsgGet OK\n", session);
729 fprintf(stderr,
"MsgGet failed !\n");
733 static void alert_event(
struct X400msSession *session)
737 printf(
"Got an alert !\n");
739 printf(
"Issuing List op for session %p\n", session);
742 fprintf(stderr,
"Failed to issue List op for session %p, error %d\n",
747 static void event_loop()
749 fd_set rfds, wfds, efds;
750 struct timeval timeout, *tp;
761 for (i = 0; st[i].oraddr != NULL; i++) {
762 if (st[i].fd != -1) {
764 printf(
"Expecting ");
767 FD_SET(st[i].fd, &rfds);
772 FD_SET(st[i].fd, &wfds);
777 FD_SET(st[i].fd, &efds);
779 printf(
"on fd %d\n", st[i].fd);
782 if (st[i].fd > num_fds)
786 if ( millisecs >= 0 ) {
787 timeout.tv_sec = millisecs / 1000;
788 timeout.tv_usec = (millisecs % 1000) *1000;
794 n = select (num_fds + 1, &rfds, &wfds, &efds, tp);
797 fprintf(stderr,
"select returned %d: errno = %d\n", n, errno);
802 printf(
"Exiting now\n");
803 for (i = 0; st[i].oraddr != NULL; i++)
810 printf(
">>>>> Timeout\n");
813 for (i = 0; st[i].oraddr != NULL; i++) {
816 if (st[i].fd != -1) {
817 printf(
"Issuing List for session %p\n", st[i].sp);
822 "Failed to issue List for session %p, err = %d\n",
int X400msProcessEvent(int num_fds, fd_set *read_fds, fd_set *write_fds, fd_set *error_fds)
Process outstanding read, write and error events on the specified set of file descriptors....
void X400msSetConfigRequest(int val)
Disable and enable configuration requests in MS Bind operations.
#define X400_N_STRICT_P7_1988
#define X400_S_LOG_CONFIGURATION_FILE
#define X400_S_OBJECTTYPE
int X400msMsgSend(struct X400msMessage *mp)
Send message object.
#define X400_N_MS_ENTRY_STATUS
int X400msMsgAddAttachment(struct X400msMessage *mp, int type, const char *string, size_t length)
Add attachment to the message.
#define X400_S_CONTENT_STRING
int X400msSetStrDefault(struct X400msSession *sp, int paramtype, const char *value, size_t length)
Set a default string parameter value in a session.
int X400msListGetIntParam(struct X400msListResult *lr, int paramtype, int number, int *valp)
Get an integer attribute value from an element of a ListResult.
int X400msOpenAsync(int type, const char *oraddr, const char *dirname, const char *credentials, const char *pa, const char *ret_psw, X400msConnEstablishedCb *conupcb, X400msConnDroppedCb *condowncb, X400msMsgSubmittedCb *msgsubcb, X400msMsgFetchedCb *msgfetchcb, X400msMsgDeletedCb *msgdelcb, X400msMsgWaitingCb *msgwaitcb, X400msListCb *listcb, X400msRegisterCb *registercb, X400msAlertCb *alertcb, X400msManageCb *managecb, X400msManageCb *unmanagecb, struct X400msSession **spp)
Initiate an asynchronous opening of a session to a Message Store (P7)
#define X400_E_NO_MORE_RESULTS
int X400msClose(struct X400msSession *sp)
Close a X400 Session.
#define X400_E_WAIT_WRITE
int X400msDeregisterAutoAction(struct X400msSession *sp, int type, int id)
Deregister an autoaction from the Message Store.
void X400msListFree(struct X400msListResult *lr)
Free the memory occupied by a ListResult.
int X400msRecipAddStrParam(struct X400Recipient *rp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msMsgGet(struct X400msSession *sp, int number, struct X400msMessage **mpp, int *typep, int *seqp)
Get message object for transfer out from MS or MTA via P3.
int X400msRecipNew(struct X400msMessage *mp, int type, struct X400Recipient **rpp)
Add new recipient to a message.
const char * X400msError(int error)
Obtain a string describing the meaning of the given error code.
#define X400_E_WAIT_READ_WRITE
#define X400_RECIP_STANDARD
int X400msMsgNew(struct X400msSession *sp, int type, struct X400msMessage **mpp)
Creates new message.
#define X400_S_CONTENT_FILENAME
#define X400_S_CONTENT_IDENTIFIER
int X400msList(struct X400msSession *sp, char *since_time, struct X400msListResult **lrp)
List messages in the P7 Message Store.
int X400msWait(struct X400msSession *sp, int seconds, int *count)
Wait for messages to be ready to be read.
#define X400_S_MESSAGE_IDENTIFIER
#define X400_N_MS_SEQUENCE_NUMBER
#define X400_S_SUBJECT_IDENTIFIER
X400 MA/MS (P3/P7) Interface.
#define X400_N_CONTENT_LENGTH
X400 MS (P7) Interface asynchronous event handler.
int X400msSetIntDefault(struct X400msSession *sp, int paramtype, int value)
Set a default integer parameter value in a session.
#define X400_S_MESSAGE_SUBMISSION_TIME
int X400msMsgGetStrParam(struct X400msMessage *mp, int paramtype, char *buffer, size_t buflen, size_t *paramlenp)
Return a string-valued parameter from the message object.
int X400msListGetStrParam(struct X400msListResult *lr, int paramtype, int number, char *buffer, size_t buflen, size_t *paramlenp)
Get a string attribute value from an element of a ListResult.
int X400msMsgAddStrParam(struct X400msMessage *mp, int paramtype, const char *value, size_t length)
Add string-valued parameter to the message.
int X400msMsgGetFinish(struct X400msMessage *mp, int errnum, int problem)
Generate delivery result or error for a message.
int X400msRegisterAutoAction(struct X400msSession *sp, int type, int id, struct X400msAutoActionParameter *aa_param)
Register an autoaction with the Message Store.
int X400msGetHandle(struct X400msSession *session)
Get a handle suitable for use in a call to select()
#define X400_S_OR_ADDRESS
int X400msMsgDelete(struct X400msMessage *mp, int retain)
Delete message object.