Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ProfMan/src/ProfMan.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 119 - (show annotations) (download) (as text)
Fri Oct 8 15:41:45 2010 UTC (13 years, 7 months ago) by kamoya
File MIME type: text/x-c++src
File size: 22302 byte(s)
avoid ARRAYSIZE macro
1 #include "ProfMan.h"
2
3 #include <algorithm>
4 #include <sstream>
5 #include <deque>
6
7 #include <shlwapi.h>
8 #if defined(_MSC_VER)
9 #pragma comment(lib, "shlwapi.lib")
10 #endif
11
12 #include "../../Common/NsmInfoUtility.h"
13 #include "../../Common/dummy.h"
14
15 #include "ProfManConsts.h"
16
17 HINSTANCE g_hInstance;
18
19 namespace Regnessem
20 {
21 namespace AddIn
22 {
23 namespace ProfMan
24 {
25 ProfManMain g_profManMain;
26
27 const char passSeed[] = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
28 const std::size_t passSeedCount = std::extent<decltype(passSeed)>::value - 1;
29
30 std::string EncodePassword(const std::string &str)
31 {
32 class RandInit
33 {
34 public:
35 RandInit()
36 {
37 srand(static_cast<unsigned int>(time(NULL)));
38 }
39 };
40
41 static RandInit init;
42
43 const int key = 0;
44 std::deque<char> buff;
45
46 std::string::size_type i = 0;
47 for(std::string::const_iterator it = str.begin(); it != str.end(); ++it)
48 {
49 unsigned int j = rand() % passSeedCount;
50 buff.push_back(passSeed[j]);
51
52 unsigned int k = *it - 0x21;
53 unsigned int m = j + k + key + (i++) + 1;
54
55 m %= passSeedCount;
56 buff.push_back(passSeed[m]);
57 }
58
59 std::string result;
60 result.reserve(buff.size());
61
62 while (!buff.empty())
63 {
64 result += buff.front();
65 result += buff.back();
66 buff.pop_front();
67 buff.pop_back();
68 }
69
70 return result;
71 }
72
73 std::string DecodePassword(std::string str)
74 {
75 std::string s2;
76 std::string::size_type len = str.length();
77
78 for(std::string::size_type i = 0; !str.empty(); ++i)
79 {
80 s2.insert(i, str, 0, 2);
81 str.erase(0, 2);
82 };
83
84 int key=0;
85 std::string result;
86 result.reserve(len / 2);
87
88 for(std::string::size_type i = 0; i < len; ++i)
89 {
90 unsigned int j = strchr(passSeed, s2[i]) - passSeed;
91 unsigned int k = strchr(passSeed, s2[++i]) - passSeed;
92 int m = (k - j - key - ((i+1) / 2));
93
94 while(m < 0)
95 m += passSeedCount;
96
97 result += static_cast<char>(0x21 + m);
98 }
99
100 return result;
101 }
102
103 inline std::wstring EncodePassword(const std::wstring &str)
104 {
105 return c2w(EncodePassword(w2c(str)));
106 }
107
108 inline std::wstring DecodePassword(const std::wstring &str)
109 {
110 return c2w(DecodePassword(w2c(str)));
111 }
112
113 // ProfManMain::KeyName ----------------------------------------------------------
114
115 const LPCTSTR ProfManMain::KeyName::ProfileName = TEXT("ProfileName");
116 const LPCTSTR ProfManMain::KeyName::Account = TEXT("Account");
117 const LPCTSTR ProfManMain::KeyName::Password = TEXT("Password");
118 const LPCTSTR ProfManMain::KeyName::Protocol = TEXT("Protocol");
119 const LPCTSTR ProfManMain::KeyName::Name = TEXT("Name");
120 const LPCTSTR ProfManMain::KeyName::Status = TEXT("Status");
121
122 // ProfManMain -------------------------------------------------------------------
123
124 ProfManMain::ProfManMain()
125 {
126 SetPluginInfo(NMPI_APIVER , NMP_INFO_APIVER);
127 SetPluginInfo(NMPI_MODULENAME , NMP_INFO_MODULENAME);
128 SetPluginInfo(NMPI_TITLE , NMP_INFO_TITLE);
129 SetPluginInfo(NMPI_DESCRIPTION , NMP_INFO_DESCRIPTION);
130 SetPluginInfo(NMPI_AUTHOR , NMP_INFO_AUTHOR);
131 SetPluginInfo(NMPI_COPYRIGHT , NMP_INFO_COPYRIGHT);
132 SetPluginInfo(NMPI_PLUGINVER , NMP_INFO_PLUGINVER);
133 }
134
135 // ����������
136 void ProfManMain::DoInitialize()
137 {
138 // �T�[�r�X���o�^
139 CreateNsmService(NMS_ADDIN_PROFMAN_ENUM, ProfManService::DoEnum);
140 CreateNsmService(NMS_ADDIN_PROFMAN_GETINFO, ProfManService::DoGetInfo);
141 CreateNsmService(NMS_ADDIN_PROFMAN_SETINFO, ProfManService::DoSetInfo);
142 CreateNsmService(NMS_ADDIN_PROFMAN_ADD, ProfManService::DoAdd);
143 CreateNsmService(NMS_ADDIN_PROFMAN_REMOVE, ProfManService::DoRemove);
144 CreateNsmService(NMS_ADDIN_PROFMAN_CONNECT, ProfManService::DoConnect);
145 CreateNsmService(NMS_ADDIN_PROFMAN_GETSPECIFICINFO, ProfManService::DoGetSpecificInfo);
146 CreateNsmService(NMS_ADDIN_PROFMAN_SETSPECIFICINFO, ProfManService::DoSetSpecificInfo);
147
148 // �C�x���g���o�^
149 InfoChanging = CreateNsmEvent(NME_ADDIN_PROFMAN_INFOCHANGING);
150 InfoChange = CreateNsmEvent(NME_ADDIN_PROFMAN_INFOCHANGE);
151 SpecificInfoChanging = CreateNsmEvent(NME_ADDIN_PROFMAN_SPECIFICINFOCHANGING);
152 SpecificInfoChange = CreateNsmEvent(NME_ADDIN_PROFMAN_SPECIFICINFOCHANGE);
153
154 // �C�x���g�t�b�N
155 HookEvent(NME_SYSTEM_CONNECTION_DISCONNECT, ProfManService::HookDisconnect);
156 HookEvent(NME_SYSTEM_CONNECTION_INFOCHANGE, ProfManService::HookConnectionInfoChange);
157
158 LoadProfile();
159 }
160
161 // �I������
162 void ProfManMain::DoTerminate()
163 {
164 SaveProfile();
165 }
166
167 void ProfManMain::LoadProfile()
168 {
169 const tstring fileName = GetIniFileName();
170
171 if(!PathFileExists(fileName.c_str()))
172 return;
173
174 std::array<TCHAR, 1024> buff = {};
175
176 GetPrivateProfileSectionNames(buff.data(), std::tuple_size<decltype(buff)>::value, fileName.c_str());
177
178 std::vector<tstring> sections;
179
180 TCHAR *buffIt = buff.data();
181 for(tstring tmp = buffIt; tmp.size(); tmp = buffIt)
182 {
183 sections.push_back(tmp);
184 buffIt += tmp.size() + 1;
185 }
186
187 Profiles.clear();
188
189 for(std::vector<tstring>::const_iterator it = sections.begin(); it != sections.end(); ++it)
190 {
191 ProfileListSub prof(new Profile());
192 Profiles.push_back(prof);
193
194 GetPrivateProfileString(it->c_str(), NULL, NULL, buff.data(), std::tuple_size<decltype(buff)>::value, fileName.c_str());
195
196 buffIt = buff.data();
197 for(tstring key = buffIt; key.size(); key = buffIt)
198 {
199 std::array<TCHAR, 1024> buff2;
200 GetPrivateProfileString(it->c_str(), key.c_str(), L"", buff2.data(), std::tuple_size<decltype(buff2)>::value, fileName.c_str());
201
202 if(*it == KeyName::ProfileName)
203 prof->ProfileName = buff2.data();
204 else if(*it == KeyName::Account)
205 prof->Account = buff2.data();
206 else if(*it == KeyName::Password)
207 prof->Password = DecodePassword(buff2.data());
208 else if(*it == KeyName::Protocol)
209 prof->Protocol = buff2.data();
210 else if(*it == KeyName::Name)
211 prof->Name = buff2.data();
212 else if(*it == KeyName::Status)
213 prof->Status = GetPrivateProfileInt(it->c_str(), key.c_str(), 0, fileName.c_str());
214 else
215 prof->Specific[key] = buff2.data();
216
217 buffIt += key.size() + 1;
218 }
219 }
220 }
221
222 void ProfManMain::SaveProfile() const
223 {
224 const tstring fileName = GetIniFileName();
225 const tstring dirPath = ExtractFilePath(fileName);
226
227 if(!PathFileExists(dirPath.c_str()))
228 ForceDirectories(dirPath);
229
230 const DWORD attr = GetFileAttributes(fileName.c_str());
231 if(attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
232 DeleteFile(fileName.c_str());
233
234 int count = 0;
235 for(ProfileList::const_iterator it = Profiles.begin(); it != Profiles.end(); ++it)
236 {
237 if((*it)->Temporary)
238 continue;
239
240 const tstring section = TEXT("Profile") + ToString(++count);
241 WritePrivateProfileString(section.c_str(), KeyName::ProfileName, (*it)->ProfileName.c_str(), fileName.c_str());
242 WritePrivateProfileString(section.c_str(), KeyName::Account, (*it)->Account.c_str(), fileName.c_str());
243 WritePrivateProfileString(section.c_str(), KeyName::Password, EncodePassword((*it)->Password).c_str(), fileName.c_str());
244 WritePrivateProfileString(section.c_str(), KeyName::Protocol, (*it)->Protocol.c_str(), fileName.c_str());
245 WritePrivateProfileString(section.c_str(), KeyName::Name, (*it)->Name.c_str(), fileName.c_str());
246 WritePrivateProfileString(section.c_str(), KeyName::Status, ToString((*it)->Status).c_str(), fileName.c_str());
247
248 for(Profile::SpecificMap::const_iterator it2 = (*it)->Specific.begin(); it2 != (*it)->Specific.end(); ++it2)
249 WritePrivateProfileString(section.c_str(), it2->first.c_str(), it2->second.c_str(), fileName.c_str());
250 }
251 }
252
253 // �v���t�@�C������
254 // wParam: EnumProfileCallback : �R�[���o�b�N��������
255 // lParam: Integer : �C���f�[�^
256 // Return: 0
257 void ProfManMain::DoEnum(EnumProfileCallback callback, LPARAM lParam) const
258 {
259 for(ProfileList::const_iterator it = Profiles.begin(); it != Profiles.end(); ++it)
260 callback(reinterpret_cast<HNsmProfile>(it->get()), lParam);
261 }
262
263 // �v���t�@�C�����{��������
264 // wParam: HNsmProfile : ���������������v���t�@�C���n���h��
265 // lParam: PNsmProfileInfo : ���������l���Z�b�g����TNsmProfileInfo�\���������|�C���^
266 // Return: �����������T�C�Y������
267 LONG_PTR ProfManMain::DoGetInfo(HNsmProfile profile, const NsmProfileInfo &profInfo) const
268 {
269 ProfileList::const_iterator it = std::find_if(Profiles.begin(), Profiles.end(),
270 Profile::FindByHandle(profile));
271
272 if(it == Profiles.end())
273 return 0;
274
275 switch(profInfo.nInfoKey)
276 {
277 case NsmProfileInfoKey::Connection:
278 return Common::NsmInfoUtility::IntToNsmInfo(profInfo.lpInfo, reinterpret_cast<INT_PTR>((*it)->Connection));
279 case NsmProfileInfoKey::ProfileName:
280 return Common::NsmInfoUtility::StrToNsmInfo(profInfo.lpInfo, (*it)->ProfileName);
281 case NsmProfileInfoKey::Account:
282 return Common::NsmInfoUtility::StrToNsmInfo(profInfo.lpInfo, (*it)->Account);
283 case NsmProfileInfoKey::Password:
284 return Common::NsmInfoUtility::StrToNsmInfo(profInfo.lpInfo, (*it)->Password);
285 case NsmProfileInfoKey::Protocol:
286 return Common::NsmInfoUtility::StrToNsmInfo(profInfo.lpInfo, (*it)->Protocol);
287 case NsmProfileInfoKey::Name:
288 return Common::NsmInfoUtility::StrToNsmInfo(profInfo.lpInfo, (*it)->Name);
289 case NsmProfileInfoKey::Status:
290 return Common::NsmInfoUtility::IntToNsmInfo(profInfo.lpInfo, (*it)->Status);
291 }
292
293 return 0;
294 }
295
296 // �v���t�@�C�����{��������
297 // wParam: HNsmProfile : ���������X�����v���t�@�C���n���h��
298 // lParam: PNsmProfileInfo : ���X����������������TNsmProfileInfo�\���������|�C���^
299 // Return: ����������0���O������
300 LONG_PTR ProfManMain::DoSetInfo(HNsmProfile profile, const NsmProfileInfo &lParam) const
301 {
302 ProfileList::const_iterator it = std::find_if(Profiles.begin(), Profiles.end(),
303 Profile::FindByHandle(profile));
304
305 if(it == Profiles.end())
306 return 0;
307
308 NotifyEvent(InfoChanging, reinterpret_cast<WPARAM>(profile), reinterpret_cast<LPARAM>(&lParam));
309
310 switch(lParam.nInfoKey)
311 {
312 case NsmProfileInfoKey::Connection:
313 (*it)->Connection = reinterpret_cast<HNsmConnection>(Common::NsmInfoUtility::NsmInfoToInt(lParam.lpInfo));
314 break;
315 case NsmProfileInfoKey::ProfileName:
316 (*it)->ProfileName = Common::NsmInfoUtility::NsmInfoToStrW(lParam.lpInfo);
317 break;
318 case NsmProfileInfoKey::Account:
319 (*it)->Account = Common::NsmInfoUtility::NsmInfoToStrW(lParam.lpInfo);
320 break;
321 case NsmProfileInfoKey::Password:
322 (*it)->Password = Common::NsmInfoUtility::NsmInfoToStrW(lParam.lpInfo);
323 break;
324 case NsmProfileInfoKey::Protocol:
325 (*it)->Protocol = Common::NsmInfoUtility::NsmInfoToStrW(lParam.lpInfo);
326 break;
327 case NsmProfileInfoKey::Name:
328 (*it)->Name = Common::NsmInfoUtility::NsmInfoToStrW(lParam.lpInfo);
329 break;
330 case NsmProfileInfoKey::Status:
331 (*it)->Status = Common::NsmInfoUtility::NsmInfoToInt(lParam.lpInfo);
332 break;
333 }
334
335 NotifyEvent(InfoChange, reinterpret_cast<WPARAM>(profile), reinterpret_cast<LPARAM>(&lParam));
336
337 SaveProfile();
338
339 return 1;
340 }
341
342 // �v���t�@�C������
343 // wParam: PNsmProfileAddInfo : �V�������������v���t�@�C��
344 // lParam: 0
345 // Return: �����������v���t�@�C���n���h��������
346 LONG_PTR ProfManMain::DoAdd(const NsmProfileAddInfo &addInfo)
347 {
348 if(!addInfo.lpProfileName)
349 return 0;
350
351 if(std::find_if(Profiles.begin(), Profiles.end(),
352 Profile::FindByProfileName(addInfo.lpProfileName)) != Profiles.end())
353 return 0;
354
355 ProfileListSub prof(new Profile());
356 prof->ProfileName = addInfo.lpProfileName;
357 prof->Temporary = (addInfo.nFlag & NsmProfileFlag::TemporaryProfile) == NsmProfileFlag::TemporaryProfile;
358
359 Profiles.push_back(prof);
360
361 // ����
362 SaveProfile();
363
364 return reinterpret_cast<LONG_PTR>(prof.get());
365 }
366
367 // �v���t�@�C������
368 // wParam: HNsmProfile : �����������v���t�@�C���n���h��
369 // lParam: 0
370 // Return: ����������0���O������
371 LONG_PTR ProfManMain::DoRemove(HNsmProfile profile)
372 {
373 ProfileList::const_iterator it = std::find_if(Profiles.begin(), Profiles.end(),
374 Profile::FindByHandle(profile));
375
376 if(it == Profiles.end())
377 return 0;
378
379 Profiles.erase(it);
380
381 SaveProfile();
382
383 return 1;
384 }
385
386 // �v���t�@�C�����L��������
387 // wParam: HNsmProfile : ���������v���t�@�C�����n���h��
388 // lParam: PNsmProfileSpecificInfo
389 // Return: �����������o�C�g��
390 LONG_PTR ProfManMain::DoGetSpecificInfo(HNsmProfile profile, const NsmProfileSpecificInfo &specInfo) const
391 {
392 if(!specInfo.lpPluginName || !specInfo.lpKey || !specInfo.lpInfo)
393 return 0;
394
395 ProfileList::const_iterator it = std::find_if(Profiles.begin(), Profiles.end(),
396 Profile::FindByHandle(profile));
397
398 if(it == Profiles.end())
399 return 0;
400
401 Profile::SpecificMap::const_iterator it2
402 = (*it)->Specific.find(std::wstring(specInfo.lpPluginName) + L"." + specInfo.lpKey);
403
404 if(it2 == (*it)->Specific.end())
405 return 0;
406
407 switch(specInfo.lpInfo->nType)
408 {
409 case NMIT_INTEGER:
410 {
411 int value = 0;
412 std::wstringstream str(it2->second);
413 str >> value;
414
415 if(str.fail())
416 break;
417
418 return Common::NsmInfoUtility::IntToNsmInfo(specInfo.lpInfo, value);
419 }
420 case NMIT_STRING:
421 return Common::NsmInfoUtility::StrToNsmInfo(specInfo.lpInfo, w2c(it2->second));
422 case NMIT_WIDESTRING:
423 return Common::NsmInfoUtility::StrToNsmInfo(specInfo.lpInfo, it2->second);
424 }
425
426 return 0;
427 }
428
429 // �v���t�@�C�����L��������
430 // wParam: HNsmProfile : ���������v���t�@�C�����n���h��
431 // lParam: PNsmProfileSpecificInfo
432 // Return: �V�����L�[����������������0 �������L�[����������������1������
433 LONG_PTR ProfManMain::DoSetSpecificInfo(HNsmProfile profile, const NsmProfileSpecificInfo &specInfo) const
434 {
435 if(!specInfo.lpPluginName || !specInfo.lpKey || !specInfo.lpInfo)
436 return 0;
437
438 ProfileList::const_iterator it = std::find_if(Profiles.begin(), Profiles.end(),
439 Profile::FindByHandle(profile));
440
441 if(it == Profiles.end())
442 return 0;
443
444 NotifyEvent(SpecificInfoChanging, reinterpret_cast<WPARAM>(profile), reinterpret_cast<LPARAM>(&specInfo));
445
446 Profile::SpecificMap &spec = (*it)->Specific;
447 const std::wstring keyName = std::wstring(specInfo.lpPluginName) + L"." + specInfo.lpKey;
448 bool exist = spec.find(keyName) == spec.end();
449
450 switch(specInfo.lpInfo->nType)
451 {
452 case NMIT_INTEGER:
453 spec[keyName] = ToStringW(Common::NsmInfoUtility::NsmInfoToInt(specInfo.lpInfo));
454 break;
455 case NMIT_STRING:
456 case NMIT_WIDESTRING:
457 spec[keyName] = Common::NsmInfoUtility::NsmInfoToStrW(specInfo.lpInfo);
458 break;
459 }
460
461 NotifyEvent(SpecificInfoChange, reinterpret_cast<WPARAM>(profile), reinterpret_cast<LPARAM>(&specInfo));
462
463 return exist ? 1 : 0;
464 }
465
466 // �v���t�@�C�������p��������
467 // wParam: PNsmProfileConnectInfo : ���������v���t�@�C��
468 // lParam: 0
469 // Return: Protocol/%protocol%/Connection/Connect�������l
470 LONG_PTR ProfManMain::DoConnect(const NsmProfileConnectInfo &connectInfo) const
471 {
472 ProfileList::const_iterator it = std::find_if(Profiles.begin(), Profiles.end(),
473 Profile::FindByHandle(connectInfo.hProfile));
474
475 if(it == Profiles.end())
476 return 0;
477
478 (*it)->NameChange = (connectInfo.nFlag & NsmProfileFlag::SetInitialName) == NsmProfileFlag::SetInitialName;
479
480 const std::string account = w2c((*it)->Account);
481 const std::string password = w2c((*it)->Password);
482
483 TLogInInfo login = {0};
484 login.cbSize = sizeof(login);
485 login.lpAccount = account.c_str();
486 login.lpPassword = password.c_str();
487 login.nStatus = (*it)->Status;
488
489 const std::wstring service = NMM_PROTOCOL L"/" + (*it)->Protocol + L"/Connection/Connect";
490 (*it)->Connection = reinterpret_cast<HNsmConnection>(CallService(service, reinterpret_cast<WPARAM>(&login), 0));
491
492 return reinterpret_cast<LONG_PTR>((*it)->Connection);
493 }
494
495 // ���f���m
496 // wParam: �����������R�l�N�V�����n���h��
497 // lParam: 0
498 // Return: 0
499 void ProfManMain::HookConnectionInfoChange(HNsmConnection connect) const
500 {
501 ProfileList::const_iterator it = std::find_if(Profiles.begin(), Profiles.end(),
502 Profile::FindByConnection(connect));
503
504 if(it != Profiles.end())
505 (*it)->Connection = NULL;
506 }
507
508 // �����������m
509 // wParam: HNsmConnection
510 // lParam: PNsmConnectionInfo
511 // Return: 0
512 void ProfManMain::HookDisconnect(HNsmConnection connect, const TNsmConnectionInfo &connectInfo) const
513 {
514 if(connectInfo.nInfoKey != NMCI_STATUS)
515 return;
516
517 if(Common::NsmInfoUtility::NsmInfoToInt(connectInfo.lpInfo) != NMCS_CONNECTED)
518 return;
519
520 ProfileList::const_iterator it =
521 std::find_if(Profiles.begin(), Profiles.end(), Profile::FindByConnection(connect));
522
523 if(it == Profiles.end())
524 return;
525
526 if(!(*it)->ProfileName.empty() && (*it)->NameChange)
527 SetConnectionUserName(**it);
528 }
529
530 // ���[�U�[�������X
531 void ProfManMain::SetConnectionUserName(const Profile &profile) const
532 {
533 TUserNameInfo info = {0};
534 info.cbSize = sizeof(info);
535 info.lpName = profile.Name.c_str();
536
537 const std::wstring service = NMM_PROTOCOL L"/" + profile.Protocol + L"/Connection/ChangeUserName";
538 CallService(service, reinterpret_cast<WPARAM>(profile.Connection), reinterpret_cast<WPARAM>(&info));
539 }
540
541 // -----------------------------------------------------------------------------
542
543 LONG_PTR __stdcall ProfManService::DoEnum(WPARAM wParam, LPARAM lParam)
544 {
545 if(!wParam)
546 return 0;
547
548 g_profManMain.DoEnum(reinterpret_cast<EnumProfileCallback>(wParam), lParam);
549
550 return 0;
551 }
552
553 LONG_PTR __stdcall ProfManService::DoGetInfo(WPARAM wParam, LPARAM lParam)
554 {
555 if(!lParam)
556 return 0;
557
558 return g_profManMain.DoGetInfo(reinterpret_cast<HNsmProfile>(wParam), *reinterpret_cast<NsmProfileInfo*>(lParam));
559 }
560
561 LONG_PTR __stdcall ProfManService::DoSetInfo(WPARAM wParam, LPARAM lParam)
562 {
563 if(!lParam)
564 return 0;
565
566 return g_profManMain.DoSetInfo(reinterpret_cast<HNsmProfile>(wParam), *reinterpret_cast<NsmProfileInfo*>(lParam));
567 }
568
569 LONG_PTR __stdcall ProfManService::DoAdd(WPARAM wParam, LPARAM /* lParam */)
570 {
571 if(!wParam)
572 return 0;
573
574 return g_profManMain.DoAdd(*reinterpret_cast<NsmProfileAddInfo*>(wParam));
575 }
576
577 LONG_PTR __stdcall ProfManService::DoRemove(WPARAM wParam, LPARAM /* lParam */)
578 {
579 if(!wParam)
580 return 0;
581
582 return g_profManMain.DoRemove(reinterpret_cast<HNsmProfile>(wParam));
583 }
584
585 LONG_PTR __stdcall ProfManService::DoGetSpecificInfo(WPARAM wParam, LPARAM lParam)
586 {
587 if(!lParam)
588 return 0;
589
590 return g_profManMain.DoGetSpecificInfo(reinterpret_cast<HNsmProfile>(wParam),
591 *reinterpret_cast<NsmProfileSpecificInfo*>(lParam));
592 }
593
594 LONG_PTR __stdcall ProfManService::DoSetSpecificInfo(WPARAM wParam, LPARAM lParam)
595 {
596 if(!lParam)
597 return 0;
598
599 return g_profManMain.DoSetSpecificInfo(reinterpret_cast<HNsmProfile>(wParam),
600 *reinterpret_cast<NsmProfileSpecificInfo*>(lParam));
601 }
602
603 LONG_PTR __stdcall ProfManService::DoConnect(WPARAM wParam, LPARAM /* lParam */)
604 {
605 if(!wParam)
606 return 0;
607
608 return g_profManMain.DoConnect(*reinterpret_cast<NsmProfileConnectInfo*>(wParam));
609 }
610
611 int __stdcall ProfManService::HookDisconnect(WPARAM wParam, LPARAM /* lParam */)
612 {
613 g_profManMain.HookConnectionInfoChange(reinterpret_cast<HNsmConnection>(wParam));
614
615 return 0;
616 }
617
618 int __stdcall ProfManService::HookConnectionInfoChange(WPARAM wParam, LPARAM lParam)
619 {
620 if(!lParam)
621 return 0;
622
623 g_profManMain.HookDisconnect(reinterpret_cast<HNsmConnection>(wParam), *reinterpret_cast<TNsmConnectionInfo*>(lParam));
624
625 return 0;
626 }
627 }
628 }
629 }
630
631 BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpvReserved*/)
632 {
633 g_hInstance = hinstDLL;
634
635 switch(fdwReason)
636 {
637 case DLL_PROCESS_ATTACH:
638 break;
639 case DLL_PROCESS_DETACH:
640 break;
641 case DLL_THREAD_ATTACH:
642 break;
643 case DLL_THREAD_DETACH:
644 break;
645 }
646
647 return TRUE;
648 }
649
650 extern "C"
651 {
652 // �v���O�C��������������������
653 //
654 // nInfoNo : ��������������������
655 // lpBuffer : �������i�[�����o�b�t�@
656 // nSize : �o�b�t�@���T�C�Y
657 //
658 // Return : �����������������������T�C�Y
659 // nInfoNo ���������� 0
660 int WINAPI GetPluginInfo(int nInfNo, LPSTR lpBuffer, int nSize)
661 {
662 if(!lpBuffer)
663 return 0;
664
665 if(nSize < 1)
666 return 0;
667
668 std::string result = t2c(Regnessem::AddIn::ProfMan::g_profManMain.GetPluginInfo(nInfNo));
669
670 if(result.empty())
671 return 0;
672
673 std::string::size_type len = std::min<std::string::size_type>(nSize-1,result.size());
674
675 result.resize(len);
676 strcpy_s(lpBuffer,nSize,result.c_str());
677
678 return static_cast<int>(len);
679 }
680
681 // �v���O�C��������������
682 //
683 // lpPluginInitInfo : �v���O�C������������
684 //
685 // Return : �G���[�R�[�h
686 int WINAPI Initialize(Regnessem::PNsmPluginInitInfo lpNsmInitInfo)
687 {
688 if(!lpNsmInitInfo)
689 return Regnessem::NsmPluginState::InternalError;
690
691 Regnessem::AddIn::ProfMan::g_profManMain.Initialize(*lpNsmInitInfo);
692
693 return Regnessem::NsmPluginState::AllRight;
694 }
695
696 // �v���O�C�����I������
697 //
698 // Return : �G���[�R�[�h
699 int WINAPI Terminate()
700 {
701 Regnessem::AddIn::ProfMan::g_profManMain.Terminate();
702
703 return Regnessem::NsmPluginState::AllRight;
704 }
705 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26