Annotation of 43BSDReno/contrib/isode-beta/ftam/ftamchrg.c, revision 1.1.1.1

1.1       root        1: /* ftamchrg.c - FPM: encode/decode charging */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/ftam/RCS/ftamchrg.c,v 7.0 89/11/23 21:53:30 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/ftam/RCS/ftamchrg.c,v 7.0 89/11/23 21:53:30 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       ftamchrg.c,v $
                     12:  * Revision 7.0  89/11/23  21:53:30  mrose
                     13:  * Release 6.0
                     14:  * 
                     15:  */
                     16: 
                     17: /*
                     18:  *                               NOTICE
                     19:  *
                     20:  *    Acquisition, use, and distribution of this module and related
                     21:  *    materials are subject to the restrictions of a license agreement.
                     22:  *    Consult the Preface in the User's Manual for the full terms of
                     23:  *    this agreement.
                     24:  *
                     25:  */
                     26: 
                     27: 
                     28: /* LINTLIBRARY */
                     29: 
                     30: #include <stdio.h>
                     31: #include "fpkt.h"
                     32: 
                     33: /*  */
                     34: 
                     35: struct type_FTAM_Charging *chrg2fpm (fsb, charging, fti)
                     36: register struct ftamblk *fsb;
                     37: register struct FTAMcharging *charging;
                     38: struct FTAMindication *fti;
                     39: {
                     40:     register int    i;
                     41:     register struct fc_charge  *fc;
                     42:     struct type_FTAM_Charging *fpmp;
                     43:     register struct type_FTAM_Charging  *fpm,
                     44:                                       **fpc;
                     45:     register struct charge_element *f1;
                     46: 
                     47:     fpmp = NULL, fpc = &fpmp;
                     48:     for (fc = charging -> fc_charges, i = charging -> fc_ncharge - 1;
                     49:            i >= 0;
                     50:            fc++, i--) {
                     51:        if (fc -> fc_resource == NULL || fc -> fc_unit == NULL) {
                     52:            (void) ftamlose (fti, FS_GEN (fsb), 0, NULLCP,
                     53:                             "empty charge at slot %d",
                     54:                             charging -> fc_ncharge - i - 1);
                     55:            goto out;
                     56:        }
                     57: 
                     58:        if ((fpm = (struct type_FTAM_Charging *) calloc (1, sizeof *fpm))
                     59:                == NULL) {
                     60: no_mem: ;
                     61:            (void) ftamlose (fti, FS_GEN (fsb), 1, NULLCP, "out of memory");
                     62: out: ;
                     63:            if (fpmp)
                     64:                free_FTAM_Charging (fpmp);
                     65:            return NULL;
                     66:        }
                     67:        *fpc = fpm;
                     68: 
                     69:        if ((f1 = (struct charge_element *) calloc (1, sizeof *f1)) == NULL)
                     70:            goto no_mem;
                     71:        fpm -> charge = f1;
                     72: 
                     73:        if ((f1 -> resource__identifier = str2qb (fc -> fc_resource,
                     74:                                                  strlen (fc -> fc_resource),
                     75:                                                  1))
                     76:                    == NULL
                     77:                || (f1 -> charging__unit = str2qb (fc -> fc_unit,
                     78:                                                   strlen (fc -> fc_unit), 1))
                     79:                        == NULL)
                     80:            goto no_mem;
                     81:        f1 -> charging__value = fc -> fc_value;
                     82: 
                     83:        fpc = &fpm -> next;
                     84:     }
                     85: 
                     86:     return fpmp;
                     87: }
                     88: 
                     89: /*  */
                     90: 
                     91: int    fpm2chrg (fsb, fpm, charging, fti)
                     92: register struct ftamblk *fsb;
                     93: register struct type_FTAM_Charging *fpm;
                     94: register struct FTAMcharging *charging;
                     95: struct FTAMindication *fti;
                     96: {
                     97:     register int    i;
                     98:     register struct fc_charge *fc;
                     99:     register struct charge_element *f1;
                    100: 
                    101:     bzero ((char *) charging, sizeof *charging);
                    102: 
                    103:     fc = charging -> fc_charges, i = 0;
                    104:     for (; fpm; fpm = fpm -> next) {
                    105:        if (i >= NFCHRG)
                    106:            return ftamlose (fti, FS_GEN (fsb), 1, NULLCP,
                    107:                             "too many charges");
                    108: 
                    109:        f1 = fpm -> charge;
                    110:        if ((fc -> fc_resource = qb2str (f1 -> resource__identifier)) == NULL
                    111:                || (fc -> fc_unit = qb2str (f1 -> charging__unit)) == NULL) {
                    112:            if (fc -> fc_resource)
                    113:                free (fc -> fc_resource), fc -> fc_resource = NULL;
                    114:            while (i-- > 0) {
                    115:                fc--;
                    116:                free (fc -> fc_resource), fc -> fc_resource = NULL;
                    117:                free (fc -> fc_unit), fc -> fc_unit = NULL;
                    118:            }
                    119: 
                    120:            return ftamlose (fti, FS_GEN (fsb), 1, NULLCP, "out of memory");
                    121:        }
                    122:        fc -> fc_value = f1 -> charging__value;
                    123: 
                    124:        fc++, i++;
                    125:     }
                    126: 
                    127:     return OK;
                    128: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.