/*--------------------------------------------------------------------------*\ ID.C Version 1.1 1995 AVM Functions for ConnectionID handling \*--------------------------------------------------------------------------*/ #include #include #include #include "id.h" /*--------------------------------------------------------------------------*\ * typedefinitions \*--------------------------------------------------------------------------*/ const char *ConnectionStateString[7] = {"Disconnected", "D_ConnectPending", "D_Connected", "B_ConnectPending", "Connected", "B_DisconnectPending", "D_DisconnectPending"}; typedef struct _ConnectionDesc { unsigned InUse; long PLCI; long NCCI; long Controller; ConnectionState State; int Initiator; unsigned char *CalledPartyNumberStruct; /*----- CAPI struct -----*/ unsigned char *CallingPartyNumberStruct; /*----- CAPI struct -----*/ } ConnectionDesc; static ConnectionDesc C[maxConnections] = {0}; static unsigned char * EmptyStruct = (unsigned char *)"\0"; /*--------------------------------------------------------------------------*\ * InitConnectionIDHandling: Initialisation of internal structures. Must be * executed before using the functions in this module. \*--------------------------------------------------------------------------*/ void InitConnectionIDHandling (void) { unsigned Con; /*----- init local data -----*/ for (Con=0; Con 1) return (char *)(&(C[Con].CalledPartyNumberStruct[2])); else return (char *)EmptyStruct; } /*--------------------------------------------------------------------------*\ * GetCalledPartyNumberStruct: Returns the CalledPartyNumber belonging to the * specified connection as a CAPI struct. \*--------------------------------------------------------------------------*/ unsigned char *GetCalledPartyNumberStruct (ConnectionID Con) { return C[Con].CalledPartyNumberStruct; } /*--------------------------------------------------------------------------*\ * SetCallingPartyNumber: Sets the CallingPartyNumber belonging to the * specified connection. CalledPartyNumber has to be a zero terminated string * containing only ASCII numbers. * CallingPartyNumber contains always the number of the party that originated * the call, if it is not needed you dont need to set it. \*--------------------------------------------------------------------------*/ void SetCallingPartyNumber (ConnectionID Con, char *CallingNumber) { assert (Con != INVALID_CONNECTION_ID); assert (C[Con].InUse); FreeNumberStruct (&C[Con].CallingPartyNumberStruct); if ((CallingNumber != NULL) && (*CallingNumber != 0)) { int len; len = strlen(CallingNumber); /*----- \xLen\x00\x80 STRING '\0' -----*/ C[Con].CallingPartyNumberStruct = (unsigned char *)malloc(len + 3 + 1); assert (C[Con].CallingPartyNumberStruct != NULL); C[Con].CallingPartyNumberStruct[0] = (unsigned char)(len + 2); C[Con].CallingPartyNumberStruct[1] = 0x00; C[Con].CallingPartyNumberStruct[2] = 0x80; strcpy ((char *)&(C[Con].CallingPartyNumberStruct[3]), CallingNumber); } } /*--------------------------------------------------------------------------*\ * SetCallingPartyNumberStruct: Sets the CallingPartyNumber belonging to the * specified connection. CallingStruct has to be a valid CAPI struct. \*--------------------------------------------------------------------------*/ void SetCallingPartyNumberStruct (ConnectionID Con, unsigned char *CallingStruct) { assert (Con != INVALID_CONNECTION_ID); assert (C[Con].InUse); FreeNumberStruct (&C[Con].CallingPartyNumberStruct); if (CallingStruct != NULL) { /*----- two more for the length byte and '\0' -----*/ C[Con].CallingPartyNumberStruct = (unsigned char *)malloc((size_t)(CallingStruct[0] + 2)); assert(C[Con].CallingPartyNumberStruct != NULL); memcpy(C[Con].CallingPartyNumberStruct, CallingStruct, (size_t)(CallingStruct[0] + 1)); C[Con].CallingPartyNumberStruct[CallingStruct[0] + 1] = '\0'; } } /*--------------------------------------------------------------------------*\ * GetCallingPartyNumber: Returns the CallingPartyNumber belonging to the * specified connection as a zero terminated string. \*--------------------------------------------------------------------------*/ char *GetCallingPartyNumber (ConnectionID Con) { if (C[Con].CallingPartyNumberStruct[0] > 2) return (char *)&(C[Con].CallingPartyNumberStruct[3]); else return (char *)EmptyStruct; } /*--------------------------------------------------------------------------*\ * GetCallingPartyNumberStruct: Returns the CallingPartyNumber belonging to the * specified connection as a CAPI struct. \*--------------------------------------------------------------------------*/ unsigned char *GetCallingPartyNumberStruct (ConnectionID Con) { return C[Con].CallingPartyNumberStruct; }