/* $Id: id.c,v 1.3 2001/03/01 14:59:11 paul Exp $ * * Connection-ID management. * This stuff is based heavily on AVM's CAPI-adk for linux. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log: id.c,v $ * Revision 1.3 2001/03/01 14:59:11 paul * Various patches to fix errors when using the newest glibc, * replaced use of insecure tempnam() function * and to remove warnings etc. * * Revision 1.2 1998/10/23 12:50:55 fritz * Added RCS keywords and GPL notice. * */ #include #include #include #include "id.h" /* * type definitions */ 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; _cword Reason; _cword B3Reason; faxNCPI_t *faxNCPI; /* CAPI struct */ 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 && (*CallingNumber != 0)) { int 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) { /* 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; } void SetB3Reason(ConnectionID Con, _cword r) { assert (Con != INVALID_CONNECTION_ID); assert (C[Con].InUse); C[Con].B3Reason = r; } void SetReason(ConnectionID Con, _cword r) { assert (Con != INVALID_CONNECTION_ID); assert (C[Con].InUse); C[Con].Reason = r; } unsigned short GetB3Reason(ConnectionID Con) { assert (Con != INVALID_CONNECTION_ID); return C[Con].B3Reason; } unsigned short GetReason(ConnectionID Con) { assert (Con != INVALID_CONNECTION_ID); return C[Con].Reason; } /* * SetFaxNCPI: Sets the faxNCPI (StationId, Speed, etc.) belonging to the * specified connection. faxNCPI has to be a valid CAPI struct. */ void SetFaxNCPI (ConnectionID Con, faxNCPI_t *faxNCPI) { assert (Con != INVALID_CONNECTION_ID); assert (C[Con].InUse); if (faxNCPI) { C[Con].faxNCPI = (faxNCPI_t *)malloc(sizeof(faxNCPI_t)); assert(C[Con].faxNCPI != NULL); memset(C[Con].faxNCPI, 0, sizeof(faxNCPI_t)); memcpy(C[Con].faxNCPI, faxNCPI, (size_t)(faxNCPI->length + 1)); C[Con].faxNCPI->id[faxNCPI->idlen + 1] = '\0'; } } faxNCPI_t *GetFaxNCPI(ConnectionID Con) { return C[Con].faxNCPI; }