OpenSS7 SS7 for the Common Man |
© Copyright 1997-2004,OpenSS7 Corporation, All Rights Reserved. |
||||||||||||||||||||||||||
Home | Overview | Status | News | Documentation | Resources | About | |||||||||||||||||||||
File /code/strss7/lib/libxnet/t_alloc.c#ident "@(#) $RCSfile: t_alloc.c,v $ $Name: $($Revision: 0.8.2.2 $) $Date: 2003/05/27 11:21:50 $" static char const ident[] = "$RCSfile: t_alloc.c,v $ $Name: $($Revision: 0.8.2.2 $) $Date: 2003/05/27 11:21:50 $"; #include <stdlib.h> #include <string.h> #include <sys/xti.h> #include <timod.h> #include "xti.h" void *t_alloc(int fd, int type, int fields) { struct t_info info = { 0, }; if (fields & ~T_ALL) goto tbadflag; switch (type) { case T_BIND: { struct t_bind *bind; if ((fields & T_ADDR) && !t_getinfo(fd, &info)) goto error; if (!(bind = malloc(sizeof(*bind)))) goto badalloc; memset(bind, 0, sizeof(*bind)); if (fields & T_ADDR) { switch (info.addr) { case T_INFINITE: info.addr = _T_DEFAULT_ADDRLEN; break; case 0: case T_INVALID: free(bind); goto tbadflag; } bind->addr.maxlen = bind->addr.len = info.addr; if (!(bind->addr.buf = malloc(info.addr))) { free(bind); goto badalloc; } } return (bind); } case T_OPTMGMT: { struct t_optmgmt *opts; if ((fields & T_OPT) && !t_getinfo(fd, &info)) goto error; if (!(opts = malloc(sizeof(*opts)))) goto badalloc; memset(opts, 0, sizeof(*opts)); if (fields & T_OPT) { switch (info.options) { case T_INFINITE: info.options = _T_DEFAULT_OPTLEN; break; case 0: case T_INVALID: free(opts); goto tbadflag; } if (!(opts->opt.buf = malloc(info.options))) { free(opts); goto badalloc; } opts->opt.maxlen = opts->opt.len = info.options; } return (opts); } case T_CALL: { struct t_call *call; if ((fields & (T_ADDR | T_OPT | T_UDATA)) && !t_getinfo(fd, &info)) goto error; if (!(call = malloc(sizeof(*call)))) goto badalloc; memset(call, 0, sizeof(*call)); if (fields & T_ADDR) { switch (info.addr) { case T_INFINITE: info.addr = _T_DEFAULT_ADDRLEN; break; case 0: case T_INVALID: free(call); goto tbadflag; } if (!(call->addr.buf = malloc(info.addr))) { free(call); goto badalloc; } call->addr.maxlen = call->addr.len = info.addr; } if (fields & T_OPT) { switch (info.options) { case T_INFINITE: info.options = _T_DEFAULT_OPTLEN; break; case 0: case T_INVALID: free(call); goto tbadflag; } if (!(call->opt.buf = malloc(info.options))) { if (call->addr.buf) free(call->addr.buf); free(call); goto badalloc; } call->opt.maxlen = call->opt.len = info.options; } if (fields & T_UDATA) { switch (info.connect) { case T_INFINITE: info.connect = _T_DEFAULT_CONNLEN; break; case 0: case T_INVALID: free(call); goto tbadflag; } if (!(call->udata.buf = malloc(info.connect))) { if (call->addr.buf) free(call->addr.buf); if (call->opt.buf) free(call->opt.buf); free(call); goto badalloc; } call->udata.maxlen = call->udata.len = info.connect; } return (call); } case T_DIS: { struct t_discon *discon; if ((fields & T_UDATA) && !t_getinfo(fd, &info)) goto error; if (!(discon = malloc(sizeof(*discon)))) goto badalloc; memset(discon, 0, sizeof(*discon)); if (fields & T_UDATA) { switch (info.discon) { case T_INFINITE: info.discon = _T_DEFAULT_DISCLEN;; break; case 0: case T_INVALID: free(discon); goto tbadflag; } if (!(discon->udata.buf = malloc(info.discon))) { free(discon); goto badalloc; } discon->udata.maxlen = discon->udata.len = info.discon; } return (discon); } case T_UNITDATA: { struct t_unitdata *udata; if ((fields & (T_ADDR | T_OPT | T_UDATA)) && !t_getinfo(fd, &info)) goto error; if (!(udata = malloc(sizeof(*udata)))) goto badalloc; memset(udata, 0, sizeof(*udata)); if (fields & T_ADDR) { switch (info.addr) { case T_INFINITE: info.addr = _T_DEFAULT_ADDRLEN; break; case 0: case T_INVALID: free(udata); goto tbadflag; } if (!(udata->addr.buf = malloc(info.addr))) { free(udata); goto badalloc; } udata->addr.maxlen = udata->addr.len = info.addr; } if (fields & T_OPT) { switch (info.options) { case T_INFINITE: info.options = _T_DEFAULT_OPTLEN; break; case 0: case T_INVALID: free(udata); goto tbadflag; } if (!(udata->opt.buf = malloc(info.options))) { if (udata->addr.buf) free(udata->addr.buf); free(udata); goto badalloc; } udata->opt.maxlen = udata->opt.len = info.options; } if (fields & T_UDATA) { switch (info.tsdu) { case T_INFINITE: info.tsdu = _T_DEFAULT_DATALEN; break; case 0: case T_INVALID: free(udata); goto tbadflag; } if (!(udata->udata.buf = malloc(info.tsdu))) { free(udata); goto badalloc; } udata->udata.maxlen = udata->udata.len = info.tsdu; } return (udata); } case T_UDERROR: { struct t_uderr *uderr; if ((fields & (T_ADDR | T_OPT)) && !t_getinfo(fd, &info)) goto error; if (!(uderr = malloc(sizeof(*uderr)))) goto badalloc; memset(uderr, 0, sizeof(*uderr)); if (fields & T_ADDR) { switch (info.addr) { case T_INFINITE: info.addr = _T_DEFAULT_ADDRLEN; break; case 0: case T_INVALID: free(uderr); goto tbadflag; } if (!(uderr->addr.buf = malloc(info.addr))) { free(uderr); goto badalloc; } uderr->addr.maxlen = uderr->addr.len = info.addr; } if (fields & T_OPT) { switch (info.options) { case T_INFINITE: info.options = _T_DEFAULT_OPTLEN; break; case 0: case T_INVALID: free(uderr); goto tbadflag; } if (!(uderr->opt.buf = malloc(info.options))) { if (uderr->addr.buf) free(uderr->addr.buf); free(uderr); goto badalloc; } uderr->opt.maxlen = uderr->opt.len = info.options; } return (uderr); } case T_INFO: { struct t_info *inf; if (!(inf = malloc(sizeof(*inf)))) goto badalloc; memset(inf, 0, sizeof(*inf)); return (inf); } default: goto tnostructype; } tnostructype: t_errno = TNOSTRUCTYPE; goto error; tbadflag: t_errno = TBADFLAG; goto error; badalloc: t_errno = TSYSERR; goto error; error: return (NULL); }
|
|||||||||||||||||||||||||||
OpenSS7 SS7 for the Common Man |
Home | Overview | Status | News | Documentation | Resources | About | ||||||||||||||||||||
© Copyright 1997-2004,OpenSS7 Corporation, All Rights Reserved. |