]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/rscript/rscript.cpp
user_property.h moved to general include dir
[stg.git] / projects / stargazer / plugins / other / rscript / rscript.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 /*
23  $Revision: 1.33 $
24  $Date: 2010/04/16 12:30:37 $
25  $Author: faust $
26 */
27
28 #include <sys/time.h>
29
30 #include <csignal>
31 #include <cassert>
32 #include <algorithm>
33
34 #include "rscript.h"
35 #include "common.h"
36 #include "ur_functor.h"
37 #include "send_functor.h"
38 #include "stg_locker.h"
39 #include "user_property.h"
40
41 extern volatile const time_t stgTime;
42
43 #define RS_MAX_ROUTERS  (100)
44
45 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 class RS_CREATOR
49 {
50 private:
51     REMOTE_SCRIPT * rs;
52
53 public:
54     RS_CREATOR()
55         : rs(new REMOTE_SCRIPT())
56         {
57         };
58     ~RS_CREATOR()
59         {
60         delete rs;
61         };
62
63     REMOTE_SCRIPT * GetPlugin()
64         {
65         return rs;
66         };
67 };
68 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 RS_CREATOR rsc;
72 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
75 PLUGIN * GetPlugin()
76 {
77 return rsc.GetPlugin();
78 }
79 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
82 RS_USER::RS_USER()
83     : lastSentTime(0),
84       shortPacketsCount(0)
85 {
86 }
87 //-----------------------------------------------------------------------------
88 RS_USER::RS_USER(const std::vector<uint32_t> & r, USER_PTR it)
89     : lastSentTime(0),
90       user(it),
91       routers(r),
92       shortPacketsCount(0)
93 {
94 }
95 //-----------------------------------------------------------------------------
96 RS_SETTINGS::RS_SETTINGS()
97     : sendPeriod(0),
98       port(0)
99 {
100 }
101 //-----------------------------------------------------------------------------
102 int RS_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val)
103 {
104 if (str2x(str.c_str(), *val))
105     {
106     errorStr = "Incorrect value \'" + str + "\'.";
107     return -1;
108     }
109 if (*val < min || *val > max)
110     {
111     errorStr = "Value \'" + str + "\' out of range.";
112     return -1;
113     }
114 return 0;
115 }
116 //-----------------------------------------------------------------------------
117 int RS_SETTINGS::ParseSettings(const MODULE_SETTINGS & s)
118 {
119 int p;
120 PARAM_VALUE pv;
121 vector<PARAM_VALUE>::const_iterator pvi;
122 netRouters.clear();
123 ///////////////////////////
124 pv.param = "Port";
125 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
126 if (pvi == s.moduleParams.end())
127     {
128     errorStr = "Parameter \'Port\' not found.";
129     printfd(__FILE__, "Parameter 'Port' not found\n");
130     return -1;
131     }
132 if (ParseIntInRange(pvi->value[0], 2, 65535, &p))
133     {
134     errorStr = "Cannot parse parameter \'Port\': " + errorStr;
135     printfd(__FILE__, "Cannot parse parameter 'Port'\n");
136     return -1;
137     }
138 port = p;
139 ///////////////////////////
140 pv.param = "SendPeriod";
141 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
142 if (pvi == s.moduleParams.end())
143     {
144     errorStr = "Parameter \'SendPeriod\' not found.";
145     printfd(__FILE__, "Parameter 'SendPeriod' not found\n");
146     return -1;
147     }
148
149 if (ParseIntInRange(pvi->value[0], 5, 600, &sendPeriod))
150     {
151     errorStr = "Cannot parse parameter \'SendPeriod\': " + errorStr;
152     printfd(__FILE__, "Cannot parse parameter 'SendPeriod'\n");
153     return -1;
154     }
155 ///////////////////////////
156 pv.param = "UserParams";
157 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
158 if (pvi == s.moduleParams.end())
159     {
160     errorStr = "Parameter \'UserParams\' not found.";
161     printfd(__FILE__, "Parameter 'UserParams' not found\n");
162     return -1;
163     }
164 userParams = pvi->value;
165 ///////////////////////////
166 pv.param = "Password";
167 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
168 if (pvi == s.moduleParams.end())
169     {
170     errorStr = "Parameter \'Password\' not found.";
171     printfd(__FILE__, "Parameter 'Password' not found\n");
172     return -1;
173     }
174 password = pvi->value[0];
175 ///////////////////////////
176 pv.param = "SubnetFile";
177 pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv);
178 if (pvi == s.moduleParams.end())
179     {
180     errorStr = "Parameter \'SubnetFile\' not found.";
181     printfd(__FILE__, "Parameter 'SubnetFile' not found\n");
182     return -1;
183     }
184 subnetFile = pvi->value[0];
185
186 NRMapParser nrMapParser;
187
188 if (nrMapParser.ReadFile(subnetFile))
189     {
190     errorStr = nrMapParser.GetErrorStr();
191     return -1;
192     }
193
194 netRouters = nrMapParser.GetMap();
195
196 if (netRouters.empty())
197     {
198     errorStr = "Parameter(s) \'Subnet*\' not found.";
199     printfd(__FILE__, "Parameter(s) 'Subnet*' not found\n");
200     return -1;
201     }
202
203 return 0;
204 }
205 //-----------------------------------------------------------------------------
206 //-----------------------------------------------------------------------------
207 //-----------------------------------------------------------------------------
208 REMOTE_SCRIPT::REMOTE_SCRIPT()
209     : sendPeriod(15),
210       halfPeriod(8),
211       nonstop(false),
212       isRunning(false),
213       users(NULL),
214       sock(0),
215       onAddUserNotifier(*this),
216       onDelUserNotifier(*this)
217 {
218 pthread_mutex_init(&mutex, NULL);
219 }
220 //-----------------------------------------------------------------------------
221 REMOTE_SCRIPT::~REMOTE_SCRIPT()
222 {
223 pthread_mutex_destroy(&mutex);
224 }
225 //-----------------------------------------------------------------------------
226 void * REMOTE_SCRIPT::Run(void * d)
227 {
228 REMOTE_SCRIPT * rs = static_cast<REMOTE_SCRIPT *>(d);
229
230 rs->isRunning = true;
231
232 while (rs->nonstop)
233     {
234     rs->PeriodicSend();
235     sleep(2);
236     }
237
238 rs->isRunning = false;
239 return NULL;
240 }
241 //-----------------------------------------------------------------------------
242 int REMOTE_SCRIPT::ParseSettings()
243 {
244 int ret = rsSettings.ParseSettings(settings);
245 if (ret)
246     errorStr = rsSettings.GetStrError();
247
248 sendPeriod = rsSettings.GetSendPeriod();
249 halfPeriod = sendPeriod / 2;
250
251 return ret;
252 }
253 //-----------------------------------------------------------------------------
254 int REMOTE_SCRIPT::Start()
255 {
256 netRouters = rsSettings.GetSubnetsMap();
257
258 InitEncrypt(&ctx, rsSettings.GetPassword());
259
260 //onAddUserNotifier.SetRemoteScript(this);
261 //onDelUserNotifier.SetRemoteScript(this);
262
263 users->AddNotifierUserAdd(&onAddUserNotifier);
264 users->AddNotifierUserDel(&onDelUserNotifier);
265
266 nonstop = true;
267
268 if (GetUsers())
269     {
270     return -1;
271     }
272
273 if (PrepareNet())
274     {
275     return -1;
276     }
277
278 if (!isRunning)
279     {
280     if (pthread_create(&thread, NULL, Run, this))
281         {
282         errorStr = "Cannot create thread.";
283         printfd(__FILE__, "Cannot create thread\n");
284         return -1;
285         }
286     }
287
288 errorStr = "";
289 return 0;
290 }
291 //-----------------------------------------------------------------------------
292 int REMOTE_SCRIPT::Stop()
293 {
294 if (!IsRunning())
295     return 0;
296
297 nonstop = false;
298
299 std::for_each(
300         authorizedUsers.begin(),
301         authorizedUsers.end(),
302         DisconnectUser(*this)
303         );
304
305 FinalizeNet();
306
307 if (isRunning)
308     {
309     //5 seconds to thread stops itself
310     for (int i = 0; i < 25 && isRunning; i++)
311         {
312         usleep(200000);
313         }
314
315     //after 5 seconds waiting thread still running. now killing it
316     if (isRunning)
317         {
318         if (pthread_kill(thread, SIGINT))
319             {
320             errorStr = "Cannot kill thread.";
321             printfd(__FILE__, "Cannot kill thread\n");
322             return -1;
323             }
324         printfd(__FILE__, "REMOTE_SCRIPT killed Run\n");
325         }
326     }
327
328 users->DelNotifierUserDel(&onDelUserNotifier);
329 users->DelNotifierUserAdd(&onAddUserNotifier);
330
331 return 0;
332 }
333 //-----------------------------------------------------------------------------
334 int REMOTE_SCRIPT::Reload()
335 {
336 NRMapParser nrMapParser;
337
338 if (nrMapParser.ReadFile(rsSettings.GetMapFileName()))
339     {
340     errorStr = nrMapParser.GetErrorStr();
341     return -1;
342     }
343
344     {
345     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
346
347     printfd(__FILE__, "REMOTE_SCRIPT::Reload()\n");
348
349     netRouters = nrMapParser.GetMap();
350     }
351
352 std::for_each(authorizedUsers.begin(),
353               authorizedUsers.end(),
354               UpdateRouter(*this));
355
356 return 0;
357 }
358 //-----------------------------------------------------------------------------
359 bool REMOTE_SCRIPT::PrepareNet()
360 {
361 sock = socket(AF_INET, SOCK_DGRAM, 0);
362
363 if (sock < 0)
364     {
365     errorStr = "Cannot create socket.";
366     printfd(__FILE__, "Cannot create socket\n");
367     return true;
368     }
369
370 return false;
371 }
372 //-----------------------------------------------------------------------------
373 bool REMOTE_SCRIPT::FinalizeNet()
374 {
375 close(sock);
376 return false;
377 }
378 //-----------------------------------------------------------------------------
379 void REMOTE_SCRIPT::PeriodicSend()
380 {
381 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
382
383 map<uint32_t, RS_USER>::iterator it(authorizedUsers.begin());
384 while (it != authorizedUsers.end())
385     {
386     if (difftime(stgTime, it->second.lastSentTime) - (rand() % halfPeriod) > sendPeriod)
387     //if (stgTime - it->second.lastSentTime > sendPeriod)
388         {
389         Send(it->first, it->second);
390         }
391     ++it;
392     }
393 }
394 //-----------------------------------------------------------------------------
395 bool REMOTE_SCRIPT::PreparePacket(char * buf, size_t bufSize, uint32_t ip, RS_USER & rsu, bool forceDisconnect) const
396 {
397 RS_PACKET_HEADER packetHead;
398
399 memset(packetHead.padding, 0, sizeof(packetHead.padding));
400 strcpy((char*)packetHead.magic, RS_ID);
401 packetHead.protoVer[0] = '0';
402 packetHead.protoVer[1] = '2';
403 if (forceDisconnect)
404     {
405     packetHead.packetType = RS_DISCONNECT_PACKET;
406     }
407 else
408     {
409     if (rsu.shortPacketsCount % MAX_SHORT_PCKT == 0)
410         {
411         //SendLong
412         packetHead.packetType = rsu.user->IsInetable() ? RS_CONNECT_PACKET : RS_DISCONNECT_PACKET;
413         }
414     else
415         {
416         //SendShort
417         packetHead.packetType = rsu.user->IsInetable() ? RS_ALIVE_PACKET : RS_DISCONNECT_PACKET;
418         }
419     }
420 rsu.shortPacketsCount++;
421 rsu.lastSentTime = stgTime;
422
423 packetHead.ip = htonl(ip);
424 packetHead.id = htonl(rsu.user->GetID());
425 strncpy((char*)packetHead.login, rsu.user->GetLogin().c_str(), RS_LOGIN_LEN);
426 packetHead.login[RS_LOGIN_LEN - 1] = 0;
427
428 memcpy(buf, &packetHead, sizeof(packetHead));
429
430 if (packetHead.packetType == RS_ALIVE_PACKET)
431     {
432     return false;
433     }
434
435 RS_PACKET_TAIL packetTail;
436
437 memset(packetTail.padding, 0, sizeof(packetTail.padding));
438 strcpy((char*)packetTail.magic, RS_ID);
439 vector<string>::const_iterator it;
440 std::string params;
441 for(it = rsSettings.GetUserParams().begin();
442     it != rsSettings.GetUserParams().end();
443     ++it)
444     {
445     std::string parameter(GetUserParam(rsu.user, *it));
446     if (params.length() + parameter.length() > RS_PARAMS_LEN - 1)
447         break;
448     params += parameter + " ";
449     }
450 strncpy((char *)packetTail.params, params.c_str(), RS_PARAMS_LEN);
451 packetTail.params[RS_PARAMS_LEN - 1] = 0;
452
453 assert(sizeof(packetHead) + sizeof(packetTail) <= bufSize && "Insufficient buffer space");
454
455 Encrypt(&ctx, buf + sizeof(packetHead), (char *)&packetTail, sizeof(packetTail) / 8);
456
457 return false;
458 }
459 //-----------------------------------------------------------------------------
460 bool REMOTE_SCRIPT::Send(uint32_t ip, RS_USER & rsu, bool forceDisconnect) const
461 {
462 char buffer[RS_MAX_PACKET_LEN];
463
464 memset(buffer, 0, sizeof(buffer));
465
466 if (PreparePacket(buffer, sizeof(buffer), ip, rsu, forceDisconnect))
467     {
468     printfd(__FILE__, "REMOTE_SCRIPT::Send() - Invalid packet length!\n");
469     return true;
470     }
471
472 std::for_each(
473         rsu.routers.begin(),
474         rsu.routers.end(),
475         PacketSender(sock, buffer, sizeof(buffer), htons(rsSettings.GetPort()))
476         );
477
478 return false;
479 }
480 //-----------------------------------------------------------------------------
481 bool REMOTE_SCRIPT::SendDirect(uint32_t ip, RS_USER & rsu, uint32_t routerIP, bool forceDisconnect) const
482 {
483 char buffer[RS_MAX_PACKET_LEN];
484
485 if (PreparePacket(buffer, sizeof(buffer), ip, rsu, forceDisconnect))
486     {
487     printfd(__FILE__, "REMOTE_SCRIPT::SendDirect() - Invalid packet length!\n");
488     return true;
489     }
490
491 struct sockaddr_in sendAddr;
492
493 sendAddr.sin_family = AF_INET;
494 sendAddr.sin_port = htons(rsSettings.GetPort());
495 sendAddr.sin_addr.s_addr = routerIP;
496
497 int res = sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&sendAddr, sizeof(sendAddr));
498
499 return (res != sizeof(buffer));
500 }
501 //-----------------------------------------------------------------------------
502 bool REMOTE_SCRIPT::GetUsers()
503 {
504 USER_PTR u;
505
506 int h = users->OpenSearch();
507 if (!h)
508     {
509     errorStr = "users->OpenSearch() error.";
510     printfd(__FILE__, "OpenSearch() error\n");
511     return true;
512     }
513
514 while (!users->SearchNext(h, &u))
515     {
516     SetUserNotifier(u);
517     }
518
519 users->CloseSearch(h);
520 return false;
521 }
522 //-----------------------------------------------------------------------------
523 void REMOTE_SCRIPT::ChangedIP(USER_PTR u, uint32_t oldIP, uint32_t newIP)
524 {
525 /*
526  * When ip changes process looks like:
527  * old => 0, 0 => new
528  *
529  */
530 if (newIP)
531     {
532     RS_USER rsu(IP2Routers(newIP), u);
533     Send(newIP, rsu);
534
535     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
536     authorizedUsers[newIP] = rsu;
537     }
538 else
539     {
540     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
541     const map<uint32_t, RS_USER>::iterator it(
542             authorizedUsers.find(oldIP)
543             );
544     if (it != authorizedUsers.end())
545         {
546         Send(oldIP, it->second, true);
547         authorizedUsers.erase(it);
548         }
549     }
550 }
551 //-----------------------------------------------------------------------------
552 std::vector<uint32_t> REMOTE_SCRIPT::IP2Routers(uint32_t ip)
553 {
554 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
555 for (size_t i = 0; i < netRouters.size(); ++i)
556     {
557     if ((ip & netRouters[i].subnetMask) == (netRouters[i].subnetIP & netRouters[i].subnetMask))
558         {
559         return netRouters[i].routers;
560         }
561     }
562 return std::vector<uint32_t>();
563 }
564 //-----------------------------------------------------------------------------
565 string REMOTE_SCRIPT::GetUserParam(USER_PTR u, const string & paramName) const
566 {
567 string value = "";
568 if (strcasecmp(paramName.c_str(), "cash") == 0)
569     strprintf(&value, "%f", u->GetProperty().cash.Get());
570 else
571 if (strcasecmp(paramName.c_str(), "freeMb") == 0)
572     strprintf(&value, "%f", u->GetProperty().freeMb.Get());
573 else
574 if (strcasecmp(paramName.c_str(), "passive") == 0)
575     strprintf(&value, "%d", u->GetProperty().passive.Get());
576 else
577 if (strcasecmp(paramName.c_str(), "disabled") == 0)
578     strprintf(&value, "%d", u->GetProperty().disabled.Get());
579 else
580 if (strcasecmp(paramName.c_str(), "alwaysOnline") == 0)
581     strprintf(&value, "%d", u->GetProperty().alwaysOnline.Get());
582 else
583 if (strcasecmp(paramName.c_str(), "tariffName") == 0 ||
584     strcasecmp(paramName.c_str(), "tariff") == 0)
585     value = "\"" + u->GetProperty().tariffName.Get() + "\"";
586 else
587 if (strcasecmp(paramName.c_str(), "nextTariff") == 0)
588     value = "\"" + u->GetProperty().nextTariff.Get() + "\"";
589 else
590 if (strcasecmp(paramName.c_str(), "address") == 0)
591     value = "\"" + u->GetProperty().address.Get() + "\"";
592 else
593 if (strcasecmp(paramName.c_str(), "note") == 0)
594     value = "\"" + u->GetProperty().note.Get() + "\"";
595 else
596 if (strcasecmp(paramName.c_str(), "group") == 0)
597     value = "\"" + u->GetProperty().group.Get() + "\"";
598 else
599 if (strcasecmp(paramName.c_str(), "email") == 0)
600     value = "\"" + u->GetProperty().email.Get() + "\"";
601 else
602 if (strcasecmp(paramName.c_str(), "realName") == 0)
603     value = "\"" + u->GetProperty().realName.Get() + "\"";
604 else
605 if (strcasecmp(paramName.c_str(), "credit") == 0)
606     strprintf(&value, "%f", u->GetProperty().credit.Get());
607 else
608 if (strcasecmp(paramName.c_str(), "userdata0") == 0)
609     value = "\"" + u->GetProperty().userdata0.Get() + "\"";
610 else
611 if (strcasecmp(paramName.c_str(), "userdata1") == 0)
612     value = "\"" + u->GetProperty().userdata1.Get() + "\"";
613 else
614 if (strcasecmp(paramName.c_str(), "userdata2") == 0)
615     value = "\"" + u->GetProperty().userdata2.Get() + "\"";
616 else
617 if (strcasecmp(paramName.c_str(), "userdata3") == 0)
618     value = "\"" + u->GetProperty().userdata3.Get() + "\"";
619 else
620 if (strcasecmp(paramName.c_str(), "userdata4") == 0)
621     value = "\"" + u->GetProperty().userdata4.Get() + "\"";
622 else
623 if (strcasecmp(paramName.c_str(), "userdata5") == 0)
624     value = "\"" + u->GetProperty().userdata5.Get() + "\"";
625 else
626 if (strcasecmp(paramName.c_str(), "userdata6") == 0)
627     value = "\"" + u->GetProperty().userdata6.Get() + "\"";
628 else
629 if (strcasecmp(paramName.c_str(), "userdata7") == 0)
630     value = "\"" + u->GetProperty().userdata7.Get() + "\"";
631 else
632 if (strcasecmp(paramName.c_str(), "userdata8") == 0)
633     value = "\"" + u->GetProperty().userdata8.Get() + "\"";
634 else
635 if (strcasecmp(paramName.c_str(), "userdata9") == 0)
636     value = "\"" + u->GetProperty().userdata9.Get() + "\"";
637 else
638 if (strcasecmp(paramName.c_str(), "enabledDirs") == 0)
639     value = u->GetEnabledDirs();
640 else
641     printfd(__FILE__, "Unknown value name: %s\n", paramName.c_str());
642 return value;
643 }
644 //-----------------------------------------------------------------------------
645 void REMOTE_SCRIPT::SetUserNotifier(USER_PTR u)
646 {
647 RS_CHG_AFTER_NOTIFIER<uint32_t> afterChgIPNotifier(*this, u);
648
649 afterChgIPNotifierList.push_front(afterChgIPNotifier);
650
651 u->AddCurrIPAfterNotifier(&(*afterChgIPNotifierList.begin()));
652 }
653 //-----------------------------------------------------------------------------
654 void REMOTE_SCRIPT::UnSetUserNotifier(USER_PTR u)
655 {
656 list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator  ipAIter;
657 std::list<list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator> toErase;
658
659 for (ipAIter = afterChgIPNotifierList.begin(); ipAIter != afterChgIPNotifierList.end(); ++ipAIter)
660     {
661     if (ipAIter->GetUser() == u)
662         {
663         u->DelCurrIPAfterNotifier(&(*ipAIter));
664         toErase.push_back(ipAIter);
665         }
666     }
667
668 std::list<list<RS_CHG_AFTER_NOTIFIER<uint32_t> >::iterator>::iterator eIter;
669
670 for (eIter = toErase.begin(); eIter != toErase.end(); ++eIter)
671     {
672     afterChgIPNotifierList.erase(*eIter);
673     }
674 }
675 //-----------------------------------------------------------------------------
676 template <typename varParamType>
677 void RS_CHG_AFTER_NOTIFIER<varParamType>::Notify(const varParamType & oldValue, const varParamType & newValue)
678 {
679 rs.ChangedIP(user, oldValue, newValue);
680 }
681 //-----------------------------------------------------------------------------
682 void REMOTE_SCRIPT::InitEncrypt(BLOWFISH_CTX * ctx, const string & password) const
683 {
684 unsigned char keyL[PASSWD_LEN];  // Пароль для шифровки
685 memset(keyL, 0, PASSWD_LEN);
686 strncpy((char *)keyL, password.c_str(), PASSWD_LEN);
687 Blowfish_Init(ctx, keyL, PASSWD_LEN);
688 }
689 //-----------------------------------------------------------------------------
690 void REMOTE_SCRIPT::Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, size_t len8) const
691 {
692 if (dst != src)
693     memcpy(dst, src, len8 * 8);
694 for (size_t i = 0; i < len8; ++i)
695     Blowfish_Encrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4));
696 }
697 //-----------------------------------------------------------------------------