OSDN Git Service

(LibGoblin)
[drdeamon64/drdeamon64.git] / deamon / drd64_marshald_cmd_connect.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRCID_MARSHALD_CMD_CONNECT        0x0000
38 #include"drd64_marshald.h"
39
40 #define DRD64_FUNCID_Marshald_Cmd_Connect_Client        0x12
41 #define DRD64_FUNCID_Marshald_Cmd_Connect_Server        0x11
42 #define DRD64_FUNCID_Marshald_Cmd_Connect                       0x01
43
44 /*----------------------------------------------------------------------
45 static int
46         Drd64_Intel64_DisAsm_GetSize_SizeID(
47                 : Get Operand Size form Intel 64 DB SizeID
48
49                 int i_operandsize,      : [src] Default Operand Size
50                 Word w_methodtype,      : [src] Method Type ID
51                 Word w_sizeid )         : [src] Size ID
52 ----------------------------------------------------------------------*/
53 int
54         Drd64_Marshald_Cmd_Connect_Client(
55                 int             i_fds,
56                 Drd64_PacketHeader      *p_phead,
57                 Drd64_PacketData_Connect        *p_connect )
58 {
59         Drd64_Marshald_ConnectInfo      *p_cinfo;
60
61         DRD64_LOG_DEBUG("  [DEBUG] CMD: Connect(Client) Start");
62         
63         p_cinfo = Drd64_Marshald_CInfo_GetConnectInfo(
64                                                 p_connect->i_client_cinfo_id );
65         assert( NULL != p_cinfo );
66
67         p_cinfo->i_dest_cinfo_id        = p_connect->i_connect_id;
68
69
70         DRD64_LOG_DEBUG("  [DEBUG] CMD: Connect(Client) Ended");
71
72         return DRD64_MARSHALD_DISPATCH_RESULT_RESTART;
73 }
74
75
76 /*----------------------------------------------------------------------
77 ----------------------------------------------------------------------*/
78 int
79         Drd64_Marshald_Cmd_Connect_Server(
80                 int             i_recv_id,
81                 Drd64_PacketHeader      *p_phead,
82                 Drd64_PacketData_Connect        *p_connect )
83 {
84         int                     i_wlen;
85         int                     i_fds;
86         int                     i_result;
87         DWord           dw_errcode;
88         DWord           dw_errlocation;
89         Drd64_Marshald_ConnectInfo              *p_cinfo;
90         Drd64_Server_RecvStatus                 *p_recv;
91
92         DRD64_LOG_DEBUG("  [DEBUG] CMD: Connect(Server) Start");
93
94         i_result                = DRD64_MARSHALD_DISPATCH_RESULT_COMPLETE;
95         dw_errcode              = DRD64_ERROR_CODE_CLEAR;
96         dw_errlocation  = DRD64_ERROR_SET_LOCATION(
97                                                 DRD64_ERROR_MODULE_MARSHALD,
98                                                 DRD64_ERROR_ARCH_NODEPEND,
99                                                 DRD64_SRCID_MARSHALD_CMD_CONNECT,
100                                                 DRD64_FUNCID_Marshald_Cmd_Connect_Server );
101
102         p_recv  = Drd64_Server_RecvStatus_GetRecvStatus( i_recv_id );
103         assert( NULL != p_recv );
104         i_fds   = p_recv->i_fds_id;
105         
106         /* Alloc ConnectInfo. */
107         p_cinfo = Drd64_Marshald_CInfo_AllocConnectInfo();
108         if( NULL == p_cinfo )           {
109                 dw_errcode      = DRD64_ERROR_SET_CODE(
110                                                 DRD64_ERROR_TYPE_ERROR,
111                                                 DRD64_ERROR_PTN_NOMEMORY,
112                                                 0x00, 0x01 );
113                 //Drd64_LibBrownie_Error_SetErrorInfo( dw_errcode, dw_errlocation, errno );
114
115                 i_result        =  DRD64_MARSHALD_DISPATCH_RESULT_CLOSE;
116
117                 goto goto_Marshald_Cmd_Connect_Server_Answer;
118         }
119
120         /* Set Cinfo Common Info. ---*/
121         p_cinfo->b_cinfo_type   = DRD64_MARSHALD_CINFOTYPE_SERVER;
122         p_cinfo->i_cinfo_refcount       = 1;
123
124         /* p_cinfo->t_dest_addr_inet = NONE */
125         p_cinfo->i_dest_cinfo_id                = -1;
126         p_cinfo->i_dest_socket                  = -1;
127         p_cinfo->str_dest_addr_local[0] = '\0'; 
128
129         Drd64_LibBrownie_INetAddr_CopyInAddr(
130                                                 &(p_cinfo->t_src_addr_inet),
131                                                 &(p_connect->t_client_addr_inet) );
132         p_cinfo->i_src_cinfo_id                 = p_connect->i_client_cinfo_id;
133         p_cinfo->i_src_socket                   = i_fds;
134
135         /* p_cinfo->t_src_addr_inet = NONE */
136         p_cinfo->i_prog_pid                             = -1;
137
138         p_cinfo->i_debugd_pid                   = -1;
139         p_cinfo->i_debugd_socket                = -1;
140
141         Drd64_LibBrownie_INetAddr_CopyInAddr(
142                                 &(p_cinfo->t_client_addr_inet),
143                                 &(p_connect->t_client_addr_inet) );
144         p_cinfo->i_client_socket                = i_fds;
145         p_cinfo->i_client_pid                   = p_connect->i_client_pid;
146
147
148         Drd64_Server_RecvStatus_SetConnectionInfoPointer(
149                                                                         p_recv, (void *)p_cinfo );
150
151     p_connect->i_connect_id             = p_cinfo->i_cinfo_id;
152     p_connect->i_marshald_pid   = getpid();
153
154         /* Set Answer Data ---------*/
155 goto_Marshald_Cmd_Connect_Server_Answer:
156         p_phead->dw_errcode                     = dw_errcode;
157         p_phead->dw_errlocation         = dw_errlocation;
158         p_phead->w_packettype           |= DRD64_PACKETTYPE_FLAG_ANSWER;
159
160         i_wlen  = send( i_fds, (void *)p_phead, DRD64_PacketSize(p_phead), 0x00 );
161         DRD64_DEBUG_PRINT("send",i_wlen,"Socket",i_fds,"errno",errno);
162         if( i_wlen != DRD64_PacketSize(p_phead) )       {
163                 dw_errcode      = DRD64_ERROR_SET_CODE(
164                                                 DRD64_ERROR_TYPE_ERROR,
165                                                 DRD64_ERROR_PTN_SOCKET,
166                                                 0x00, 0x02 );
167                 //Drd64_LibBrownie_Error_SetErrorInfo( dw_errcode, dw_errlocation, errno );
168
169                 i_result        =  DRD64_MARSHALD_DISPATCH_RESULT_CLOSE;
170         }
171         
172         DRD64_LOG_DEBUG("  [DEBUG] CMD: Connect(Server) Complete ");
173
174         return i_result;
175 }
176
177
178 /*----------------------------------------------------------------------
179 Drd64_Marshald_Cmd_Connect(
180 ----------------------------------------------------------------------*/
181 int
182         Drd64_Marshald_Cmd_Connect(
183                 int             i_recv_id,
184                 Drd64_PacketHeader      *p_phead,
185                 Drd64_PacketData_Connect        *p_connect )
186 {
187         int             i_result;
188
189         DRD64_LOG_VERBOSE("[STAT]CMD: Connect Start");
190         
191         if( DRD64_IsPacketType_Answer( p_phead ) )      {
192                 i_result        = Drd64_Marshald_Cmd_Connect_Client(
193                                                                 i_recv_id, p_phead, p_connect );
194
195         }
196         else    {
197                 i_result        = Drd64_Marshald_Cmd_Connect_Server(
198                                                                 i_recv_id, p_phead, p_connect );
199         }
200         
201         DRD64_LOG_VERBOSE("[STAT]CMD: Connect Ended");
202
203         return i_result;
204 }
205
206
207 /* EOF of drd64_.c ----------------------------------- */