home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / qmgr / qstruct2qmgr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  13.7 KB  |  580 lines

  1. /* qstruct2qmgr.c: conversion routine from verbose submit struct to concise
  2. qmgr struct */
  3.  
  4. # ifndef lint
  5. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/qmgr/RCS/qstruct2qmgr.c,v 6.0 1991/12/18 20:23:58 jpo Rel $";
  6. # endif
  7.  
  8. /*
  9.  * $Header: /xtel/pp/pp-beta/Lib/qmgr/RCS/qstruct2qmgr.c,v 6.0 1991/12/18 20:23:58 jpo Rel $
  10.  *
  11.  * $Log: qstruct2qmgr.c,v $
  12.  * Revision 6.0  1991/12/18  20:23:58  jpo
  13.  * Release 6.0
  14.  *
  15.  */
  16.  
  17.  
  18.  
  19. #include "util.h"
  20. #include <isode/cmd_srch.h>
  21.  
  22. /* Qmgr types */
  23. #include "Qmgr-types.h"
  24.  
  25. /* Sumbit types */
  26. #include "q.h"
  27. #include "prm.h"
  28.  
  29. extern CMD_TABLE qtbl_con_type[];
  30. /*   */
  31. /* Routines */
  32. extern time_t utctotime();
  33. static struct type_Qmgr_PerMessageInfo *fillin_messageinfo();
  34. static struct type_Qmgr_MPDUIdentifier *fillin_mpduiden();
  35. static struct type_Qmgr_GlobalDomainIdentifier *fillin_gldmdid();
  36. static struct type_Qmgr_CountryName *fillin_country();
  37. static struct type_Qmgr_AdministrationDomainName *fillin_admd();
  38. static struct type_Qmgr_PrivateDomainIdentifier *fillin_prmd();
  39. static struct type_Qmgr_ContentType *fillin_content();
  40. static struct type_Qmgr_EncodedInformationTypes *fillin_eit();
  41. static struct type_Qmgr_Priority *fillin_prio();
  42. static struct type_UNIV_UTCTime *fillin_age();
  43. static struct type_UNIV_UTCTime *fillin_expiryTime();
  44. static struct type_UNIV_UTCTime *fillin_deferredTime();
  45. static struct type_Qmgr_User *fillin_user();
  46. static struct type_Qmgr_RecipientList *fillin_reciplist();
  47. static struct type_Qmgr_RecipientInfo *fillin_recip();
  48. static struct type_Qmgr_ChannelList *fillin_chans();
  49.  
  50. /* error flag and values */
  51. int fatal_errors;
  52.  
  53. /*   */
  54.  
  55. /* routine to initialise a qstruct */
  56. void qinit (que)
  57. Q_struct *que;
  58. {
  59.     que->inbound = NULL;
  60.     que->encodedinfo.eit_types = NULL;
  61.     que->orig_encodedinfo.eit_types = NULL;
  62.     que->ua_id = NULL;
  63.     que->msgid.mpduid_DomId.global_Country = NULL;
  64.     que->msgid.mpduid_DomId.global_Admin = NULL;
  65.     que->msgid.mpduid_DomId.global_Private = NULL;
  66.     que->msgid.mpduid_string = NULL;
  67.     que->trace = NULL;
  68.     que->Oaddress = NULL;
  69.     que->Raddress = NULL;
  70. }
  71.  
  72. /* conversion routine */
  73. struct type_Qmgr_MsgStruct *qstruct2qmgr (file,prm,que,sender,recip,rcount)
  74. char            *file;
  75. struct prm_vars *prm;
  76. Q_struct        *que;
  77. ADDR            *sender;
  78. ADDR            *recip;
  79. int             rcount;
  80. {
  81.     struct type_Qmgr_MsgStruct *msg;
  82.  
  83.     /*
  84.     if fatal_errors becomes true something missing that must be there
  85.     */
  86.     fatal_errors = FALSE;
  87.  
  88.     msg = (struct type_Qmgr_MsgStruct *) calloc (1, sizeof ( *msg));
  89.  
  90.     msg->messageinfo = fillin_messageinfo (file,prm,que,sender);
  91.     msg->recipientlist = fillin_reciplist (file,sender,recip,rcount);
  92.  
  93. /*      if (msg->recipientlist == NULL) {
  94. *               PP_LOG(LLOG_NOTICE,
  95. *                      ("Lib/qmgr/qstruct2qmgr : no recipients for '%s'",file));
  96. *               free_Qmgr_MsgStruct(msg);
  97. *               msg = NULL;
  98. *       }*/
  99.  
  100.     if (fatal_errors == TRUE) {
  101.         free_Qmgr_MsgStruct (msg);
  102.         msg = NULL;
  103.     }
  104.     return msg;
  105.  
  106. }
  107.  
  108. /*   */
  109. /* per message info routines */
  110.  
  111. /* ARGSUSED */
  112. static struct type_Qmgr_PerMessageInfo *fillin_messageinfo (
  113.                       file,prm,que,sender)
  114. char            *file;
  115. struct prm_vars *prm;
  116. Q_struct        *que;
  117. ADDR            *sender;
  118. {
  119.     struct type_Qmgr_PerMessageInfo *qmi;
  120.  
  121.     qmi = (struct type_Qmgr_PerMessageInfo *)
  122.         calloc (1, sizeof ( *qmi));
  123.  
  124.     if (file != NULLCP)
  125.         qmi->queueid = (struct qbuf *)
  126.                 str2qb (file, strlen(file), 1);
  127.     else {
  128.         PP_OPER (file, ("Lib/qmgr/qstruct2qmgr: null queueid"));
  129.         fatal_errors = TRUE;
  130.     }
  131.     qmi->mpduiden = fillin_mpduiden (que->msgid);
  132.     qmi->originator = fillin_user (sender,file);
  133.     qmi->contenttype = fillin_content (que);
  134.     qmi->eit = fillin_eit (que);
  135.     qmi->priority = fillin_prio (que);
  136.     qmi->size = que->msgsize;
  137.     qmi->age = fillin_age (que);
  138.     qmi->warnInterval = que->warninterval;
  139.     qmi->numberWarningsSent = que->nwarns;
  140.     qmi->expiryTime = fillin_expiryTime (que);
  141.     qmi->deferredTime = fillin_deferredTime (que);
  142.     if (que->ua_id != NULL)
  143.         qmi->uaContentId = (struct qbuf *)
  144.                    str2qb (que->ua_id,strlen (que->ua_id),1);
  145.     else qmi->uaContentId = NULL;
  146.     if (que -> inbound && que -> inbound -> li_chan)
  147.         qmi -> inChannel =
  148.             str2qb (que -> inbound -> li_chan -> ch_name,
  149.                 strlen (que -> inbound -> li_chan -> ch_name),
  150.                 1);
  151.     return qmi;
  152. }
  153.  
  154.  
  155.  
  156. static struct type_Qmgr_MPDUIdentifier *fillin_mpduiden (msgid)
  157. MPDUid  msgid;
  158. {
  159.     struct type_Qmgr_MPDUIdentifier *mpdu;
  160.  
  161.     mpdu = (struct type_Qmgr_MPDUIdentifier *)
  162.         calloc (1, sizeof (*mpdu));
  163.  
  164.     mpdu->global = fillin_gldmdid (msgid);
  165.     if (msgid.mpduid_string == NULL) {
  166.         PP_OPER(NULLCP,
  167.             ("Lib/qmgr/qstruct2qmgr: missing MsgId string"));
  168.         fatal_errors = TRUE;
  169.  
  170.         mpdu->local = NULL;
  171.     } else
  172.         mpdu->local = str2qb (msgid.mpduid_string,
  173.                         strlen (msgid.mpduid_string),
  174.                         1);
  175.  
  176.     return mpdu;
  177. }
  178.  
  179. static struct type_Qmgr_GlobalDomainIdentifier *fillin_gldmdid (msgid)
  180. MPDUid  msgid;
  181. {
  182.     struct type_Qmgr_GlobalDomainIdentifier *glid;
  183.  
  184.     glid = (struct type_Qmgr_GlobalDomainIdentifier *)
  185.         calloc (1,sizeof (*glid));
  186.  
  187.     glid->country = fillin_country (msgid);
  188.     glid->admd = fillin_admd (msgid);
  189.     glid->prmd = fillin_prmd (msgid);
  190.     return glid;
  191. }
  192.  
  193. static struct type_Qmgr_CountryName *fillin_country (msgid)
  194. MPDUid  msgid;
  195. {
  196.     struct type_Qmgr_CountryName *country;
  197.  
  198.     country = (struct type_Qmgr_CountryName *)
  199.           calloc (1,sizeof (*country));
  200.  
  201.     country->offset = type_Qmgr_CountryName_printable;
  202.     if (msgid.mpduid_DomId.global_Country == NULL) {
  203.         PP_OPER (NULLCP,
  204.             ("Lib/qmgr/qstruct2qmgr : missing MsgId country"));
  205.         fatal_errors = TRUE;
  206.         country->un.printable = NULL;
  207.  
  208.     } else
  209.         country->un.printable = str2qb (
  210.                   msgid.mpduid_DomId.global_Country,
  211.                   strlen (msgid.mpduid_DomId.global_Country),
  212.                   1);
  213.  
  214.     return country;
  215. }
  216.  
  217. static struct type_Qmgr_AdministrationDomainName *fillin_admd (msgid)
  218. MPDUid  msgid;
  219. {
  220.     struct type_Qmgr_AdministrationDomainName *admd;
  221.  
  222.     admd = (struct type_Qmgr_AdministrationDomainName *)
  223.         calloc (1,sizeof (*admd));
  224.  
  225.     admd->offset = type_Qmgr_AdministrationDomainName_printable;
  226.     if (msgid.mpduid_DomId.global_Admin == NULL) {
  227.         PP_OPER(NULLCP,
  228.             ("Lib/qmgr/qstruct2 missing MsgId admin domain"));
  229.         fatal_errors = TRUE;
  230.         admd->un.printable = NULL;
  231.     } else
  232.         admd->un.printable = str2qb (
  233.                    msgid.mpduid_DomId.global_Admin,
  234.                    strlen (msgid.mpduid_DomId.global_Admin),
  235.                    1);
  236.     return admd;
  237. }
  238.  
  239. static struct type_Qmgr_PrivateDomainIdentifier *fillin_prmd (msgid)
  240. MPDUid  msgid;
  241. {
  242.     struct type_Qmgr_PrivateDomainIdentifier *prmd = NULL;
  243.  
  244.     if (msgid.mpduid_DomId.global_Private != NULL) {
  245.  
  246.         prmd = (struct type_Qmgr_PrivateDomainIdentifier *)
  247.             calloc (1,sizeof (*prmd));
  248.  
  249.         prmd->offset = type_Qmgr_PrivateDomainIdentifier_printable;
  250.         prmd->un.printable = str2qb (
  251.                          msgid.mpduid_DomId.global_Private,
  252.                          strlen (msgid.mpduid_DomId.global_Private),
  253.                          1);
  254.     }
  255.     return prmd;
  256. }
  257.  
  258. static struct type_Qmgr_ContentType *fillin_content (que)
  259. Q_struct        *que;
  260. {
  261.     char *str = que->cont_type;
  262.  
  263.     if (str)
  264.         return str2qb (str,strlen (str),1);
  265.     return NULL;
  266. }
  267.  
  268. static struct type_Qmgr_EncodedInformationTypes *fillin_eit (que)
  269. Q_struct        *que;
  270. {
  271.     struct type_Qmgr_EncodedInformationTypes *head = NULL,
  272.                          *tail = NULL,
  273.                          *temp = NULL;
  274.     LIST_BPT *ix = que->encodedinfo.eit_types;
  275.  
  276.     while (ix != NULL) {
  277.         temp = (struct type_Qmgr_EncodedInformationTypes *)
  278.             calloc (1, sizeof (*temp));
  279.         temp->PrintableString = str2qb (ix->li_name, 
  280.                            strlen (ix->li_name),
  281.                            1);
  282.         if (head == NULL)
  283.             head = tail = temp;
  284.         else {
  285.             tail->next = temp;
  286.             tail = temp;
  287.         }
  288.         ix = ix->li_next;
  289.     }
  290.     return head;
  291. }
  292.  
  293. static struct type_Qmgr_Priority *fillin_prio (que)
  294. Q_struct        *que;
  295. {
  296.     struct type_Qmgr_Priority *prio;
  297.  
  298.     prio = (struct type_Qmgr_Priority *) calloc (1,sizeof (*prio));
  299.     prio->parm = que->priority;
  300.     return prio;
  301. }
  302.  
  303. static struct type_UNIV_UTCTime *fillin_age (que)
  304. Q_struct        *que;
  305. {
  306.     struct type_UNIV_UTCTime *ti;
  307.     char *str;
  308.  
  309.     str = utct2str (que->queuetime);
  310.     ti = str2qb (str,strlen (str),1);
  311.  
  312.     return ti;
  313. }
  314.  
  315.  
  316. static struct type_UNIV_UTCTime *fillin_expiryTime (que)
  317. Q_struct        *que;
  318. {
  319.     time_t t;
  320.     UTC utc;
  321.     char *str;
  322.  
  323.     /* expiry time = queuetime + retinterval */
  324.  
  325.     t = utc2time_t (que -> queuetime);
  326.     t += que -> retinterval * 60 * 60;
  327.     utc = time_t2utc (t);
  328.     str = utct2str (utc);
  329.     free ((char *)utc);
  330.     return str2qb (str, strlen (str), 1);
  331. }
  332.  
  333. static struct type_UNIV_UTCTime *fillin_deferredTime (que)
  334. Q_struct        *que;
  335. {
  336.     struct type_UNIV_UTCTime *ti;
  337.     char *str;
  338.  
  339.     if (que -> defertime)
  340.         str = utct2str (que->defertime);
  341.     else
  342.         return NULL;
  343.  
  344.     ti = str2qb (str, strlen (str), 1);
  345.  
  346.     return ti;
  347. }
  348.  
  349. static struct type_Qmgr_User *fillin_user (usr,file)
  350. ADDR            *usr;
  351. char            *file;
  352. {
  353.     struct type_Qmgr_User *user = NULL;
  354.     switch (usr->ad_type) {
  355.         case AD_X400_TYPE:
  356.         if (usr->ad_r400adr == NULL) {
  357.             PP_OPER(NULLCP,
  358.                 ("Lib/qmgr/qstruct2qmgr: ad_r400adr = nil in %s",file));
  359.             fatal_errors = TRUE;
  360.         } else
  361.             user = (struct type_Qmgr_User *)
  362.                 str2qb (usr->ad_r400adr, strlen (usr->ad_r400adr), 1);
  363.         break;
  364.         case AD_822_TYPE:
  365.         if (usr->ad_r822adr == NULL) {
  366.             PP_OPER(NULLCP,
  367.                 ("Lib/qmgr/qstruct2qmgr: ad_r822adr = nil in %s",file));
  368.             fatal_errors = TRUE;
  369.         } else 
  370.             user = (struct type_Qmgr_User *)
  371.                 str2qb (usr->ad_r822adr, strlen (usr->ad_r822adr), 1);
  372.         break;
  373.         case AD_ANY_TYPE:
  374.         if (usr->ad_value == NULL) {
  375.             PP_OPER(NULLCP,
  376.                 ("Lib/qmgr/qstruct2qmgr: ad_value = nil in %s",file));
  377.             fatal_errors = TRUE;
  378.         } else
  379.             user = (struct type_Qmgr_User *)
  380.                 str2qb (usr->ad_value, strlen (usr->ad_value), 1);
  381.         break;
  382.         default:
  383.         PP_OPER (NULLCP,
  384.             ("Lib/qmgr/qstruct2qmgr: unknown address type in %s",
  385.             file));
  386.         fatal_errors = TRUE;
  387.         break;
  388.     }
  389.     return user;
  390. }
  391.  
  392. /*   */
  393. /* recip list routines */
  394. static struct type_Qmgr_RecipientList *fillin_reciplist (file,sender,recip,rcount)
  395. char            *file;
  396. ADDR            *sender;
  397. ADDR            *recip;
  398. int             rcount;
  399. {
  400.     struct type_Qmgr_RecipientList *ri, *head, *tail;
  401.     int                     ix;
  402.     ADDR                    *adr;
  403.  
  404.     head = tail = NULL;
  405.     ix = 0;
  406.     adr = recip;
  407.  
  408.     /* deal with sender */
  409.     ri = (struct type_Qmgr_RecipientList *) calloc(1, sizeof(*ri));
  410.     ri->RecipientInfo = fillin_recip(file, sender);
  411.     head = tail = ri;
  412.  
  413.     while (ix++ < rcount && adr != NULLADDR) {
  414.         if (adr->ad_status != AD_STAT_DONE) {
  415.             /* okay to pass to qmgr */
  416.  
  417.             ri = (struct type_Qmgr_RecipientList *)
  418.                 calloc (1, sizeof (*ri));
  419.             ri->RecipientInfo = fillin_recip (file,adr);
  420.  
  421.             /* add to list */
  422.             tail->next = ri;
  423.             tail = ri;
  424.         }
  425.         adr = adr->ad_next;
  426.     }
  427.     if (adr)
  428.         PP_LOG(LLOG_NOTICE,
  429.                ("qstruct2qmgr/fillin_reciplist: discrepancy between rcount and recip (number in recip list < rcount)"));
  430.     return head;
  431. }
  432.  
  433. static int countChans(list)
  434. struct type_Qmgr_ChannelList    *list;
  435. {
  436.     int     count = 0;
  437.     while (list != NULL) {
  438.         count++;
  439.         list = list->next;
  440.     }
  441.  
  442.     return count;
  443. }
  444.  
  445.  
  446. static struct type_Qmgr_RecipientInfo *fillin_recip (file, recip)
  447. char            *file;
  448. ADDR            *recip;
  449. {
  450.     struct type_Qmgr_RecipientInfo *ri;
  451.  
  452.     ri = (struct type_Qmgr_RecipientInfo *) calloc (1,sizeof (*ri));
  453.     ri->user = fillin_user (recip,file);
  454.     ri->id = (struct type_Qmgr_RecipientId *) calloc (1, sizeof *ri->id);
  455.     ri -> id -> parm = recip->ad_no;
  456.  
  457.  
  458.     /* --- *** ---
  459.     Note:   if a non DR is to be sent for that recipient then the
  460.         output channel and mta is not required as the sender's
  461.         info is used instead
  462.         BUT mta is not OPTIONAL in ASN.1 so put dummy value in 
  463.     --- *** --- */
  464.  
  465.  
  466.     if (recip->ad_outchan
  467.         && recip->ad_outchan->li_mta != NULLCP)
  468.         ri->mta = (struct type_Qmgr_Mta *)
  469.             str2qb (recip->ad_outchan->li_mta,
  470.                 strlen (recip->ad_outchan->li_mta), 1);
  471.     else if (recip->ad_status == AD_STAT_DRWRITTEN) 
  472.         ri->mta = (struct type_Qmgr_Mta *)
  473.             str2qb("Delivery Report Written",
  474.                 strlen("Delivery Report Written"), 1);
  475.     else {
  476.         PP_OPER (NULLCP,
  477.             ("Lib/qmgr/qstruct2qmgr: %s '%s'",
  478.             "missing recipient mta name in",
  479.             file));
  480.         fatal_errors = TRUE;
  481.     }
  482.  
  483.  
  484.     ri->channelList = fillin_chans (
  485.                     file,
  486.                     recip->ad_status,
  487.                     recip->ad_fmtchan,
  488.                     recip->ad_outchan
  489.                     );
  490.     if (recip->ad_status == AD_STAT_DRWRITTEN)
  491.         ri -> channelsDone = countChans(ri->channelList);
  492.     else
  493.         ri -> channelsDone = recip -> ad_rcnt;
  494.     return ri;
  495. }
  496.  
  497.  
  498. static struct type_Qmgr_ChannelList *fillin_chans (file,status,fmt,out)
  499. char            *file;
  500. int             status;
  501. LIST_RCHAN      *fmt,
  502.         *out;
  503. {
  504.     struct type_Qmgr_ChannelList *head = NULL, *ptr, *tmp;
  505.     LIST_RCHAN *ix;
  506.  
  507.     /* formatters */
  508.     ix = fmt;
  509.     while (ix != NULL) {
  510.         tmp = (struct type_Qmgr_ChannelList *)
  511.             calloc (1,sizeof (*tmp));
  512.         tmp->next = NULL;
  513.         if ((ix->li_chan != NULL)
  514.            && (ix->li_chan->ch_name != NULL))
  515.             tmp->Channel = (struct type_Qmgr_Channel *)
  516.                     str2qb (ix->li_chan->ch_name,
  517.                            strlen (ix->li_chan->ch_name),
  518.                            1);
  519.         else {
  520.             PP_OPER (NULLCP,
  521.                 ("Lib/qmgr/qstruct2qmgr: %s '%s'",
  522.                 "null channel name in",
  523.                 file));
  524.             fatal_errors = TRUE;
  525.         }
  526.  
  527.         /* add to list */
  528.         if (head == NULL)
  529.             head = tmp;
  530.         else {
  531.             ptr = head;
  532.             while (ptr->next != NULL)
  533.                 ptr = ptr->next;
  534.             ptr->next = tmp;
  535.         }
  536.         ix = ix->li_next;
  537.     }
  538.  
  539.     /* outputters */
  540.     ix = out;
  541.     if ((ix == NULL) && (status != AD_STAT_DRWRITTEN)) {
  542.             PP_OPER (NULLCP,
  543.                 ("Lib/qmgr/qstruct2qmgr: %s '%s'",
  544.                 "missing out channel in",
  545.                 file));
  546.             fatal_errors = TRUE;
  547.     } 
  548.  
  549.     while (ix != NULL) {
  550.         tmp = (struct type_Qmgr_ChannelList *)
  551.             calloc (1,sizeof (*tmp));
  552.         tmp->next = NULL;
  553.         if ((ix->li_chan != NULL)
  554.             && (ix->li_chan->ch_name != NULL))
  555.             tmp->Channel = (struct type_Qmgr_Channel *)
  556.                 str2qb (ix->li_chan->ch_name,
  557.                 strlen (ix->li_chan->ch_name),
  558.                 1);
  559.         else {
  560.             PP_OPER (NULLCP,
  561.                 ("Lib/qmgr/qstruct2qmgr: %s '%s'",
  562.                 "null out channel name in",
  563.                 file));
  564.             fatal_errors = TRUE;
  565.         }
  566.  
  567.         /* add to list */
  568.         if (head == NULL)
  569.             head = tmp;
  570.         else {
  571.             ptr = head;
  572.             while (ptr->next != NULL)
  573.                 ptr = ptr->next;
  574.             ptr->next = tmp;
  575.         }
  576.         ix = ix->li_next;
  577.     }
  578.     return head;
  579. }
  580.