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