00001 /*[ 00002 * Copyright (c) 2007 Integration Engineering Laboratory 00003 University of California, Davis 00004 * 00005 * Permission to use, copy, and distribute this software and its 00006 * documentation for any purpose with or without fee is hereby granted, 00007 * provided that the above copyright notice appear in all copies and 00008 * that both that copyright notice and this permission notice appear 00009 * in supporting documentation. 00010 * 00011 * Permission to modify the software is granted, but not the right to 00012 * distribute the complete modified source code. Modifications are to 00013 * be distributed as patches to the released version. Permission to 00014 * distribute binaries produced by compiling modified sources is granted, 00015 * provided you 00016 * 1. distribute the corresponding source modifications from the 00017 * released version in the form of a patch file along with the binaries, 00018 * 2. add special version identification to distinguish your version 00019 * in addition to the base release version number, 00020 * 3. provide your name and address as the primary contact for the 00021 * support of your modified version, and 00022 * 4. retain our contact information in regard to use of the base 00023 * software. 00024 * Permission to distribute the released version of the source code along 00025 * with corresponding source modifications in the form of a patch file is 00026 * granted with same provisions 2 through 4 for binary distributions. 00027 * 00028 * This software is provided "as is" without express or implied warranty 00029 * to the extent permitted by applicable law. 00030 ]*/ 00031 00032 #include <stdio.h> 00033 #include <stdlib.h> 00034 #include <string.h> 00035 #include "include/connection.h" 00036 #include "include/mc_error.h" 00037 00038 int 00039 connection_Destroy(connection_p connection) 00040 { 00041 if(connection == NULL) { 00042 return MC_SUCCESS; 00043 } 00044 /* Close the connection, just to make sure. */ 00045 #ifndef _WIN32 00046 close(connection->clientfd); 00047 #else 00048 closesocket(connection->clientfd); 00049 #endif 00050 00051 if(connection->remote_hostname != NULL) { 00052 free(connection->remote_hostname); 00053 } 00054 00055 free(connection); 00056 return MC_SUCCESS; 00057 } 00058 00059 connection_p connection_New(void) 00060 { 00061 connection_p connection; 00062 connection = (connection_p)malloc(sizeof(connection_t)); 00063 if (connection==NULL) { 00064 fprintf(stderr, "Memory error. %s:%d\n", __FILE__, __LINE__); 00065 } 00066 memset(connection, 0, sizeof(connection_t)); 00067 return connection; 00068 } 00069 00070 connection_p connection_Copy(connection_p connection) 00071 { 00072 connection_p tmp = connection_New(); 00073 tmp->connect_id = connection->connect_id; 00074 tmp->remote_hostname = strdup(connection->remote_hostname); 00075 tmp->addr = connection->addr; 00076 tmp->clientfd = connection->clientfd; 00077 tmp->serverfd = connection->serverfd; 00078 00079 return tmp; 00080 } 00081