1 /* ccapi/server/win/ccs_win_pipe.c */ 2 /* 3 * Copyright 2008 Massachusetts Institute of Technology. 4 * All Rights Reserved. 5 * 6 * Export of this software from the United States of America may 7 * require a specific license from the United States Government. 8 * It is the responsibility of any person or organization contemplating 9 * export to obtain such a license before exporting. 10 * 11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 12 * distribute this software and its documentation for any purpose and 13 * without fee is hereby granted, provided that the above copyright 14 * notice appear in all copies and that both that copyright notice and 15 * this permission notice appear in supporting documentation, and that 16 * the name of M.I.T. not be used in advertising or publicity pertaining 17 * to distribution of the software without specific, written prior 18 * permission. Furthermore if you modify this software you must label 19 * your software as modified software and not distribute it in such a 20 * fashion that it might be confused with the original M.I.T. software. 21 * M.I.T. makes no representations about the suitability of 22 * this software for any purpose. It is provided "as is" without express 23 * or implied warranty. 24 */ 25 26 #include "assert.h" 27 #include <stdlib.h> 28 #include <malloc.h> 29 30 #include "ccs_win_pipe.h" 31 #include "cci_debugging.h" 32 33 /* Ref: 34 struct ccs_win_pipe_t { 35 char* uuid; 36 UINT64 clientHandle; 37 } 38 */ 39 40 /* ------------------------------------------------------------------------ */ 41 42 struct ccs_win_pipe_t* ccs_win_pipe_new (const char* uuid, const UINT64 h) { 43 44 cc_int32 err = ccNoError; 45 struct ccs_win_pipe_t* out_pipe = NULL; 46 char* uuidCopy = NULL; 47 48 if (!err) { 49 if (!uuid) {err = cci_check_error(ccErrBadParam);} 50 } 51 52 if (!err) { 53 uuidCopy = (char*)malloc(1+strlen(uuid)); 54 if (!uuidCopy) {err = cci_check_error(ccErrBadParam);} 55 strcpy(uuidCopy, uuid); 56 } 57 58 if (!err) { 59 out_pipe = (struct ccs_win_pipe_t*)malloc(sizeof(struct ccs_win_pipe_t)); 60 if (!out_pipe) {err = cci_check_error(ccErrBadParam);} 61 out_pipe->uuid = uuidCopy; 62 out_pipe->clientHandle = h; 63 } 64 65 return out_pipe; 66 } 67 68 /* ------------------------------------------------------------------------ */ 69 70 cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe, 71 const WIN_PIPE* in_pipe) { 72 73 *out_pipe = 74 ccs_win_pipe_new( 75 ccs_win_pipe_getUuid (in_pipe), 76 ccs_win_pipe_getHandle(in_pipe) ); 77 78 return (*out_pipe) ? ccNoError : ccErrBadParam; 79 } 80 81 /* ------------------------------------------------------------------------ */ 82 83 cc_int32 ccs_win_pipe_release(const WIN_PIPE* in_pipe) { 84 85 cc_int32 err = ccNoError; 86 87 if (!ccs_win_pipe_valid(in_pipe)) {err = cci_check_error(ccErrBadParam);} 88 89 if (!err) { 90 if (!in_pipe->uuid) free(in_pipe->uuid); 91 if (!in_pipe) free(in_pipe); 92 } 93 94 return err; 95 } 96 97 /* ------------------------------------------------------------------------ */ 98 99 cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe) { 100 101 if (!in_pipe) { 102 cci_check_error(ccErrBadParam); 103 return FALSE; 104 } 105 106 if (!in_pipe->uuid) { 107 cci_check_error(ccErrBadParam); 108 return FALSE; 109 } 110 111 return TRUE; 112 } 113 114 /* ------------------------------------------------------------------------ */ 115 116 cc_int32 ccs_win_pipe_compare (const WIN_PIPE* in_pipe_1, 117 const WIN_PIPE* in_pipe_2, 118 cc_uint32 *out_equal) { 119 120 cc_int32 err = ccNoError; 121 int seq = 0; 122 *out_equal = FALSE; 123 124 if (!ccs_win_pipe_valid(in_pipe_1)) {err = cci_check_error(ccErrBadParam);} 125 if (!ccs_win_pipe_valid(in_pipe_2)) {err = cci_check_error(ccErrBadParam);} 126 if (!out_equal) {err = cci_check_error(ccErrBadParam);} 127 128 /* A disconnect doesn't have a tls* with it -- only the uuid. SO only 129 compare the uuids. 130 */ 131 if (!err) { 132 seq = strcmp( ccs_win_pipe_getUuid(in_pipe_1), 133 ccs_win_pipe_getUuid(in_pipe_2) ); 134 *out_equal = (seq == 0); 135 } 136 137 return err; 138 } 139 140 /* ------------------------------------------------------------------------ */ 141 142 char* ccs_win_pipe_getUuid (const WIN_PIPE* in_pipe) { 143 144 char* result = NULL; 145 146 if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);} 147 else {result = in_pipe->uuid;} 148 149 return result; 150 } 151 152 /* ------------------------------------------------------------------------ */ 153 154 UINT64 ccs_win_pipe_getHandle (const WIN_PIPE* in_pipe) { 155 156 UINT64 result = 0; 157 158 if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);} 159 else {result = in_pipe->clientHandle;} 160 161 return result; 162 } 163