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

  1. /* op_msg.c msg ROS operation routines */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/qmgr/RCS/op_msg.c,v 6.0 1991/12/18 20:23:58 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/qmgr/RCS/op_msg.c,v 6.0 1991/12/18 20:23:58 jpo Rel $
  9.  *
  10.  * $Log: op_msg.c,v $
  11.  * Revision 6.0  1991/12/18  20:23:58  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include "util.h"
  17. #include "qmgr-int.h"
  18. #include "consblk.h"
  19. #include "Qmgr-types.h"
  20. #include <isode/cmd_srch.h>
  21. #include <isode/rosap.h>
  22.  
  23. #define     MSG_READ_INTERVAL    60    /* in secs */
  24.  
  25. /* ARGSUSED */
  26. int    arg_readchannelmtamessage (ad, args, arg)
  27. int    ad;
  28. char                **args; 
  29. /* args[0] = chan args[1] = mta or name in case of local chan */
  30. struct type_Qmgr_MsgRead    **arg;
  31. {
  32.     char    *str;
  33.     UTC    utc;
  34.  
  35.     *arg = (struct type_Qmgr_MsgRead *) malloc(sizeof(**arg));
  36.     bzero ((char *) *arg, sizeof(**arg));
  37.     /* fillin time */
  38.     utc = (UTC) malloc (sizeof(struct UTCtime));
  39.  
  40.     utc->ut_flags = UT_SEC;
  41.     utc->ut_sec = MSG_READ_INTERVAL;
  42.     str = utct2str(utc);
  43.     (*arg)->time = str2qb(str, strlen(str), 1);
  44.     if (args[0] != NULLCP)
  45.         (*arg)->channel = str2qb(args[0], strlen(args[0]), 1);
  46.     if (args[1] != NULLCP)
  47.         (*arg)->mta = str2qb(args[1], strlen(args[1]), 1);
  48.     return OK;
  49. }
  50.  
  51. static MsgList *convert_MsgList();
  52.  
  53. /* ARGSUSED */
  54. int res_readchannelmtamessage (ad, id, dummy, result, roi)
  55. int                        ad,
  56.                         id,
  57.                         dummy;
  58. register struct type_Qmgr_MsgList        *result;
  59. struct RoSAPindication                *roi;
  60. {
  61.     struct cons_opblk *op;
  62.  
  63.     if ((op = find_copblk(ad, id)) == NULL)
  64.         return NOTOK;
  65.     
  66.     if (op -> fnx)
  67.         (*op -> fnx)(convert_MsgList(result), id);
  68.     free_copblk (op);
  69.     return OK;
  70. }
  71.  
  72. /*   */
  73.  
  74. static struct type_Qmgr_UserList *create_userlist();
  75.  
  76. extern char *mystrtotime();
  77.  
  78. static CMD_TABLE control_tbl[] = {
  79.     CTRL_ENABLE,    type_Qmgr_Control_start,
  80.     CTRL_DISABLE,    type_Qmgr_Control_stop,
  81.     CTRL_CACHECLEAR,type_Qmgr_Control_cacheClear,
  82.     CTRL_CACHEADD,    type_Qmgr_Control_cacheAdd,
  83.     NULLCP,        NOTOK
  84.     };
  85.  
  86. /* ARGSUSED */
  87. int arg_msgcontrol (ad, args, arg)
  88. int    ad;
  89. char                **args;
  90. struct type_Qmgr_MsgControl    **arg;
  91. /* args[0] = qid */
  92. /* args[1] = time */
  93. /* args[2] = stop, start, clear cacheadd*/
  94. /* args[3..] = NULL terminated list of users */
  95. {
  96.     int n;
  97.  
  98.     *arg = (struct type_Qmgr_MsgControl *) malloc(sizeof(**arg));
  99.     
  100.     (*arg)->qid = str2qb(args[0], strlen(args[0]), 1);
  101.  
  102.     (*arg)->users = create_userlist(&(args[3]));
  103.  
  104.     (*arg)->control = (struct type_Qmgr_Control *)
  105.         malloc(sizeof(struct type_Qmgr_Control));
  106.  
  107.     if ((n = cmd_srch (args[2], control_tbl)) == NOTOK)
  108.         return NOTOK;
  109.  
  110.     if (((*arg)->control->offset = n) == type_Qmgr_Control_cacheAdd) {
  111.         char    *timestr;
  112.         timestr = mystrtotime(args[1]);
  113.         (*arg)->control->un.cacheAdd = str2qb(timestr,strlen(timestr),1);
  114.         free(timestr);
  115.     }
  116.     return OK;
  117. }
  118.  
  119. /* ARGSUSED */
  120. int res_msgcontrol (ad, id, dummy, result, roi)
  121. int    ad, id, dummy;
  122. struct type_Qmgr_Pseudo__newmessage    *result;
  123. struct RoSAPindication    *roi;
  124. {
  125.     struct cons_opblk *op;
  126.  
  127.     if ((op = find_copblk(ad, id)) == NULL)
  128.         return NOTOK;
  129.     
  130.     if (op -> fnx)
  131.         (*op -> fnx) (id);
  132.     free_copblk (op);
  133.     return OK;
  134. }
  135.  
  136. /*   */
  137.  
  138. static Strlist    *convert_EITs (pepsy)
  139. register struct type_Qmgr_EncodedInformationTypes    *pepsy;
  140. {
  141.     Strlist    *head, *tail, *temp;
  142.  
  143.     head = tail = (Strlist *) NULL;
  144.     
  145.     while (pepsy != (struct type_Qmgr_EncodedInformationTypes *) NULL) {
  146.         if (pepsy->PrintableString) {
  147.             temp = (Strlist *) calloc (1, sizeof(*temp));
  148.             temp -> str = qb2str (pepsy->PrintableString);
  149.             if (head == (Strlist *) NULL)
  150.                 head = tail = temp;
  151.             else {
  152.                 tail -> next = temp;
  153.                 tail = temp;
  154.             }
  155.         }
  156.         pepsy = pepsy -> next;
  157.     }
  158.     return head;
  159. }
  160.  
  161. static PerMessageInfo    *convert_PerMessageInfo(pepsy)
  162. register struct type_Qmgr_PerMessageInfo    *pepsy;
  163. {
  164.     PerMessageInfo    *ret;
  165.  
  166.     if (pepsy == (struct type_Qmgr_PerMessageInfo *) NULL)
  167.         return (PerMessageInfo *) NULL;
  168.  
  169.     ret = (PerMessageInfo *) calloc(1, sizeof(*ret));
  170.  
  171.     ret -> qid = qb2str(pepsy->queueid);
  172.     
  173.     if (pepsy->mpduiden) {
  174.         if (pepsy->mpduiden->global) {
  175.             if (pepsy->mpduiden->global->country)
  176.                 ret->country = 
  177.                     qb2str(pepsy->mpduiden->
  178.                            global->country -> un.printable);
  179.             if (pepsy->mpduiden->global->admd)
  180.                 ret->admd = 
  181.                     qb2str(pepsy->mpduiden->global->
  182.                            admd -> un.printable);
  183.             if (pepsy->mpduiden->global->prmd)
  184.                 ret->prmd = 
  185.                     qb2str(pepsy->mpduiden->global->
  186.                            prmd -> un.printable);
  187.         }
  188.         if (pepsy->mpduiden->local)
  189.             ret->local =
  190.                 qb2str(pepsy->mpduiden->local);
  191.     }
  192.  
  193.     ret->originator = qb2str(pepsy->originator);
  194.     if (pepsy->contenttype)
  195.         ret->contenttype = qb2str(pepsy->contenttype);
  196.     if (pepsy->eit)
  197.         ret -> eits = convert_EITs(pepsy->eit);
  198.     ret -> priority = pepsy->priority->parm;
  199.     ret -> size = pepsy->size;
  200.     ret->age = convert_time(pepsy->age);
  201.     ret -> warnInterval = pepsy -> warnInterval;
  202.     ret -> numberWarningsSent = pepsy ->numberWarningsSent;
  203.     if (pepsy -> expiryTime)
  204.         ret -> expiryTime = convert_time(pepsy -> expiryTime);
  205.     if (pepsy -> deferredTime)
  206.         ret -> deferredTime = convert_time(pepsy -> deferredTime);
  207.     if (pepsy -> uaContentId)
  208.         ret -> uaContentId = qb2str (pepsy -> uaContentId);
  209.     if (pepsy -> optionals & opt_Qmgr_PerMessageInfo_errorCount)
  210.         ret->errorCount = pepsy->errorCount;
  211.     if (pepsy -> inChannel)
  212.         ret -> inChannel = qb2str(pepsy -> inChannel);
  213.     return ret;
  214. }
  215.  
  216. static Strlist    *convert_ChannelList (pepsy)
  217. register struct type_Qmgr_ChannelList    *pepsy;
  218. {
  219.     Strlist    *head, *tail, *temp;
  220.  
  221.     head = tail = (Strlist *) NULL;
  222.     
  223.     while (pepsy != (struct type_Qmgr_ChannelList *) NULL) {
  224.         if (pepsy->Channel) {
  225.             temp = (Strlist *) calloc (1, sizeof(*temp));
  226.             temp -> str = qb2str (pepsy->Channel);
  227.             if (head == (Strlist *) NULL)
  228.                 head = tail = temp;
  229.             else {
  230.                 tail -> next = temp;
  231.                 tail = temp;
  232.             }
  233.         }
  234.         pepsy = pepsy -> next;
  235.     }
  236.     return head;
  237. }
  238.  
  239. static RecipInfo *convert_RecipientInfo (pepsy)
  240. register struct type_Qmgr_RecipientInfo    *pepsy;
  241. {
  242.     RecipInfo    *ret;
  243.  
  244.     if (pepsy == (struct type_Qmgr_RecipientInfo *) NULL)
  245.         return (RecipInfo *) NULL;
  246.  
  247.     ret = (RecipInfo *) calloc (1, sizeof(*ret));
  248.     
  249.     ret -> user = qb2str(pepsy->user);
  250.     
  251.     if (pepsy->id)
  252.         ret->id = pepsy->id->parm;
  253.  
  254.     if (pepsy->mta)
  255.         ret->mta = qb2str(pepsy->mta);
  256.     
  257.     if (pepsy->channelList)
  258.         ret->channels = convert_ChannelList(pepsy->channelList);
  259.  
  260.     ret->channelsDone = pepsy->channelsDone;
  261.     ret->status = convert_ProcStatus(pepsy->procStatus);
  262.     if (pepsy->info)
  263.         ret->info = qb2str(pepsy->info);
  264.     return ret;
  265. }
  266.     
  267. static RecipInfo *convert_RecipientList (pepsy)
  268. register struct type_Qmgr_RecipientList    *pepsy;
  269. {
  270.     RecipInfo    *head, *tail, *temp;
  271.  
  272.     head = tail = (RecipInfo *) NULL;
  273.     
  274.     while (pepsy != (struct type_Qmgr_RecipientList *) NULL) {
  275.         if (pepsy -> RecipientInfo
  276.             && ((temp = 
  277.             convert_RecipientInfo (pepsy -> RecipientInfo)) 
  278.             != (RecipInfo *) NULL)) {
  279.             if (head == (RecipInfo *) NULL)
  280.                 head = tail = temp;
  281.             else {
  282.                 tail -> next = temp;
  283.                 tail = temp;
  284.             }
  285.         }
  286.         pepsy = pepsy -> next;
  287.     }
  288.     return head;
  289. }
  290.     
  291. static MsgInfo    *convert_MsgStruct(pepsy)
  292. register struct type_Qmgr_MsgStruct    *pepsy;
  293. {
  294.     MsgInfo    *ret;
  295.  
  296.     if (pepsy == (struct type_Qmgr_MsgStruct *) NULL)
  297.         return (MsgInfo *) NULL;
  298.     
  299.     ret = (MsgInfo *) calloc (1, sizeof(*ret));
  300.     
  301.     ret -> permsginfo = convert_PerMessageInfo (pepsy -> messageinfo);
  302.     
  303.     ret -> recips = convert_RecipientList (pepsy -> recipientlist);
  304.     
  305.     return ret;
  306. }
  307.  
  308. static MsgInfo    *convert_MsgStructList(pepsy)
  309. register struct type_Qmgr_MsgStructList    *pepsy;
  310. {
  311.     MsgInfo    *head, *tail, *temp;
  312.  
  313.     head = tail = (MsgInfo *) NULL;
  314.     
  315.     while (pepsy != (struct type_Qmgr_MsgStructList *) NULL) {
  316.         if (pepsy->MsgStruct
  317.             && (temp = convert_MsgStruct(pepsy->MsgStruct)) !=
  318.             (MsgInfo *) NULL) {
  319.             if (head == (MsgInfo *) NULL)
  320.                 head = tail = temp;
  321.             else {
  322.                 tail -> next = temp;
  323.                 tail = temp;
  324.             }
  325.         }
  326.         pepsy = pepsy -> next;
  327.     }
  328.  
  329.     return head;
  330. }
  331.  
  332. static Strlist    *convert_QidList (pepsy)
  333. register struct type_Qmgr_QidList    *pepsy;
  334. {
  335.     Strlist    *head, *tail, *temp;
  336.  
  337.     head = tail = (Strlist *) NULL;
  338.     
  339.     while (pepsy != (struct type_Qmgr_QidList *) NULL) {
  340.         if (pepsy->QID) {
  341.             temp = (Strlist *) calloc (1, sizeof(*temp));
  342.             temp -> str = qb2str (pepsy->QID);
  343.             if (head == (Strlist *) NULL)
  344.                 head = tail = temp;
  345.             else {
  346.                 tail -> next = temp;
  347.                 tail = temp;
  348.             }
  349.         }
  350.         pepsy = pepsy -> next;
  351.     }
  352.     return head;
  353. }
  354.  
  355. static MsgList    *convert_MsgList(pepsy)
  356. register struct type_Qmgr_MsgList    *pepsy;
  357. {
  358.     MsgList    *ret;
  359.     
  360.     if (pepsy == (struct type_Qmgr_MsgList *) NULL)
  361.         return (MsgList *) NULL;
  362.     
  363.     ret = (MsgList *) calloc (1, sizeof(*ret));
  364.  
  365.     if (pepsy->msgs)
  366.         ret->msgs = convert_MsgStructList (pepsy->msgs);
  367.     if (pepsy->deleted)
  368.         ret->deleted = convert_QidList (pepsy->deleted);
  369.     return ret;
  370. }
  371.  
  372.  
  373. /*   */
  374.  
  375. free_MsgList(list)
  376. MsgList    *list;
  377. {
  378.     if (list -> msgs)
  379.         free_MsgInfo (list -> msgs);
  380.     if (list -> deleted)
  381.         free_Strlist (list -> deleted);
  382.     free((char *) list);
  383. }
  384.  
  385. free_Strlist(list)
  386. Strlist    *list;
  387. {
  388.     Strlist *temp;
  389.  
  390.     while (list != (Strlist *) NULL) {
  391.         if (list->str) free(list->str);
  392.         temp = list;
  393.         list = list -> next;
  394.         free((char *) temp);
  395.     }
  396. }
  397.  
  398. free_MsgInfo (info)
  399. MsgInfo    *info;
  400. {
  401.     MsgInfo    *temp;
  402.  
  403.     while ((MsgInfo *) NULL != info) {
  404.         if (info->permsginfo)
  405.             free_PerMessageInfo(info->permsginfo);
  406.         if (info->recips)
  407.             free_RecipInfo(info->recips);
  408.         temp = info;
  409.         info = info->next;
  410.         free((char *) temp);
  411.     }
  412. }
  413.  
  414. free_PerMessageInfo (permsg)
  415. PerMessageInfo    *permsg;
  416. {
  417.     if (permsg->qid) free(permsg->qid);
  418.     if (permsg->country) free(permsg->country);
  419.     if (permsg->admd) free(permsg->admd);
  420.     if (permsg->prmd) free(permsg->prmd);
  421.     if (permsg->local) free(permsg->local);
  422.     if (permsg->originator) free(permsg->originator);
  423.     if (permsg->contenttype) free(permsg->contenttype);
  424.     if (permsg->eits) free_Strlist(permsg->eits);
  425.     if (permsg->uaContentId) free(permsg->uaContentId);
  426.     if (permsg->inChannel) free(permsg->inChannel);
  427.     free((char *) permsg);
  428. }
  429.  
  430. free_RecipInfo(recips)
  431. RecipInfo    *recips;
  432. {
  433.     RecipInfo    *temp;
  434.     while (recips) {
  435.         if (recips->user) free(recips->user);
  436.         if (recips->mta) free(recips->mta);
  437.         if (recips->channels) free_Strlist(recips->channels);
  438.         if (recips->status) free_ProcStatus (recips->status);
  439.         if (recips->info) free(recips->info);
  440.         temp = recips;
  441.         recips = recips->next;
  442.         free((char *) temp);
  443.     }
  444. }
  445.  
  446. /*   */
  447.  
  448. static struct type_Qmgr_UserList    *create_userlist(argv)
  449. char    **argv;
  450. {
  451.     struct type_Qmgr_UserList    *temp,
  452.     *head = NULL,
  453.     *tail = NULL;
  454.     int                i = 0;
  455.     while (argv[i] != NULL) {
  456.         temp = (struct type_Qmgr_UserList *) 
  457.             calloc (1, sizeof(*temp));
  458.         temp->RecipientId = (struct type_Qmgr_RecipientId *) 
  459.             malloc(sizeof(struct type_Qmgr_RecipientId));
  460.         temp->RecipientId->parm = atoi(argv[i++]);
  461.         
  462.         if (head == NULL)
  463.             head = tail = temp;
  464.         else {
  465.             tail->next = temp;
  466.             tail = tail->next;
  467.         }
  468.     }
  469.  
  470.     return head;
  471. }
  472.