Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

C-Beispielprogramme

&pagelevel(5)&pagelevel

Die nachfolgendend abgedruckten C-Beispielprogramme zeigen die Verwendung der C-Funktionsaufrufe YMLSML(), YMLCML(), YMLDML(), YMLGML().

Beispiel 1: Funktionsaufrufe YMLSML() und YMLCML()

#include <stdio.h>
#include <stdlib.h>
#include "FHDR.H"
#define _YMLSML_H_VERSION_3
#include "YMLSML.H"
#define _YMLCML_H_VERSION_2
#include "YMLCML.H"

#define ALIGNMENT 4
#define PAD(length) ((length + ALIGNMENT - 1) & ~(ALIGNMENT - 1))

main(int argc, char *argv[])
{
  int c;
  int suppressCheck = 0;
  struct YMLSML_pl_mdl sendParam;
  struct YMLCML_pl_mdl checkParam;
  enum {UNIT = 940, SEND_FUNCTION = 20, SEND_VERSION = 3,
        CHECK_FUNCTION = 21, CHECK_VERSION = 2,
        parLen = 63 * 1024 + 512, orderIdLen = 16};
  char sender[] = "Claudio.Monteverdi@mantova.example";
  char recipient[] = "Heinrich.Schuetz@dresden.example";
  char subject[] = "This is a test message";
  char msgText[] = "This is the start of the test message.\n"
                   "This is the end of the test message.\n";
  char srcCCSN[8 + 1] = "EDF04DRV";
  char destCCSN[8 + 1] = "ISO88591";
  char charSetName[] = "ISO-8859-1";
  char *ptr;
  struct YMLSML_general *ptrGeneral;
  struct YMLSML_msg_att *ptrMsgAtt;
  struct YMLSML_data_spec *ptrDataSpec;
  struct YMLSML_charset *ptrCharset;
  struct YMLSML_encoding *ptrEncoding;
  char *mailPar;
  char orderId[orderIdLen];

  while ((c = getopt(argc, argv, "C")) != EOF) {
    if (c == 'C')
      suppressCheck = 1;
  }

  mailPar = ptr = malloc(parLen);
  /* [Do some error handling] */
  /* Supplying sender address */
  ptrGeneral = (struct YMLSML_general *) ptr;
  ptrGeneral->tag = YMLSML_tag_from;
  ptrGeneral->len = strlen(sender);
  ptr += sizeof(*ptrGeneral);
  memcpy(ptr, sender, ptrGeneral->len);
  ptr += PAD(ptrGeneral->len);

  /* Supplying recipient address */
  ptrGeneral = (struct YMLSML_general *) ptr;
  ptrGeneral->tag = YMLSML_tag_to;
  ptrGeneral->len = strlen(recipient);
  ptr += sizeof(*ptrGeneral);
  memcpy(ptr, recipient, ptrGeneral->len);
  ptr += PAD(ptrGeneral->len);

  /* Supplying subject line */
  ptrGeneral = (struct YMLSML_general *) ptr;
  ptrGeneral->tag = YMLSML_tag_subject;
  ptrGeneral->len = strlen(subject);
  ptr += sizeof(*ptrGeneral);
  memcpy(ptr, subject, ptrGeneral->len);
  ptr += PAD(ptrGeneral->len);

  /* Supplying message body */
  ptrMsgAtt = (struct YMLSML_msg_att *) ptr;
  ptrMsgAtt->tag = YMLSML_tag_msg_begin;
  ptr += sizeof(*ptrMsgAtt);
  ptrDataSpec = (struct YMLSML_data_spec *) ptr;
  ptrDataSpec->tag = YMLSML_tag_data_spec;
  ptrDataSpec->type = YMLSML_data;
  ptrDataSpec->len = strlen(msgText);
  ptr += sizeof(*ptrDataSpec);
  memcpy(ptr, msgText, ptrDataSpec->len);
  ptr += PAD(ptrDataSpec->len);
  ptrCharset = (struct YMLSML_charset *) ptr;
  ptrCharset->tag = YMLSML_tag_charset;
  ptrCharset->binary = YMLSML_no;
  memcpy(ptrCharset->src_charset_XHCS, srcCCSN,
  sizeof(ptrCharset->src_charset_XHCS));
  memcpy(ptrCharset->dest_charset_XHCS, destCCSN,
  sizeof(ptrCharset->dest_charset_XHCS));
  ptrCharset->len = strlen(charSetName);
  ptr += sizeof(*ptrCharset);
  memcpy(ptr, charSetName, ptrCharset->len);
  ptr += PAD(ptrCharset->len);
  ptrEncoding = (struct YMLSML_encoding *) ptr;
  ptrEncoding->tag = YMLSML_tag_encoding;
  ptrEncoding->mechanism = YMLSML_qp;
  ptr += sizeof(*ptrEncoding);
  ptrMsgAtt = (struct YMLSML_msg_att *) ptr;
  ptrMsgAtt->tag = YMLSML_tag_msg_end;
  ptr += sizeof(*ptrMsgAtt);

  memset(&sendParam, 0x00, sizeof(sendParam));
  FHDR_SET_RC_NIL(sendParam.hdr);
  FHDR_MOD_IFID(sendParam.hdr, UNIT, SEND_FUNCTION, SEND_VERSION);
  sendParam.in_data.mail_par = mailPar;
  sendParam.in_data.mail_par_len = ptr - mailPar;
  sendParam.in_data.wait = YMLSML_res;
  sendParam.in_data.sec_prot = YMLSML_smime;
  sendParam.in_data.encrypt = YMLSML_no;
  sendParam.in_data.sign = YMLSML_no;
  sendParam.in_data.cipher = YMLSML_cipher_from_optfile;
  memcpy(sendParam.in_data.optfile, "*NONE", 5);
  YMLSML(sendParam);
  if (sendParam.hdr.FHDR_RC_MAINCODE == YMLSML_successful) {
    printf("YMLSML called successfully\n");
    memcpy(orderId, sendParam.out_data.order_id, orderIdLen);
    printf(" Order id: %.16s\n", sendParam.out_data.order_id);
    if (sendParam.in_data.wait == YMLSML_yes) {
      printf(" Return code: %d\n", sendParam.out_data.rc);
      printf(" Return message: %.160s\n", sendParam.out_data.ret_msg);
      exit(0);
    }
  }
  else {
    printf("Error in call of YMLSML: %08X\n", sendParam.hdr.FHDR_RC_NBR);
    printf(" Order id: %.16s\n", sendParam.out_data.order_id);
    printf(" Return code: %d\n", sendParam.out_data.rc);
    printf(" Return message: %.160s\n", sendParam.out_data.ret_msg);
    if (sendParam.hdr.FHDR_RC_MAINCODE == YMLSML_asti_error)
      printf(" ASTI error: %08X\n", sendParam.out_data.asti_rc);
    exit(1);
  }

  if (!suppressCheck) {
    memset(&checkParam, 0x00, sizeof(checkParam));
    FHDR_SET_RC_NIL(checkParam.hdr);
    FHDR_MOD_IFID(checkParam.hdr, UNIT, CHECK_FUNCTION, CHECK_VERSION);
    checkParam.in_data.wait = YMLCML_yes;
    checkParam.in_data.order = YMLCML_single;
    memcpy(checkParam.in_data.order_id, orderId, orderIdLen);
    YMLCML(checkParam);
    if (checkParam.hdr.FHDR_RC_MAINCODE == YMLCML_successful) {
      printf("YMLCML called successfully\n");
      printf(" Order id: %.16s\n", checkParam.out_data.order_id);
      printf(" Return code: %d\n", checkParam.out_data.rc);
      printf(" Return message: %.160s\n", checkParam.out_data.ret_msg);
    }
    else {
      printf("Error in call of YMLCML: %08X\n", checkParam.hdr.FHDR_RC_NBR);
      printf(" Order id: %.16s\n", checkParam.out_data.order_id);
      printf(" Return code: %d\n", checkParam.out_data.rc);
      printf(" Return message: %.160s\n", checkParam.out_data.ret_msg);
      if (checkParam.hdr.FHDR_RC_MAINCODE == YMLCML_asti_error)
        printf(" ASTI error: %08X\n", checkParam.out_data.asti_rc);
    }
  }
}


Beispiel 2: Funktionsaufruf YMLDML()

#include <stdio.h>
#include <stdlib.h>
#include "FHDR.H"
#define _YMLDML_H_VERSION_2
#include "YMLDML.H"

main(int argc, char *argv[])
{
  int c;
  int deleteAll = 0;
  struct YMLDML_pl_mdl deleteParam;
  enum {UNIT = 940, DELETE_FUNCTION = 22, DELETE_VERSION = 1,
        orderIdLen = 16};
  char orderId[orderIdLen + 1];

  while ((c = getopt(argc, argv, "AO:")) != EOF) {
    if (c == 'O') {
      strupper(optarg, NULL);
      strncpy(orderId, optarg, orderIdLen);
      orderId[orderIdLen] = 0x00;
    }
    else if (c == 'A')
      deleteAll = 1;
  }

  memset(&deleteParam, 0x00, sizeof(deleteParam));
  FHDR_SET_RC_NIL(deleteParam.hdr);
  FHDR_MOD_IFID(deleteParam.hdr, UNIT, DELETE_FUNCTION, DELETE_VERSION);
  if (deleteAll)
    deleteParam.in_data.order = YMLDML_all;
  else {
    deleteParam.in_data.order = YMLDML_single;
    memcpy(deleteParam.in_data.order_id, orderId, orderIdLen);
  }
  deleteParam.in_data.owner = YMLDML_own;
  YMLDML(deleteParam);
  if (deleteParam.hdr.FHDR_RC_MAINCODE == YMLDML_successful) {
    printf("YMLDML called successfully\n");
  }
  else {
    printf("Error in call of YMLDML: %08X\n",
           deleteParam.hdr.FHDR_RC_NBR);
    if (deleteParam.hdr.FHDR_RC_MAINCODE == YMLDML_asti_error)
      printf("  ASTI error: %08X\n", deleteParam.out_data.asti_rc);
    exit(1);
  }
}


Beispiel 3: Funktionsaufruf YMLGML()

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "FHDR.H"
#define _YMLGML_H_VERSION_2
#include "YMLGML.H"

main(int argc, char *argv[])
{
  int c;
  int getInfo = 0;
  struct YMLGML_pl_mdl getInfoParam;
  enum {UNIT = 940, GETINFO_FUNCTION = 23, GETINFO_VERSION = 2,
        orderIdLen = 16, maxListSize = 30, mailParSize = 32768};
  char orderId[orderIdLen + 1];
  struct YMLGML_order *orderIdList;
  int orderIdListSize = sizeof(orderIdList->num_order) +
                        sizeof(orderIdList->order_id) * maxListSize;
  struct YMLGMLoutpar *mailPar;
  char *statusTxt[5] =
    {"Waiting", "Deferred", "Active", "Sent", "Failed"};
  char *rcTxt[11] =
    {"Ok", "Parameter error", "Resource saturation", "SMTP error",
     "S/MIME error", NULL, NULL, NULL, NULL, NULL, "Internal error"};
  int i;
  time_t time;

  while ((c = getopt(argc, argv, "AO:S")) != EOF) {
    getInfo = c;
    if (getInfo == 'O') {
      strupper(optarg, NULL);
      strncpy(orderId, optarg, orderIdLen);
      orderId[orderIdLen] = 0x00;
    }
  }

  memset(&getInfoParam, 0x00, sizeof(getInfoParam));
  FHDR_SET_RC_NIL(getInfoParam.hdr);
  FHDR_MOD_IFID(getInfoParam.hdr, UNIT, GETINFO_FUNCTION, GETINFO_VERSION);
  if (getInfo == 'A') {
    getInfoParam.in_data.order = YMLGML_all;
    if (!(orderIdList = malloc(orderIdListSize))) {
      printf("malloc failed\n");
      exit(1);
    }
    getInfoParam.in_data.out  = orderIdList;
    getInfoParam.in_data.outl = orderIdListSize;
  }
  else if (getInfo == 'S') {
    getInfoParam.in_data.order = YMLGML_sum;
    getInfoParam.in_data.out   = NULL;
    getInfoParam.in_data.outl  = 0;
  }
  else if (getInfo == 'O') {
    getInfoParam.in_data.order = YMLGML_single;
    memcpy(getInfoParam.in_data.order_id, orderId, orderIdLen);
    if (!(mailPar = malloc(mailParSize))) {
      printf("malloc failed\n");
      exit(1);
    }
    getInfoParam.in_data.out  = mailPar;
    getInfoParam.in_data.outl = mailParSize;
  }
  else {
    printf("No getInfo option specified!\n");
    exit(1);
  }
  getInfoParam.in_data.owner = YMLGML_own;
  YMLGML(getInfoParam);
  if (getInfoParam.hdr.FHDR_RC_MAINCODE == YMLGML_successful) {
    printf("YMLGML called successfully\n");
    if (getInfo == 'A' || getInfo == 'S')
      printf("  Number of mail orders: %d\n",
             getInfoParam.out_data.sum);
    if (getInfo == 'A') {
      for (i = 0; i < orderIdList->num_order; i++)
        printf("  OrderId[%d]: %.16s\n",
               i + 1, orderIdList->order_id[i]);
    }
    else if (getInfo == 'O') {
      printf("  Mail status: %s\n",
        statusTxt[mailPar->_outp.mail_data.status - 1]);
      printf("  Mail submitter: %.8s\n",
             mailPar->_outp.mail_data.user);
      time = (time_t) mailPar->_outp.mail_data.time -
              (50 * 365 + 12) * 24 * 60 * 60;
      printf("  Mail send time: %s", ctime(&time));
      if (mailPar->_outp.mail_data.slctr == YMLGML_sel_result) {
        printf("  Mail result: %s\n",
               rcTxt[mailPar->_outp.mail_data._data.result_data.rc]);
        printf("  Mail result message: %s\n",
               mailPar->_outp.mail_data._data.result_data.ret_msg);
      }
      printf("  Mail parameter length: %d\n",
             mailPar->_outp.mail_data.mail_par_len);
      printf("  Mail parameter:");
      for (i = 0; i < mailPar->_outp.mail_data.mail_par_len; i++) {
        if (i % 32 == 0)
          printf("\n    ");
        else if (i % 4 == 0)
          printf(" ");
        printf("%02X", mailPar->_outp.mail_data.mail_par[i]);
      }
    }
  }
  else if (getInfoParam.hdr.FHDR_RC_MAINCODE == YMLGML_order_not_found) {
    printf("No order found.\n");
  }
  else {
    printf("Error in call of YMLGML: %08X\n",
           getInfoParam.hdr.FHDR_RC_NBR);
    if (getInfoParam.hdr.FHDR_RC_MAINCODE == YMLGML_asti_error)
      printf("  ASTI error: %08X\n", getInfoParam.out_data.asti_rc);
  }
}