- Timestamp:
- 07/08/05 07:35:21 (3 years ago)
- Location:
- trunk/rms/src
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/rms/src/rms.cpp
r4081 r4144 95 95 { 96 96 { "ADDUSER", &CRMSClient::Process_ADDUSER, 97 "Add user to contact list { < uin>}." },97 "Add user to contact list { <id>[.<protocol>] }." }, 98 98 { "AR", &CRMSClient::Process_AR, 99 "Set your (or a user custom) auto response { [ < uin>] }." },99 "Set your (or a user custom) auto response { [ <id>[.<protocol>] ] }." }, 100 100 { "GROUPS", &CRMSClient::Process_GROUPS, 101 101 "Show list of groups." }, … … 103 103 "Print out help on commands." }, 104 104 { "INFO", &CRMSClient::Process_INFO, 105 "Print out user information. Argument is the uin, or none for personal." },105 "Print out user information. Argument is the id and protocol, or none for personal." }, 106 106 { "LIST", &CRMSClient::Process_LIST, 107 107 "List users { [ <group #> ] [ <online|offline|all> ] [ <format> ] }." }, … … 109 109 "Dump log messages { <log types> }." }, 110 110 { "MESSAGE", &CRMSClient::Process_MESSAGE, 111 "Send a message { < uin>}." },111 "Send a message { <id>[.<protocol>] }." }, 112 112 { "QUIT", &CRMSClient::Process_QUIT, 113 113 "Close the connection. With an argument of 1 causes the plugin to unload." }, 114 114 { "REMUSER", &CRMSClient::Process_REMUSER, 115 "Remove user from contact list { < uin>}." },115 "Remove user from contact list { <id>[.<protocol>] }." }, 116 116 { "SECURE", &CRMSClient::Process_SECURE, 117 117 "Open/close/check secure channel { <uin> [ <open|close> ] } ." }, … … 121 121 "Terminate the licq daemon." }, 122 122 { "VIEW", &CRMSClient::Process_VIEW, 123 "View event (next or specific user) { [ < uin>] }." },123 "View event (next or specific user) { [ <id>[.<protocol>] ] }." }, 124 124 { "URL", &CRMSClient::Process_URL, 125 "Send a url { < uin>}." },125 "Send a url { <id>[.<protocol>] }." }, 126 126 { "SMS", &CRMSClient::Process_SMS, 127 127 "Send an sms { <uin> }." }, … … 174 174 m_nPipe = _licqDaemon->RegisterPlugin(SIGNAL_UPDATExUSER); 175 175 licqDaemon = _licqDaemon; 176 176 177 177 char filename[256]; 178 178 sprintf (filename, "%s/licq_rms.conf", BASE_DIR); … … 351 351 default: 352 352 break; 353 354 case SIGNAL_EVENTxID: 355 //XXX Catch this 356 break; 353 357 } 354 358 delete s; … … 403 407 fflush(fs); 404 408 409 m_szCheckId = 0; 410 m_szId = 0; 405 411 m_nState = STATE_UIN; 406 412 m_nLogTypes = 0; … … 415 421 { 416 422 sockman.CloseSocket(sock.Descriptor(), false, false); 417 } 418 423 424 if (m_szCheckId) 425 free(m_szCheckId); 426 } 427 428 /*--------------------------------------------------------------------------- 429 * CRMSClient::GetProtocol 430 *-------------------------------------------------------------------------*/ 431 unsigned long CRMSClient::GetProtocol(const char *szData) 432 { 433 unsigned long nPPID = 0; 434 ProtoPluginsList pl; 435 ProtoPluginsListIter it; 436 licqDaemon->ProtoPluginList(pl); 437 for (it = pl.begin(); it != pl.end(); it++) 438 { 439 if (strcasecmp((*it)->Name(), szData) == 0) 440 { 441 nPPID = (*it)->PPID(); 442 break; 443 } 444 } 445 446 return nPPID; 447 } 448 449 /*--------------------------------------------------------------------------- 450 * CRMSClient::ParseUser 451 *-------------------------------------------------------------------------*/ 452 void CRMSClient::ParseUser(const char *szData) 453 { 454 if (m_szId) 455 free(m_szId); 456 457 string strData(szData); 458 string::size_type nPos= strData.find_last_of("."); 459 if (nPos == string::npos) 460 { 461 m_szId = strdup(data_arg); 462 m_nPPID = 0; 463 ProtoPluginsList pl; 464 ProtoPluginsListIter it; 465 licqDaemon->ProtoPluginList(pl); 466 for (it = pl.begin(); it != pl.end(); it++) 467 { 468 ICQUser *u = gUserManager.FetchUser(m_szId, (*it)->PPID(), LOCK_R); 469 if (u) 470 { 471 gUserManager.DropUser(u); 472 m_nPPID = (*it)->PPID(); 473 break; 474 } 475 } 476 } 477 else 478 { 479 string strId(strData, 0, strData.find_last_of(".")); 480 string strProtocol(strData, strData.find_last_of(".")+1, strData.size()); 481 m_szId = strdup(strId.c_str()); 482 m_nPPID = GetProtocol(strProtocol.c_str()); 483 } 484 } 419 485 420 486 /*--------------------------------------------------------------------------- … … 517 583 case STATE_UIN: 518 584 { 519 m_ nCheckUin = strtoul(data_line, (char**)NULL, 10);585 m_szCheckId = data_line ? strdup(data_line) : 0; 520 586 fprintf(fs, "%d Enter your password:\n", CODE_ENTERxPASSWORD); 521 587 fflush(fs); … … 526 592 { 527 593 ICQOwner *o = gUserManager.FetchOwner(LOCK_R); 528 bool ok = ( m_nCheckUin == o->Uin()&&594 bool ok = (strcmp(m_szCheckId, o->IdString()) == 0 && 529 595 strcmp(o->Password(), data_line) == 0); 596 free(m_szCheckId); 597 m_szCheckId = 0; 530 598 if (!ok) 531 599 { … … 533 601 gLog.Info("%sClient failed validation from %s.\n", L_RMSxSTR, 534 602 sock.RemoteIpStr(buf)); 535 fprintf(fs, "%d Invalid UIN/Password.\n", CODE_INVALID);603 fprintf(fs, "%d Invalid ID/Password.\n", CODE_INVALID); 536 604 fflush(fs); 537 605 return -1; … … 631 699 int CRMSClient::Process_INFO() 632 700 { 633 unsigned long nUin = strtoul(data_arg, (char**)NULL, 10); 634 635 if (nUin == 0) nUin = gUserManager.OwnerUin(); 701 char *szId = strdup(data_arg); 702 NEXT_WORD(data_arg); 703 unsigned long nPPID = GetProtocol(data_arg); 704 705 //XXX Handle the case when we have the owner 706 if (szId == 0) 707 m_nUin = gUserManager.OwnerUin(); 636 708 637 709 // Print the user info 638 ICQUser *u = gUserManager.FetchUser( nUin, LOCK_R);710 ICQUser *u = gUserManager.FetchUser(szId, nPPID, LOCK_R); 639 711 if (u == NULL) 640 712 { … … 643 715 } 644 716 645 fprintf(fs, "%d %ld Alias: %s\n", CODE_USERxINFO, u->Uin(), u->GetAlias()); 646 fprintf(fs, "%d %ld Status: %s\n", CODE_USERxINFO, u->Uin(), u->StatusStr()); 647 fprintf(fs, "%d %ld First Name: %s\n", CODE_USERxINFO, u->Uin(), u->GetFirstName()); 648 fprintf(fs, "%d %ld Last Name: %s\n", CODE_USERxINFO, u->Uin(), u->GetLastName()); 649 fprintf(fs, "%d %ld Email 1: %s\n", CODE_USERxINFO, u->Uin(), u->GetEmailPrimary()); 650 fprintf(fs, "%d %ld Email 2: %s\n", CODE_USERxINFO, u->Uin(), u->GetEmailSecondary()); 717 fprintf(fs, "%d %s Alias: %s\n", CODE_USERxINFO, u->IdString(), 718 u->GetAlias()); 719 fprintf(fs, "%d %s Status: %s\n", CODE_USERxINFO, u->IdString(), 720 u->StatusStr()); 721 fprintf(fs, "%d %s First Name: %s\n", CODE_USERxINFO, u->IdString(), 722 u->GetFirstName()); 723 fprintf(fs, "%d %s Last Name: %s\n", CODE_USERxINFO, u->IdString(), 724 u->GetLastName()); 725 fprintf(fs, "%d %s Email 1: %s\n", CODE_USERxINFO, u->IdString(), 726 u->GetEmailPrimary()); 727 fprintf(fs, "%d %s Email 2: %s\n", CODE_USERxINFO, u->IdString(), 728 u->GetEmailSecondary()); 651 729 652 730 gUserManager.DropUser(u); 653 731 732 if (szId) 733 free(szId); 734 654 735 return fflush(fs); 655 736 } … … 660 741 * 661 742 * Command: 662 * STATUS [ status ]743 * STATUS [ status | protocol ] 663 744 * 664 745 * Response: … … 670 751 if (data_arg[0] == '\0') 671 752 { 672 ICQOwner *o = gUserManager.FetchOwner(LOCK_R); 673 fprintf(fs, "%d %s\n", CODE_STATUS, o->StatusStr()); 674 gUserManager.DropOwner(); 753 ProtoPluginsList l; 754 ProtoPluginsListIter it; 755 licqDaemon->ProtoPluginList(l); 756 for (it = l.begin(); it != l.end(); it++) 757 { 758 ICQOwner *o = gUserManager.FetchOwner((*it)->PPID(), LOCK_R); 759 if (o) 760 { 761 fprintf(fs, "%d %s %s\n", CODE_STATUS, (*it)->Name(), o->StatusStr()); 762 gUserManager.DropOwner((*it)->PPID()); 763 } 764 } 675 765 return fflush(fs); 676 766 } … … 684 774 } 685 775 686 if (nStatus == ICQ_STATUS_OFFLINE) 687 { 688 fprintf(fs, "%d [0] Logging off.\n", CODE_COMMANDxSTART); 689 fflush(fs); 690 licqDaemon->icqLogoff(); 691 fprintf(fs, "%d [0] Event done.\n", CODE_RESULTxSUCCESS); 692 return fflush(fs); 693 } 694 695 ICQOwner *o = gUserManager.FetchOwner(LOCK_R); 696 bool b = o->StatusOffline(); 697 gUserManager.DropOwner(); 698 unsigned long tag = 0; 699 if (b) 700 { 701 tag = licqDaemon->icqLogon(nStatus); 702 fprintf(fs, "%d [%ld] Logging on.\n", CODE_COMMANDxSTART, tag); 703 } 704 else 705 { 706 tag = licqDaemon->icqSetStatus(nStatus); 707 fprintf(fs, "%d [%ld] Setting status.\n", CODE_COMMANDxSTART, tag); 708 } 709 tags.push_back(tag); 710 776 ProtoPluginsList l; 777 ProtoPluginsListIter it; 778 licqDaemon->ProtoPluginList(l); 779 for (it = l.begin(); it != l.end(); it++) 780 { 781 if (nStatus == ICQ_STATUS_OFFLINE) 782 { 783 fprintf(fs, "%d [0] Logging off %s.\n", CODE_COMMANDxSTART, 784 (*it)->Name()); 785 fflush(fs); 786 licqDaemon->ProtoLogoff((*it)->PPID()); 787 fprintf(fs, "%d [0] Event done.\n", CODE_RESULTxSUCCESS); 788 } 789 else 790 { 791 ICQOwner *o = gUserManager.FetchOwner((*it)->PPID(), LOCK_R); 792 bool b = o->StatusOffline(); 793 gUserManager.DropOwner((*it)->PPID()); 794 unsigned long tag = 0; 795 if (b) 796 { 797 tag = licqDaemon->ProtoLogon((*it)->PPID(), nStatus); 798 fprintf(fs, "%d [%ld] Logging on to %s.\n", CODE_COMMANDxSTART, tag, 799 (*it)->Name()); 800 } 801 else 802 { 803 tag = licqDaemon->ProtoSetStatus((*it)->PPID(), nStatus); 804 fprintf(fs, "%d [%ld] Setting status for %s.\n", CODE_COMMANDxSTART, 805 tag, (*it)->Name()); 806 } 807 tags.push_back(tag); 808 } 809 } 810 711 811 return fflush(fs); 712 812 } … … 718 818 int CRMSClient::Process_QUIT() 719 819 { 720 fprintf(fs, "%d Aurevoir.\n", CODE_QUIT);820 fprintf(fs, "%d Sayonara.\n", CODE_QUIT); 721 821 fflush(fs); 722 822 if (strtoul(data_arg, (char**)NULL, 10) > 0) licqRMS->m_bExit = true; … … 785 885 * "LIST all" is a valid call and will print all online and offline users. 786 886 * <format> is a printf style string using the user % symbols as 787 * documented in UTILITIES.HOWTO. The default is "% 9u%-20a %3m %s"887 * documented in UTILITIES.HOWTO. The default is "%u %P %-20a %3m %s" 788 888 * and prints out users as follows. 789 889 * 790 890 * Response: 791 * CODE_LISTxUSER 5550000 AnAlias 2 Online792 * The default line contains the uin, alias, number of new messages793 * and status all column and white space deliminated. Note that the794 * alias may contain white space.891 * CODE_LISTxUSER 5550000 Licq AnAlias 2 Online 892 * The default line contains the uin, protocol, alias, number of new 893 * messages and status all column and white space deliminated. Note that 894 * the alias may contain white space. 795 895 * CODE_LISTxUSER ... 796 896 * ... … … 829 929 if (*data_arg == '\0') 830 930 { 831 strcpy(format, "%u % -20a %3m %s");931 strcpy(format, "%u %P %-20a %3m %s"); 832 932 } 833 933 else … … 858 958 * 859 959 * Command: 860 * MESSAGE < uin>960 * MESSAGE <id>[.<protocol>] 861 961 * 862 962 * Response: … … 871 971 int CRMSClient::Process_MESSAGE() 872 972 { 873 // unsigned long nUin = strtoul(data_arg, (char**)NULL, 10);874 875 // if (nUin < 10000)876 // {877 // fprintf(fs, "%d Invalid UIN.\n", CODE_INVALIDxUSER);878 // return fflush(fs);879 // }880 881 973 fprintf(fs, "%d Enter message, terminate with a . on a line by itself:\n", 882 974 CODE_ENTERxTEXT); 883 975 884 // m_nUin = nUin;885 m_szId = strdup(data_arg); 976 ParseUser(data_arg); 977 886 978 m_szText[0] = '\0'; 887 979 m_nTextPos = 0; … … 893 985 int CRMSClient::Process_MESSAGE_text() 894 986 { 895 unsigned long tag = licqDaemon->icqSendMessage(m_szId, m_szText, false, ICQ_TCPxMSG_NORMAL); 987 //XXX Give a tag... 988 unsigned long tag = licqDaemon->ProtoSendMessage(m_szId, m_nPPID, m_szText, 989 false, ICQ_TCPxMSG_NORMAL); 896 990 897 991 fprintf(fs, "%d [%ld] Sending message to %s.\n", CODE_COMMANDxSTART, 898 992 tag, m_szId); 899 900 tags.push_back(tag);901 993 m_nState = STATE_COMMAND; 902 994 995 if (m_nPPID == LICQ_PPID) 996 tags.push_back(tag); 997 903 998 return fflush(fs); 904 999 } … … 910 1005 * 911 1006 * Command: 912 * URL < uin>1007 * URL <id>[.<protocol>] 913 1008 * 914 1009 * Response: … … 926 1021 int CRMSClient::Process_URL() 927 1022 { 928 unsigned long nUin = strtoul(data_arg, (char**)NULL, 10); 929 930 if (nUin < 10000) 931 { 932 fprintf(fs, "%d Invalid UIN.\n", CODE_INVALIDxUSER); 933 return fflush(fs); 934 } 935 fprintf(fs, "%d Enter URL:\n", CODE_ENTERxLINE); 936 937 m_nUin = nUin; 1023 ParseUser(data_arg); 1024 938 1025 m_nTextPos = 0; 939 1026 … … 960 1047 int CRMSClient::Process_URL_text() 961 1048 { 962 unsigned long tag = licqDaemon->icqSendUrl(m_nUin, m_szLine, m_szText, false, ICQ_TCPxMSG_NORMAL); 963 964 fprintf(fs, "%d [%ld] Sending URL to %ld.\n", CODE_COMMANDxSTART, 965 tag, m_nUin); 966 967 tags.push_back(tag); 1049 unsigned long tag = licqDaemon->ProtoSendUrl(m_szId, m_nPPID, m_szLine, 1050 m_szText, false, ICQ_TCPxMSG_NORMAL); 1051 1052 fprintf(fs, "%d [%ld] Sending URL to %s.\n", CODE_COMMANDxSTART, 1053 tag, m_szId); 1054 1055 if (m_nPPID == LICQ_PPID) 1056 tags.push_back(tag); 1057 968 1058 m_nState = STATE_COMMAND; 969 1059 … … 1042 1132 * 1043 1133 * Command: 1044 * AR [ < uin>]1134 * AR [ <id>[.<protocol>] ] 1045 1135 * 1046 1136 * Response: … … 1052 1142 int CRMSClient::Process_AR() 1053 1143 { 1054 /* 1055 if (data_arg[0] == '\0') 1056 { 1057 ICQOwner *o = gUserManager.FetchOwner(LOCK_R); 1058 // print... 1059 gUserManager.DropOwner(); 1144 ParseUser(data_arg); 1145 1146 if (m_szId && !gUserManager.IsOnList(m_szId, m_nPPID)) 1147 { 1148 fprintf(fs, "%d Invalid User.\n", CODE_INVALIDxUSER); 1060 1149 return fflush(fs); 1061 1150 } 1062 */1063 unsigned long nUin = strtoul(data_arg, (char**)NULL, 10);1064 1065 if (nUin != 0 && !gUserManager.IsOnList(nUin))1066 {1067 fprintf(fs, "%d Invalid UIN.\n", CODE_INVALIDxUSER);1068 return fflush(fs);1069 }1070 1151 1071 1152 fprintf(fs, "%d Enter %sauto response, terminate with a . on a line by itself:\n", 1072 CODE_ENTERxTEXT, nUin == 0 ? "" : "custom " ); 1073 1074 m_nUin = nUin; 1153 CODE_ENTERxTEXT, m_szId == 0 ? "" : "custom " ); 1154 1075 1155 m_szText[0] = '\0'; 1076 1156 m_nTextPos = 0; … … 1082 1162 int CRMSClient::Process_AR_text() 1083 1163 { 1084 if (m_ nUin== 0)1085 { 1086 ICQOwner *o = gUserManager.FetchOwner( LOCK_W);1164 if (m_szId == 0) 1165 { 1166 ICQOwner *o = gUserManager.FetchOwner(m_nPPID, LOCK_W); 1087 1167 o->SetAutoResponse(m_szText); 1088 1168 gUserManager.DropOwner(); … … 1090 1170 else 1091 1171 { 1092 ICQUser *u = gUserManager.FetchUser(m_ nUin, LOCK_W);1172 ICQUser *u = gUserManager.FetchUser(m_szId, m_nPPID, LOCK_W); 1093 1173 u->SetCustomAutoResponse(m_szText); 1094 1174 gUserManager.DropUser(u); … … 1136 1216 * 1137 1217 * Command: 1138 * VIEW <uin>1218 * VIEW [ <id>[.<protocol> ] 1139 1219 * 1140 1220 * Response: … … 1143 1223 int CRMSClient::Process_VIEW() 1144 1224 { 1145 unsigned long nUin = 0;1146 char *szId = 0;1147 1148 1225 if (*data_arg != '\0') 1149 1226 { 1150 nUin = strtoul(data_arg, (char**)NULL, 10); 1151 szId = strdup(data_arg); 1227 ParseUser(data_arg); 1152 1228 } 1153 1229 else … … 1159 1235 { 1160 1236 if(pUser->NewMessages() > 0) 1161 szId = strdup(pUser->IdString()); 1237 { 1238 if (m_szId) 1239 free(m_szId); 1240 m_szId = strdup(pUser->IdString()); 1241 m_nPPID = pUser->PPID(); 1242 FOR_EACH_USER_BREAK 1243 } 1162 1244 } 1163 1245 FOR_EACH_USER_END 1164 1246 1165 if ( szId == 0)1247 if (m_szId == 0) 1166 1248 { 1167 1249 fprintf(fs, "%d No new messages.\n", CODE_VIEWxNONE); … … 1170 1252 } 1171 1253 1172 ICQUser *u = gUserManager.FetchUser( szId, LICQ_PPID, LOCK_W);1254 ICQUser *u = gUserManager.FetchUser(m_szId, m_nPPID, LOCK_W); 1173 1255 if (u == NULL) 1174 1256 { … … 1233 1315 1234 1316 gUserManager.DropUser(u); 1235 1236 if (szId) free(szId); 1317 1237 1318 return fflush(fs); 1238 1319 } … … 1242 1323 * 1243 1324 * Command: 1244 * ADDUSER < uin>1325 * ADDUSER <id> <protocol> 1245 1326 * 1246 1327 * Response: … … 1249 1330 int CRMSClient::Process_ADDUSER() 1250 1331 { 1251 unsigned long nUin = strtoul(data_arg, (char**)NULL, 10); 1252 1253 if (nUin >= 10000) 1254 { 1255 if (licqDaemon->AddUserToList(nUin)) 1256 { 1257 fprintf(fs, "%d User added\n", CODE_ADDUSERxDONE); 1258 } 1259 else 1260 { 1261 fprintf(fs, "%d User not added\n", CODE_ADDUSERxERROR); 1262 } 1332 char *szId = strdup(data_arg); 1333 NEXT_WORD(data_arg); 1334 unsigned long nPPID = GetProtocol(data_arg); 1335 1336 if (licqDaemon->AddUserToList(szId, nPPID)) 1337 { 1338 fprintf(fs, "%d User added\n", CODE_ADDUSERxDONE); 1263 1339 } 1264 1340 else 1265 1341 { 1266 fprintf(fs, "%d Invalid UIN.\n", CODE_INVALIDxUSER);1267 } 1268 1342 fprintf(fs, "%d User not added\n", CODE_ADDUSERxERROR); 1343 } 1344 1269 1345 return fflush(fs); 1270 1346 } -
trunk/rms/src/rms.h
r4081 r4144 93 93 unsigned short data_line_pos; 94 94 unsigned long m_nCheckUin; 95 char *m_szCheckId; 95 96 unsigned long m_nLogTypes; 96 97 97 98 unsigned long m_nUin; 98 99 char *m_szId; 100 unsigned long m_nPPID; 99 101 char m_szText[MAX_TEXT_LENGTH + 1]; 100 102 char m_szLine[MAX_LINE_LENGTH + 1]; … … 105 107 bool ProcessEvent(ICQEvent *); 106 108 bool AddLineToText(); 107 109 unsigned long GetProtocol(const char *); 110 void ParseUser(const char *); 111 108 112 int Process_MESSAGE_text(); 109 113 int Process_URL_url();
