summaryrefslogtreecommitdiff
path: root/mBot/src/mbot/functions
diff options
context:
space:
mode:
Diffstat (limited to 'mBot/src/mbot/functions')
-rw-r--r--mBot/src/mbot/functions/mb_auth.cpp115
-rw-r--r--mBot/src/mbot/functions/mb_contact.cpp518
-rw-r--r--mBot/src/mbot/functions/mb_dlg.cpp899
-rw-r--r--mBot/src/mbot/functions/mb_event.cpp202
-rw-r--r--mBot/src/mbot/functions/mb_ft.cpp260
-rw-r--r--mBot/src/mbot/functions/mb_icons.cpp79
-rw-r--r--mBot/src/mbot/functions/mb_irc.cpp357
-rw-r--r--mBot/src/mbot/functions/mb_menu.cpp167
-rw-r--r--mBot/src/mbot/functions/mb_misc.cpp185
-rw-r--r--mBot/src/mbot/functions/mb_msg.cpp152
-rw-r--r--mBot/src/mbot/functions/mb_proto.cpp80
-rw-r--r--mBot/src/mbot/functions/mb_pu.cpp198
-rw-r--r--mBot/src/mbot/functions/mb_reg.cpp432
-rw-r--r--mBot/src/mbot/functions/mb_search.cpp154
-rw-r--r--mBot/src/mbot/functions/mb_snd.cpp73
-rw-r--r--mBot/src/mbot/functions/mb_sys.cpp786
16 files changed, 4657 insertions, 0 deletions
diff --git a/mBot/src/mbot/functions/mb_auth.cpp b/mBot/src/mbot/functions/mb_auth.cpp
new file mode 100644
index 0000000..5fdae44
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_auth.cpp
@@ -0,0 +1,115 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+///////////////////////////////
+//authorize
+///////////////////////////////
+ZEND_FUNCTION(mb_AuthGetInfo)
+{
+ sPHPENV* ctx = (sPHPENV*)SG(server_context);
+ mb_event* mbe = (mb_event*)(ctx->c_param);
+ char* inf = (char*)mbe->p3;
+
+ if(mbe->t2 != MBE_EVENTID || (mbe->p2 != (void*)MB_EVENT_AUTH_IN) || mbe->t3!=MBE_CUSTOM){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(array_init(return_value)==FAILURE){
+ RETURN_FALSE;
+ }
+
+ //blob is: uin(DWORD),hcontact(HANDLE),nick(ASCIIZ),first(ASCIIZ),last(ASCIIZ),email(ASCIIZ),reason(ASCIIZ)
+
+ //nick
+ inf += sizeof(DWORD) + sizeof(HANDLE);
+ add_index_string(return_value,0,inf,1);
+ //first
+ inf += strlen(inf) + 1;
+ add_index_string(return_value,1,inf,1);
+ //last
+ inf += strlen(inf) + 1;
+ add_index_string(return_value,2,inf,1);
+ //email
+ inf += strlen(inf) + 1;
+ add_index_string(return_value,3,inf,1);
+ return;
+}
+
+ZEND_FUNCTION(mb_AuthDeny)
+{
+ sPHPENV* ctx = (sPHPENV*)SG(server_context);
+ mb_event* mbe = (mb_event*)(ctx->c_param);
+ char* reason=NULL;
+ long rl=0,hid=0,cid=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll",&reason,&rl,&cid,&hid) == FAILURE ||
+ !reason || !hid || !cid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG((CallService(PS_AUTHDENY,(WPARAM)hid,(LPARAM)reason) == 0));
+}
+
+ZEND_FUNCTION(mb_AuthAccept)
+{
+ sPHPENV* ctx = (sPHPENV*)SG(server_context);
+ mb_event* mbe = (mb_event*)(ctx->c_param);
+ long hid=0,cid=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",&cid,&hid) == FAILURE || !hid || !cid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG((CallContactService((HANDLE)cid,PS_AUTHALLOW,(WPARAM)hid,NULL) == 0));
+}
+
+ZEND_FUNCTION(mb_AuthStore)
+{
+ DBEVENTINFO dbei = {sizeof(dbei),0};
+ sPHPENV* ctx = (sPHPENV*)SG(server_context);
+ mb_event* mbe = (mb_event*)(ctx->c_param);
+ CCSDATA* css = (CCSDATA*)mbe->lParam;
+ PROTORECVEVENT* prr;
+ long result = 0;
+ char* proto = NULL;
+
+ if(mbe->event != MBT_AUTHRECV || !css || !css->lParam){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(mbe->lFlags & MBOT_FLAG_STORED){
+ RETURN_FALSE;
+ }
+
+ prr = (PROTORECVEVENT*)css->lParam;
+ proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)css->hContact,0);
+
+ dbei.cbBlob = prr->lParam;
+ dbei.pBlob = (PBYTE)prr->szMessage;
+ dbei.eventType = (unsigned short)EVENTTYPE_AUTHREQUEST;
+ dbei.timestamp = time(0);
+ dbei.szModule = proto;
+ dbei.flags = DBEF_READ;
+
+ result = CallService(MS_DB_EVENT_ADD,(WPARAM)css->hContact,(LPARAM)&dbei);
+ if(result){
+ mbe->lFlags |= MBOT_FLAG_STORED;
+ }
+
+ RETURN_LONG(result);
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_contact.cpp b/mBot/src/mbot/functions/mb_contact.cpp
new file mode 100644
index 0000000..6156936
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_contact.cpp
@@ -0,0 +1,518 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+ZEND_FUNCTION(mb_CIsOnList)
+{
+ long cid=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE || cid==0){
+ PHP_FALSE_AND_ERROR;
+ }
+ RETURN_LONG(DBGetContactSettingByte((HANDLE)cid,"CList","NotOnList",0)==FALSE);
+}
+
+ZEND_FUNCTION(mb_CSendTypingInfo)
+{
+ long cid=0;
+ char on=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb",&cid,&on) == FAILURE || cid==0){
+ PHP_FALSE_AND_ERROR;
+ }
+
+ RETURN_LONG(CallContactService((HANDLE)cid,PSS_USERISTYPING,(WPARAM)cid,on)==0);
+}
+
+ZEND_FUNCTION(mb_CGetStatus)
+{
+ long cid = 0;
+ char* proto = NULL;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE || !cid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)cid,0);
+ if(!proto){
+ RETURN_FALSE;
+ }
+
+ cid = DBGetContactSettingWord((HANDLE)cid,proto,"Status",0);
+ RETURN_LONG(cid);
+}
+
+ZEND_FUNCTION(mb_CGetProto)
+{
+ long cid = 0;
+ char* proto = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE || !cid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)cid,0);
+ if(proto){
+ RETURN_STRING(proto,1);
+ }else{
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_CDelete)
+{
+ long cid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE || !cid)
+ {
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(CallService(MS_DB_CONTACT_DELETE,(WPARAM)cid,0)==0);
+}
+
+ZEND_FUNCTION(mb_CGetDisplayName)
+{
+ long cid=0;
+ char* tmp=NULL;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE || !cid)
+ {
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ tmp = (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME,(WPARAM)cid,0);
+ if(tmp){
+ RETURN_STRING(tmp,1);
+ }else{
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_CGetAwayMsg)
+{
+ long cid=0;
+ zval *cb;
+ char *proto;
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+ sACKSync* ack;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz",&cid,&cb)==FAILURE || cid==0 || cb->type != IS_STRING){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!(proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,cid,0))){
+ RETURN_FALSE;
+ }
+
+ ack = (sACKSync*)my_malloc(sizeof(sACKSync));
+ if(!ack){RETURN_FALSE}
+ memset(ack,0,sizeof(sACKSync));
+
+ if(!(ack->php = mbe->php))goto Error;
+ sman_incref(ack->php);
+
+ ack->lType = ACKTYPE_AWAYMSG;
+ ack->hContact = (HANDLE)cid;
+
+ strncpy(ack->pszFunction,cb->value.str.val,sizeof(ack->pszFunction)-1);
+ strncpy(ack->pszProtocol,proto,15);
+
+ if(!g_slist.Add(ack)){goto Error;}
+
+ ack->hProcess = (HANDLE)CallContactService((HANDLE)cid,PSS_GETAWAYMSG,0,0);
+ if(!ack->hProcess){
+ g_slist.Del(ack);
+ goto Error;
+ }
+ RETURN_LONG(1);
+Error:
+ if(ack->php)sman_decref(ack->php);
+ if(ack)my_memfree(ack);
+ RETURN_FALSE;
+}
+
+int xx_enumcsettings(const char *szSetting,LPARAM lParam)
+{
+ cutMemf* mf = (cutMemf*)lParam;
+ if(*szSetting){
+ mf->write((void*)szSetting, strlen(szSetting)+1);
+ }
+ return 0;
+}
+
+ZEND_FUNCTION(mb_CSettingEnum)
+{
+ DBCONTACTENUMSETTINGS ecs = {0};
+ cutMemf mf;
+ long cid=0,ml=0;
+ char* mod=NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls",&cid,&mod,&ml) == FAILURE || !mod || !ml){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!mf.create(2048)){
+ RETURN_FALSE;
+ }
+
+ ecs.pfnEnumProc = xx_enumcsettings;
+ ecs.szModule = mod;
+ ecs.lParam = (LPARAM)&mf;
+
+ if(CallService(MS_DB_CONTACT_ENUMSETTINGS,cid,(LPARAM)&ecs)!=0){
+ RETURN_FALSE;
+ }
+ mf.putc(0);
+ if(array_init(return_value)==FAILURE){
+ RETURN_FALSE;
+ }
+
+ mod = (char*)mf.getdata();
+ ml = 0;
+ while(*mod)
+ {
+ add_index_string(return_value,ml,mod,1);
+ mod = mod + strlen(mod) + 1;
+ ml++;
+ }
+ mf.close();
+ return;
+}
+
+ZEND_FUNCTION(mb_CSetApparentMode)
+{
+ long cid=0,mode=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",&cid,&mode) == FAILURE || !cid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(CallContactService((HANDLE)cid,PSS_SETAPPARENTMODE,mode,0)==0);
+}
+ZEND_FUNCTION(mb_CAddNew)
+{
+ RETURN_LONG(CallService(MS_DB_CONTACT_ADD,0,0));
+}
+ZEND_FUNCTION(mb_CAddAuth)
+{
+ long aid=0;
+ DBEVENTINFO dbei={0};
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&aid) == FAILURE || !aid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ dbei.cbSize = sizeof(dbei);
+
+ if(CallService(MS_DB_EVENT_GET,(WPARAM)aid,(LPARAM)&dbei)!=0){
+ RETURN_FALSE;
+ }
+ RETURN_LONG(CallProtoService(dbei.szModule,PS_ADDTOLISTBYEVENT,0,(LPARAM)aid));
+}
+ZEND_FUNCTION(mb_CAddSearch)
+{
+ //MBT_SRESULT
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+ if(mbe->event != MBT_CALLBACK || mbe->t3 != MBE_SRESULT)
+ {
+ //PHPWARN();
+ RETURN_FALSE;
+ }
+ else
+ {
+ PROTOSEARCHRESULT* sr = (PROTOSEARCHRESULT*)mbe->p3;
+ ACKDATA* ack = (ACKDATA*)mbe->p2;
+
+ RETURN_LONG(CallProtoService(ack->szModule,PS_ADDTOLIST,0,(LPARAM)sr));
+ }
+}
+ZEND_FUNCTION(mb_CGetInfo)
+{
+ long cid=0,cf=0;
+ CONTACTINFO ci={0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",&cid,&cf) == FAILURE || !cid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(cf < 1 || cf > 17){
+ RETURN_FALSE;
+ }
+
+ ci.cbSize = sizeof(ci);
+ ci.dwFlag = (BYTE)((0xFF)& cf);
+ ci.hContact = (HANDLE)cid;
+ ci.szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)cid,0);
+
+ cid = CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci);
+
+ if(cid == 0)
+ {
+ if(ci.type == CNFT_ASCIIZ){
+ RETURN_STRING(ci.pszVal,1);
+ }else if(ci.type == CNFT_BYTE){
+ RETURN_LONG(ci.bVal);
+ }else if(ci.type == CNFT_WORD){
+ RETURN_LONG(ci.wVal);
+ }else{
+ RETURN_LONG(ci.dVal);
+ }
+
+ if(cf >= 16)
+ {
+ MM_INTERFACE mmi={0};
+ mmi.cbSize = sizeof(mmi);
+ CallService(MS_SYSTEM_GET_MMI,0,(LPARAM)&mmi);
+ mmi.mmi_free((void*)ci.pszVal);
+ }
+ return;
+ }else{
+ RETURN_FALSE;
+ }
+}
+ZEND_FUNCTION(mb_CGetUIN)
+{
+ long cid = 0;
+ char* proto = NULL;
+ char* uin = NULL;
+ DBVARIANT dbv;
+ DBCONTACTGETSETTING cgs;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE || cid==0){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)cid,0);
+ if(!proto){
+ RETURN_FALSE;
+ }
+ uin = (char*)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
+ if(!uin){
+ RETURN_FALSE;
+ }
+
+ cgs.szModule=proto;
+ cgs.szSetting=uin;
+ cgs.pValue=&dbv;
+ if(CallService(MS_DB_CONTACT_GETSETTING,(WPARAM)cid,(LPARAM)&cgs)){
+ RETURN_FALSE;
+ }
+
+ if(dbv.type==DBVT_BYTE){
+ RETVAL_LONG(dbv.bVal);
+ }else if(dbv.type==DBVT_WORD){
+ RETVAL_LONG(dbv.wVal);
+ }else if(dbv.type==DBVT_DWORD){
+ RETVAL_LONG(dbv.dVal);
+ }else if(dbv.type==DBVT_ASCIIZ){
+ RETVAL_STRING(dbv.pszVal,1);
+ }else if(dbv.type==DBVT_BLOB){
+ RETVAL_STRINGL((char*)dbv.pbVal,dbv.cpbVal,1)
+ }else{
+ RETVAL_FALSE;
+ }
+ DBFreeVariant(&dbv);
+ return;
+}
+
+ZEND_FUNCTION(mb_CSettingGet)
+{
+ char* setting = NULL;
+ char* module = NULL;
+ long cid=0,sl=0,ml=0;
+ DBVARIANT dbv;
+ DBCONTACTGETSETTING cgs;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss",&cid,&module,&ml,&setting,&sl) == FAILURE || !sl || !ml){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ cgs.szModule=module;
+ cgs.szSetting=setting;
+ cgs.pValue=&dbv;
+
+ if(CallService(MS_DB_CONTACT_GETSETTING,(WPARAM)cid,(LPARAM)&cgs)){
+ RETURN_FALSE;
+ }
+
+ if(dbv.type==DBVT_BYTE){
+ RETVAL_LONG(dbv.bVal);
+ }else if(dbv.type==DBVT_WORD){
+ RETVAL_LONG(dbv.wVal);
+ }else if(dbv.type==DBVT_DWORD){
+ RETVAL_LONG(dbv.dVal);
+ }else if(dbv.type==DBVT_ASCIIZ){
+ RETVAL_STRING(dbv.pszVal,1);
+ }else if(dbv.type==DBVT_BLOB){
+ RETVAL_STRINGL((char*)dbv.pbVal,dbv.cpbVal,1)
+ }else{
+ RETVAL_FALSE;
+ }
+ DBFreeVariant(&dbv);
+}
+ZEND_FUNCTION(mb_CSettingDel)
+{
+ char* setting = NULL;
+ char* module = NULL;
+ long cid=0,sl=0,ml=0;
+ DBVARIANT dbv={0};
+ DBCONTACTGETSETTING cgs;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss",&cid,&module,&ml,&setting,&sl) == FAILURE || !sl || !ml){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else{
+ //MBT_CSCHANGED
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+ if(mbe->event == MBT_CSCHANGED && strcmp(setting,"Status")==0){
+ RETURN_FALSE;
+ }
+ }
+
+ cgs.szModule=module;
+ cgs.szSetting=setting;
+ cgs.pValue=&dbv;
+
+ RETURN_LONG(DBDeleteContactSetting((HANDLE)cid,module,setting)==0);
+}
+
+
+ZEND_FUNCTION(mb_CSettingSet)
+{
+ char* setting = NULL;
+ char* module = NULL;
+ char* value = NULL;
+ char buf[32]={0};
+ long cid=0,sl=0,ml=0,vl=0;
+ DBVARIANT dbv ={0};
+ DBCONTACTGETSETTING cgs;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsss",&cid,&module,&ml,&setting,&sl,&value,&vl) == FAILURE ||
+ !sl || !ml || !value){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else{
+ //MBT_CSCHANGED
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+ if(mbe->event == MBT_CSCHANGED && strcmp(setting,"Status")==0){
+ RETURN_FALSE;
+ }
+ }
+
+
+ cgs.szModule = module;
+ cgs.szSetting = setting;
+ cgs.pValue = &dbv;
+
+ dbv.type = DBVT_ASCIIZ;
+ dbv.pszVal = (char*)buf;
+ dbv.cchVal = sizeof(buf);
+
+ if(CallService(MS_DB_CONTACT_GETSETTINGSTATIC,(WPARAM)cid,(LPARAM)&cgs)){
+ RETURN_FALSE;
+ }
+
+ if(dbv.type==DBVT_BYTE){
+ RETVAL_LONG(DBWriteContactSettingByte((HANDLE)cid,module,setting,(BYTE)(strtoul(value,NULL,0)&0xff))==FALSE);
+ }else if(dbv.type==DBVT_WORD){
+ RETVAL_LONG(DBWriteContactSettingWord((HANDLE)cid,module,setting,(WORD)(strtoul(value,NULL,0)&0xffff))==FALSE);
+ }else if(dbv.type==DBVT_DWORD){
+ RETVAL_LONG(DBWriteContactSettingDword((HANDLE)cid,module,setting,(DWORD)(strtoul(value,NULL,0)))==FALSE);
+ }else if(dbv.type==DBVT_ASCIIZ){
+ RETVAL_LONG(DBWriteContactSettingString((HANDLE)cid,module,setting,value)==FALSE)
+ }else if(dbv.type==DBVT_BLOB){
+ DBCONTACTWRITESETTING cws;
+ cws.szModule=module;
+ cws.szSetting = mbot_replace_with_our_own(setting);
+ cws.value.type=DBVT_BLOB;
+ cws.value.pbVal=(BYTE*)value;
+ cws.value.cpbVal = (WORD)(vl&0x00ffff);
+ RETVAL_LONG(CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)cid,(LPARAM)&cws)==FALSE);
+ }else{
+ RETVAL_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_CSettingAdd)
+{
+ char* setting = NULL;
+ char* module = NULL;
+ char* value = NULL;
+ char buf[32]={0};
+ long cid=0,sl=0,ml=0,vl=0,type=0;
+ DBVARIANT dbv ={0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lslss",&cid,&module,&ml,&type,&setting,&sl,&value,&vl) == FAILURE ||
+ !sl || !ml || !value){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else{
+ //MBT_CSCHANGED
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+ if(mbe->event == MBT_CSCHANGED && strcmp(setting,"Status")==0){
+ RETURN_FALSE;
+ }
+ }
+
+ if(type==DBVT_BYTE){
+ RETVAL_LONG(DBWriteContactSettingByte((HANDLE)cid,module,setting,(BYTE)(strtoul(value,NULL,0)&0xff))==FALSE);
+ }else if(type==DBVT_WORD){
+ RETVAL_LONG(DBWriteContactSettingWord((HANDLE)cid,module,setting,(WORD)(strtoul(value,NULL,0)&0xffff))==FALSE);
+ }else if(type==DBVT_DWORD){
+ RETVAL_LONG(DBWriteContactSettingDword((HANDLE)cid,module,setting,(DWORD)(strtoul(value,NULL,0)))==FALSE);
+ }else if(type==DBVT_ASCIIZ){
+ RETVAL_LONG(DBWriteContactSettingString((HANDLE)cid,module,setting,value)==FALSE)
+ }else if(type==DBVT_BLOB){
+ DBCONTACTWRITESETTING cws;
+ cws.szModule=module;
+ cws.szSetting = mbot_replace_with_our_own(setting);
+ cws.value.type=DBVT_BLOB;
+ cws.value.pbVal=(BYTE*)value;
+ cws.value.cpbVal = (WORD)(vl&0x00ffff);
+ RETVAL_LONG(CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)cid,(LPARAM)&cws)==FALSE);
+ }else{
+ RETVAL_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_CFindFirst)
+{
+ long cid = CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ RETURN_LONG(cid);
+}
+ZEND_FUNCTION(mb_CFindNext)
+{
+ long cid = 0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE || cid==NULL){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ cid = CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)cid,0);
+ RETURN_LONG(cid);
+}
+ZEND_FUNCTION(mb_CFindByUIN)
+{
+ char* proto=NULL;
+ long pl=0;
+ zval* uin;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",&proto,&pl,&uin) == FAILURE || !pl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(uin->type == IS_STRING){
+ RETURN_LONG((long)help_find_by_uin(proto,uin->value.str.val,0));
+ }else if(uin->type == IS_LONG){
+ RETURN_LONG((long)help_find_by_uin(proto,(const char*)uin->value.lval,1));
+ }else{
+ RETURN_FALSE;
+ }
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_dlg.cpp b/mBot/src/mbot/functions/mb_dlg.cpp
new file mode 100644
index 0000000..9ff635b
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_dlg.cpp
@@ -0,0 +1,899 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+#include "../dialogs.h"
+
+int g_res_dlg_id = 0;
+char* g_res_dlg_name = "mb_rsc_dlg";
+
+void help_dlg_destruction_handler(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+{
+ sDialog* dlg = (sDialog*)rsrc->ptr;
+ if(dlg && (dlg->lFlags & 0x01)==0)
+ {
+ if(dlg->hDlg){
+ DestroyWindow(dlg->hDlg);
+ dlg->hDlg = NULL;
+ }
+ DlgFree(dlg);
+ }
+}
+
+ZEND_FUNCTION(mb_DlgGetFile)
+{
+ char open = 0;
+ char *ext = NULL;
+ char *std = NULL;
+ char *e;
+ long el = 0;
+ long sl = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sb|s",&ext,&el,&open,&std,&sl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(el < 2 || ext[el-1]!='|'){
+ RETURN_FALSE;
+ }
+
+ e = ext;
+ while(*e){
+ if(*e == '|'){
+ *e = '\0';
+ }e++;
+ };
+
+ e = help_getfilename(open,ext,std);
+ if(e && *e){
+ RETURN_STRING(e,1);
+ }else{
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_DlgGetFileMultiple)
+{
+ char *ext = NULL;
+ char *fn;
+ char *e;
+ char out[2048];
+ char path[MAX_PATH];
+ long el = 0;
+ long n = 0;
+ long offset = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&ext,&el) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(el < 2 || ext[el-1]!='|'){
+ RETURN_FALSE;
+ }
+
+ e = ext;
+ while(*e){
+ if(*e == '|'){
+ *e = '\0';
+ }e++;
+ };
+
+ *out = 0;
+
+ fn = help_getfilenamemultiple(ext,out,sizeof(out)-1,&offset);
+
+ if(!fn || array_init(return_value)==FAILURE)
+ {
+ RETURN_FALSE;
+ }
+ else
+ {
+ //add_index_string(return_value,i,proto[i]->szName,1);
+ if(offset>0){
+ out[offset-1]='\0';
+ }
+
+ fn = out + offset;
+ while(*fn)
+ {
+ _snprintf(path,sizeof(path)-1,"%s\\%s",out,fn);
+ add_index_string(return_value,n++,path,1);
+ fn += strlen(fn) + 1;
+ }
+ return;
+ }
+}
+
+ZEND_FUNCTION(mb_DlgCreate)
+{
+ char* title=NULL;
+ unsigned long tl=0;
+ unsigned long cx=CW_USEDEFAULT;
+ unsigned long cy=CW_USEDEFAULT;
+ long rs_id = 0;
+ long param = 0;
+ long flags = 0;
+ zval* cb;
+ sDialog* dlg = NULL;
+
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szll|ll",&title,&tl,&cb,&cx,&cy,&param,&flags) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(mbe->php == NULL){
+ RETURN_FALSE;
+ }else if(!zend_is_callable(cb,0,NULL)){
+ PHPWSE("$cb is expected to be a valid callback function!");
+ }
+
+ if(!tl){title="MBot";}
+ if(cx < 100 || cx > 1024){
+ cx = 256;
+ }
+ if(cy < 100 || cy > 1024){
+ cy = 256;
+ }
+
+ dlg = (sDialog*)my_malloc(sizeof(sDialog));
+ if(!dlg){
+ RETURN_NULL();
+ }
+ memset(dlg,0,sizeof(sDialog));
+ dlg->php = mbe->php;
+ dlg->param = param;
+
+ if(!(dlg->hDlg = CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)DlgProcedure,(LPARAM)dlg))){
+ goto Error;
+ }
+
+ if(flags & 0x01){
+ ShowWindow(GetDlgItem(dlg->hDlg,IDCANCEL),SW_HIDE);
+ }
+
+ SetWindowPos(dlg->hDlg,NULL,0,0,cx,cy,SWP_NOMOVE | SWP_NOZORDER);
+ SetWindowText(dlg->hDlg,title);
+ SendMessage(dlg->hDlg,WM_USER + 2,0,0);
+ strncpy(dlg->pszCallback,cb->value.str.val,sizeof(dlg->pszCallback)-1);
+
+ rs_id = zend_list_insert(dlg,g_res_dlg_id);
+ if(rs_id){
+ RETURN_RESOURCE(rs_id);
+ }
+Error:
+ if(dlg){
+ if(dlg->hDlg)DestroyWindow(dlg->hDlg);
+ my_memfree(dlg);
+ }
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgRun)
+{
+ zval* res = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r",&res) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ if(!res)goto Error;
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || (dlg->lFlags & 0x01))goto Error;
+
+ ShowWindow(dlg->hDlg,SW_SHOWNORMAL);
+ dlg->lFlags |= 1;
+
+ RETURN_TRUE;
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_DlgSetCallbacks)
+{
+ zval* res = 0;
+ zval* wmc=NULL;
+ zval* wmn=NULL;
+ zval* wmt=NULL;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|z!z!z!",&res,&wmc,&wmn,&wmt) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ if(!res)goto Error;
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)goto Error;
+
+ if(wmc && zend_is_callable(wmc,0,NULL)){
+ strncpy(dlg->pszWmCommand,wmc->value.str.val,sizeof(dlg->pszWmCommand));
+ }else{
+ *dlg->pszWmCommand = 0;
+ }
+
+ if(wmn && zend_is_callable(wmn,0,NULL)){
+ strncpy(dlg->pszWmNotify,wmn->value.str.val,sizeof(dlg->pszWmNotify));
+ }else{
+ *dlg->pszWmNotify = 0;
+ }
+
+ if(wmt && zend_is_callable(wmt,0,NULL)){
+ strncpy(dlg->pszWmTimer,wmt->value.str.val,sizeof(dlg->pszWmTimer));
+ }else{
+ *dlg->pszWmTimer = 0;
+ }
+
+ RETURN_TRUE;
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_DlgSetTimer)
+{
+ unsigned long id,ts;
+ zval* res = 0;
+ zval* cb = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllz",&res,&id,&ts,&cb) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHPWSE("$cb must be a valid callback!");
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)RETURN_FALSE;
+
+ strncpy(dlg->pszWmTimer,cb->value.str.val,sizeof(dlg->pszWmTimer));
+
+ RETURN_LONG(SetTimer(dlg->hDlg,id,ts,NULL));
+}
+
+ZEND_FUNCTION(mb_DlgKillTimer)
+{
+ unsigned long id;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",&res,&id) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)RETURN_FALSE;
+ RETURN_LONG(KillTimer(dlg->hDlg,id));
+}
+
+ZEND_FUNCTION(mb_DlgGet)
+{
+ sDialog* dlg = NULL;
+ long rs_id = 0;
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(mbe->event != MBT_DIALOG){
+ RETURN_NULL();
+ }
+
+ if(mbe->p1 != NULL){
+ RETURN_RESOURCE((long)mbe->p1);
+ }
+
+ dlg = (sDialog*)mbe->p3;
+ rs_id = zend_list_insert(dlg,g_res_dlg_id);
+ if(rs_id){
+ mbe->p1 = (void*)(rs_id);
+ RETURN_RESOURCE(rs_id);
+ }
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgGetText)
+{
+ unsigned long id=0;
+ char text[2048];
+ zval* res = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",&res,&id) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)goto Error;
+
+
+ if(id > (dlg->lNum + 1000)){
+ goto Error;
+ }else{
+ *text = 0;
+ GetDlgItemText(dlg->hDlg,id,text,sizeof(text)-1);
+ RETURN_STRING(text,1);
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgSetText)
+{
+ char* text="";
+ unsigned long id=0,tl=0;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls",&res,&id,&text,&tl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)goto Error;
+
+
+ if(id > (dlg->lNum + 1000)){
+ goto Error;
+ }else{
+ SetDlgItemText(dlg->hDlg,id,text);
+ }
+ RETURN_TRUE;
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_DlgGetInt)
+{
+ unsigned long id=0;
+ char isss=0;
+ int ok = 0;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|b",&res,&id,&isss) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)goto Error;
+
+
+ if(id > (dlg->lNum + 1000)){
+ goto Error;
+ }else{
+ id = GetDlgItemInt(dlg->hDlg,id,&ok,isss);
+ if(ok){
+ RETURN_LONG(id);
+ }else{
+ RETURN_FALSE;
+ }
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgSendMsg)
+{
+ zval* res=0;
+ zval* lparam=0;
+ zval* wparam=0;
+ unsigned long id=0;
+ unsigned long msg=0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll|z!z!",&res,&id,&msg,&wparam,&lparam) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || !msg || msg == WM_DESTROY)goto Error;
+
+ if(id > (dlg->lNum + 1000)){
+ goto Error;
+ }else{
+ try{
+ void* lp = (lparam->type==IS_STRING)?((void*)lparam->value.str.val):((void*)lparam->value.lval);
+ void* wp = (lparam->type==IS_STRING)?((void*)wparam->value.str.val):((void*)wparam->value.lval);
+ RETURN_LONG(SendDlgItemMessage(dlg->hDlg,id,msg,(WPARAM)wp,(LPARAM)lp));
+ }catch(...){
+ RETURN_FALSE;
+ }
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgGetIdByParam)
+{
+ long param=0;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",&res,&param) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)goto Error;
+
+ for(unsigned long i=0;i<dlg->lNum;i++)
+ {
+ if(dlg->table[i]->param == param){
+ RETURN_LONG(1000 + i);
+ }
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgGetHWND)
+{
+ long id=0;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",&res,&id) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)goto Error;
+ if(id == NULL){
+ RETURN_LONG((long)dlg->hDlg);
+ }else{
+ RETURN_LONG((long)GetDlgItem(dlg->hDlg,id));
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgMove)
+{
+ sDialog* dlg = NULL;
+ long id,x,y,cx=-1,cy=-1;
+ HWND hWnd;
+ zval* res = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll|ll",&res,&id,&x,&y,&cx,&cy) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg)goto Error;
+
+ hWnd = (id == NULL)?(dlg->hDlg):GetDlgItem(dlg->hDlg,id);
+ RETURN_LONG(SetWindowPos(hWnd,NULL,x,y,cx,cy,SWP_NOZORDER | ((cx == -1)?(SWP_NOSIZE):0)));
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgGetString)
+{
+ sStdInDlg di = {0};
+ zval* tmp = NULL;
+ long ilen;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sllls",&di.info,&ilen,&di.title,&ilen,&di.flags,&di.x,&di.y,&di.def,&ilen) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+
+ //zend_alter_ini_entry("max_execution_time",sizeof("max_execution_time"),"600",3,PHP_INI_USER,PHP_INI_STAGE_RUNTIME);
+
+ if(DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_DIALOG2),NULL,(DLGPROC)DlgStdInProc,(LPARAM)&di)==IDOK)
+ {
+ RETURN_STRING(di.buffer,1);
+ }else{
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_DlgListAddItem)
+{
+ unsigned long id=0;
+ unsigned long nl=0;
+ unsigned long cx=0;
+ unsigned long i=0;
+ zval* res = 0;
+ char* values[5]={0};
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+ LVITEM li={0};
+ HWND hList;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls|ssss",&res,&id,&values[0],&nl,
+ &values[1],&nl,&values[2],&nl,&values[3],&nl,&values[4],&nl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)) || *values[0]=='\0')goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 6)goto Error;
+
+ li.pszText = values[0];
+ li.lParam = (LPARAM)ct->cs2;
+ li.iSubItem = 0;
+ li.iItem = ct->cs2;
+ li.mask = LVIF_PARAM | LVIF_TEXT;
+
+ hList = GetDlgItem(dlg->hDlg,id);
+ nl = ListView_InsertItem(hList,&li);
+ if(nl != -1)
+ {
+ for(char** v=(values + 1);*v;v++)
+ {
+ li.mask = LVIF_TEXT;
+ li.pszText = *v;
+ li.iItem = nl;
+ li.iSubItem = ++i;
+ ListView_SetItem(hList,&li);
+ }
+ ct->cs2++;
+ RETURN_LONG(nl);
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgListDelItem)
+{
+ unsigned long item=0;
+ unsigned long id=0;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll",&res,&id,&item) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 6)goto Error;
+
+ RETURN_LONG(ListView_DeleteItem(ct->hWnd,item));
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgListSetItem)
+{
+ unsigned long id=0,it=0,si=0,tl=0;
+ zval* res = 0;
+ char* txt = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+ LVITEM li={0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllls",&res,&id,&it,&si,&txt,&tl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 6 || it > ct->cs2 || si > ct->cs1)goto Error;
+
+ li.mask = LVIF_TEXT;
+ li.pszText = txt;
+ li.iItem = it;
+ li.iSubItem = si;
+ ListView_SetItem(ct->hWnd,&li);
+ RETURN_TRUE;
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgListGetItem)
+{
+ unsigned long id=0,it=0,si=0;
+ char buffer[1024];
+ zval* res = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+ LVITEM li={0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll",&res,&id,&it,&si) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 6 || it > ct->cs2 || si > ct->cs1)goto Error;
+
+ *buffer = 0;
+
+ li.mask = LVIF_TEXT;
+ li.iItem = it;
+ li.iSubItem = si;
+ li.pszText = buffer;
+ li.cchTextMax = sizeof(buffer)-1;
+
+ if(ListView_GetItem(ct->hWnd,&li) == FALSE)goto Error;
+ RETURN_STRING(buffer,1);
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgListGetSel)
+{
+ unsigned long id=0;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",&res,&id) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 6)goto Error;
+
+ id = ListView_GetSelectionMark(ct->hWnd);
+ if(id !=-1){
+ RETURN_LONG(id);
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgListAddCol)
+{
+ unsigned long id=0;
+ unsigned long nl=0;
+ unsigned long cx=0;
+ zval* res = 0;
+ char* name;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+ LVCOLUMN lvc={0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlsl",&res,&id,&name,&nl,&cx) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 6 || ct->cs1 > 5)goto Error;
+
+ lvc.cx = cx;
+ lvc.fmt = LVCFMT_CENTER;
+ lvc.pszText = name;
+ lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_FMT;
+
+ nl = ListView_InsertColumn(GetDlgItem(dlg->hDlg,id),ct->cs1,&lvc) != -1;
+ ct->cs1 += nl;
+ if(nl != -1){
+ RETURN_LONG(nl);
+ }
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgComboAddItem)
+{
+ unsigned long id;
+ unsigned long il;
+ unsigned long param = -1;
+ char* item;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls|l",&res,&id,&item,&il,&param) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 4)goto Error;
+
+ id = SendMessage(ct->hWnd,CB_ADDSTRING,NULL,(LPARAM)item);
+ if(id >= 0){
+ if(param != -1){
+ SendMessage(ct->hWnd,CB_SETITEMDATA,id,param);
+ }
+ RETURN_LONG(id);
+ }
+Error:
+ RETURN_NULL();
+}
+ZEND_FUNCTION(mb_DlgComboDelItem)
+{
+ unsigned long id;
+ unsigned long iid;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll",&res,&id,&iid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 4)goto Error;
+
+ RETURN_LONG(SendMessage(ct->hWnd,CB_DELETESTRING,iid,0)>=0);
+Error:
+ RETURN_NULL();
+}
+
+ZEND_FUNCTION(mb_DlgComboGetItem)
+{
+ unsigned long id;
+ unsigned long iid;
+ zval* res = 0;
+ char* str = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll",&res,&id,&iid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 4)goto Error;
+
+ id = SendMessage(ct->hWnd,CB_GETLBTEXTLEN,iid,0);
+ if(id < 0)goto Error;
+
+ str = (char*)emalloc(id + 1);
+ if(!str)goto Error;
+ str[id] = 0;
+
+ id = SendMessage(ct->hWnd,CB_GETLBTEXT,iid,(LPARAM)str);
+ if(id<=0){
+ efree(str);
+ goto Error;
+ }
+ RETURN_STRING(str,0);
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_DlgComboGetSel)
+{
+ unsigned long id;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl",&res,&id) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 4)goto Error;
+
+ id = SendMessage(ct->hWnd,CB_GETCURSEL,0,0);
+ if(id != CB_ERR){
+ RETURN_LONG(id);
+ }
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_DlgComboGetItemData)
+{
+ unsigned long id;
+ unsigned long iid;
+ zval* res = 0;
+ sDialog* dlg = NULL;
+ sDlgControl* ct;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll",&res,&id,&iid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || id < 1000 || (id > (dlg->lNum + 1000)))goto Error;
+
+ ct = dlg->table[id - 1000];
+ if(ct->type != 4)goto Error;
+
+ id = SendMessage(ct->hWnd,CB_GETITEMDATA,iid,0);
+ if(id == CB_ERR)goto Error;
+ RETURN_LONG(id);
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_DlgAddControl)
+{
+ extern HFONT hVerdanaFont;
+
+ zval* res = 0;
+ zval* cb = 0;
+ long type=0;
+ long param=0;
+ long style=0;
+ long x,y,cx,cy;
+ char* name;
+ long nl=0;
+ sDialog* dlg = NULL;
+ sDlgControl* ctrl = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlsllllz!|ll",&res,&type,&name,&nl,
+ &x,&y,&cx,&cy,&cb,&style,&param) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!res){
+ goto Error;
+ }
+
+ if(cb){
+ if(cb->type!=IS_STRING || !zend_is_callable(cb,0,NULL)){
+ goto Error;
+ }
+ }
+
+ ZEND_FETCH_RESOURCE(dlg,sDialog*,&res,-1,g_res_dlg_name,g_res_dlg_id);
+ if(!dlg || dlg->lNum >= DLG_NUM_CONTROLS)goto Error;
+
+ ctrl = (sDlgControl*)my_malloc(sizeof(sDlgControl));
+ if(!ctrl)goto Error;
+ memset(ctrl,0,sizeof(sDlgControl));
+
+ if(type != 1){
+ style |= WS_TABSTOP;
+ }
+
+ ctrl->hWnd = CreateWindow(DlgGetCtrlClass(type),name,(WS_CHILD|WS_VISIBLE|style),x,y,cx,cy,
+ dlg->hDlg,(HMENU)(1000 + dlg->lNum),hInst,NULL);
+
+ if(!ctrl->hWnd)goto Error;
+
+ if(type == 6){
+ ListView_SetExtendedListViewStyle(ctrl->hWnd,LVS_EX_FULLROWSELECT);
+ }
+
+ SendMessage(ctrl->hWnd,WM_SETFONT,(WPARAM)hVerdanaFont,0);
+
+ if(cb){
+ strncpy(ctrl->pszCallback,cb->value.str.val,sizeof(ctrl->pszCallback)-1);
+ }
+
+ ctrl->type = (char)(0xFF & type);
+ ctrl->param = param;
+ dlg->table[dlg->lNum] = ctrl;
+
+ RETURN_LONG(1000 + dlg->lNum++);
+Error:
+ if(ctrl){
+ my_memfree((void*)ctrl);
+ }
+ RETURN_FALSE;
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_event.cpp b/mBot/src/mbot/functions/mb_event.cpp
new file mode 100644
index 0000000..e7602b7
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_event.cpp
@@ -0,0 +1,202 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+/***********************************
+ * history
+ **********************************/
+ZEND_FUNCTION(mb_EventFindFirst)
+{
+ long cid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(CallService(MS_DB_EVENT_FINDFIRST,(WPARAM)cid,0));
+}
+ZEND_FUNCTION(mb_EventFindFirstUnread)
+{
+ long cid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(CallService(MS_DB_EVENT_FINDFIRSTUNREAD,(WPARAM)cid,0));
+}
+ZEND_FUNCTION(mb_EventFindLast)
+{
+ long cid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(CallService(MS_DB_EVENT_FINDLAST,(WPARAM)cid,0));
+}
+ZEND_FUNCTION(mb_EventFindNext)
+{
+ long hid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&hid) == FAILURE || !hid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(CallService(MS_DB_EVENT_FINDNEXT,(WPARAM)hid,0));
+}
+ZEND_FUNCTION(mb_EventFindPrev)
+{
+ long hid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&hid) == FAILURE || !hid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(CallService(MS_DB_EVENT_FINDPREV,(WPARAM)hid,0));
+}
+ZEND_FUNCTION(mb_EventGetCount)
+{
+ long cid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&cid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ cid = CallService(MS_DB_EVENT_GETCOUNT,(WPARAM)cid,0);
+ if(cid == -1){
+ RETURN_FALSE;
+ }else{
+ RETURN_LONG(cid);
+ }
+}
+ZEND_FUNCTION(mb_EventDel)
+{
+ long hid=0,cid=-1;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",&hid,&cid) == FAILURE || !hid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(cid == -1){
+ cid = CallService(MS_DB_EVENT_GETCONTACT,hid,0);
+ if(cid == -1){
+ RETURN_NULL();
+ }
+ }
+ RETURN_LONG(CallService(MS_DB_EVENT_DELETE,cid,hid)!=-1);
+}
+ZEND_FUNCTION(mb_EventAdd)
+{
+ DBEVENTINFO dbei = {sizeof(dbei),0};
+ char* proto=NULL,*body=NULL;
+ long hid=0,cid=0,pl=0,bl=0,type=EVENTTYPE_MESSAGE,ts=0;
+ long flags=DBEF_SENT;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls|lll",&proto,&pl,&cid,&body,&bl,&type,&flags,&ts) == FAILURE || !proto){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ flags &= ~(0x00000001);
+
+ dbei.cbBlob = bl + 1;
+ dbei.pBlob = (PBYTE)body;
+ dbei.eventType = (unsigned short)type;
+ dbei.timestamp = (ts)?(ts):(time(0));
+ dbei.szModule = proto;
+ dbei.flags = flags;
+
+ RETURN_LONG(CallService(MS_DB_EVENT_ADD,(WPARAM)cid,(LPARAM)&dbei));
+}
+ZEND_FUNCTION(mb_EventGetData)
+{
+ long hid=0;
+ unsigned long mbLen = 0;
+ char* buffer = NULL;
+ wchar_t *wbuff = NULL;
+ long req_buff = NULL;
+ zend_bool unicode = 0;
+
+ DBEVENTINFO dbei = {0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b",&hid,&unicode) == FAILURE || !hid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ req_buff = CallService(MS_DB_EVENT_GETBLOBSIZE,(WPARAM)hid,0);
+ if(req_buff < 0){
+ RETURN_FALSE;
+ }
+
+ buffer = (char*)emalloc(req_buff + 1);
+ if(!buffer){
+ RETURN_FALSE;
+ }
+ buffer[req_buff]='\0';
+
+ dbei.cbSize = sizeof(dbei);
+ dbei.cbBlob = req_buff;
+ dbei.pBlob = (PBYTE)buffer;
+
+ if(CallService(MS_DB_EVENT_GET, (WPARAM)hid, (LPARAM)&dbei)!=0){
+ efree(buffer);
+ RETURN_FALSE;
+ }
+
+ //module,type,timestamp,flags,value
+ if(array_init(return_value)==FAILURE){
+ efree(buffer);
+ RETURN_FALSE;
+ }
+
+ add_index_string(return_value, 0, dbei.szModule, 1);
+ add_index_long(return_value, 1, dbei.eventType);
+ add_index_long(return_value, 2, dbei.timestamp);
+ add_index_long(return_value, 3, dbei.flags);
+
+ mbLen = strlen(buffer);
+
+ if(unicode){
+ //add the ascii body
+ add_index_stringl(return_value, 4, buffer, mbLen, 1);
+ //if possible add the UNICODE body
+ if(((mbLen + 1) * 3) <= dbei.cbBlob){
+ add_index_stringl(return_value, 5, (buffer + mbLen + 1), mbLen * 2 , 1);
+ }else{//if not add empty string
+ wbuff = (wchar_t*)emalloc((mbLen + 1) * sizeof(wchar_t));
+ if(wbuff){
+ for(unsigned i=0;i<mbLen;i++){
+ wbuff[i] = buffer[i];
+ }
+ add_index_stringl(return_value, 5, (char*)wbuff, mbLen * 2 , 0);
+ }else{
+ add_index_null(return_value, 5);
+ }
+ }
+ }else{
+ add_index_stringl(return_value, 4, buffer, mbLen, 0);
+ }
+ return;
+}
+ZEND_FUNCTION(mb_EventMarkRead)
+{
+ long hid=0,cid=(-1);
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",&hid,&cid) == FAILURE || !hid){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(cid == (-1)){
+ cid = CallService(MS_DB_EVENT_GETCONTACT,hid,0);
+ }
+
+ if(cid == (-1)){
+ RETURN_FALSE;
+ }
+
+ RETURN_LONG(CallService(MS_DB_EVENT_MARKREAD,cid,hid)!=-1);
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_ft.cpp b/mBot/src/mbot/functions/mb_ft.cpp
new file mode 100644
index 0000000..736b345
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_ft.cpp
@@ -0,0 +1,260 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+ZEND_FUNCTION(mb_FileInitSend)
+{
+ char *desc=NULL,*file=NULL;
+ long dl=0,fl=0,cid=0,param=0;
+ zval* cb = NULL;
+ sACKSync* ack = NULL;
+ char *files[2]={0};
+
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsszl",&cid,&desc,&dl,&file,&fl,&cb,&param) == FAILURE || !cid || !dl || !fl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(!mbe->php){
+ PHPWSE("You can't use this function here!");
+ }else if(!zend_is_callable(cb,0,NULL)){
+ PHPWSE("$cb is expected to be a valid callback function!");
+ }
+
+ ack = (sACKSync*)my_malloc(sizeof(sACKSync));
+ if(!ack){RETURN_FALSE}
+ memset(ack,0,sizeof(sACKSync));
+
+ ack->lType = ACKTYPE_FILE;
+ ack->hContact = (HANDLE)cid;
+ ack->php = mbe->php;
+ ack->lParam = param;
+ strncpy(ack->pszFunction,cb->value.str.val,sizeof(ack->pszFunction)-1);
+
+ files[0] = file;
+ ack->hProcess = (HANDLE)CallContactService((HANDLE)cid,PSS_FILE,(WPARAM)desc,(LPARAM)files);
+ if(!ack->hProcess)goto Error;
+ g_slist.Add(ack);
+
+ RETURN_LONG((long)ack);
+Error:
+ free(ack);
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_FileGetInfo)
+{
+ long fth;
+ sACKSync* as;
+ sFileInfo* fi;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",&fth) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!fth){
+ goto Error;
+ }
+
+ try{
+ g_slist.Lock();
+ as = (sACKSync*)g_slist.m_head;
+ while(as)
+ {
+ if((long)as == fth)
+ {
+ fi = (sFileInfo*)as->pszProtocol;
+ if(array_init(return_value)==FAILURE){
+ as = NULL;
+ break;
+ }
+ //array($num_files,$cur_file,$tot_bytes,$tot_sent,$cur_size,$cur_sent,$cur_time);
+ add_index_long(return_value,0,fi->numFiles);
+ add_index_long(return_value,1,fi->curFile);
+ add_index_long(return_value,2,fi->bytesTotal);
+ add_index_long(return_value,3,fi->bytesDone);
+ add_index_long(return_value,4,fi->curSize);
+ add_index_long(return_value,5,fi->curDone);
+ add_index_long(return_value,6,fi->curTime);
+ break;
+ }
+ as = (sACKSync*)as->next;
+ }
+ }catch(...){
+ as = NULL;
+ }
+
+ g_slist.Unlock();
+
+ if(as){
+ return;
+ }
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_FileCancel)
+{
+ long fth,hp;
+ sACKSync* as;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&fth) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!fth){
+ goto Error;
+ }
+
+ try{
+ g_slist.Lock();
+ as = (sACKSync*)g_slist.m_head;
+ while(as){
+ if((long)as == fth){
+ hp = (long)as->hProcess;
+ break;
+ }
+ as = (sACKSync*)as->next;
+ }
+ }catch(...){
+ as = NULL;
+ }
+
+ g_slist.Unlock();
+
+
+ if(as){
+ CallContactService((HANDLE)as->hContact,PSS_FILECANCEL,(WPARAM)hp,0);
+ RETURN_TRUE;
+ }
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_FileDeny)
+{
+ char *desc=NULL;
+ long fid=0,dl=0,cid=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lls",&cid,&fid,&desc,&dl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ if(!fid || !cid){
+ RETURN_FALSE;
+ }
+ RETURN_LONG(CallContactService((HANDLE)cid,PSS_FILEDENY,(WPARAM)fid,(LPARAM)desc));
+}
+
+ZEND_FUNCTION(mb_FileAccept)
+{
+ char *dst=NULL;
+ long dl;
+ long cid;
+ long fth;
+ long param=0;
+ char resume=0;
+ zval* cb;
+ sACKSync* ack = NULL;
+ PROTOFILERESUME pfr;
+
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llsz|cl",&fth,&cid,&dst,&dl,&cb,&resume,&param) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(!mbe->php){
+ PHPWSE("You can't use this function here!");
+ }else if(!zend_is_callable(cb,0,NULL)){
+ PHPWSE("$cb is expected to be a valid callback function!");
+ }
+
+ if(!fth){RETURN_FALSE}
+
+ ack = (sACKSync*)my_malloc(sizeof(sACKSync));
+ if(!ack){RETURN_FALSE}
+ memset(ack,0,sizeof(sACKSync));
+
+ ack->lType = ACKTYPE_FILE;
+ ack->hContact = (HANDLE)cid;
+ ack->php = mbe->php;
+ ack->lParam = param;
+ strncpy(ack->pszFunction,cb->value.str.val,sizeof(ack->pszFunction)-1);
+
+ try{
+ if(resume == 0){
+ ack->hProcess = (HANDLE)CallContactService((HANDLE)cid,PSS_FILEALLOW,(WPARAM)fth,(LPARAM)dst);
+ }else{
+ pfr.action = resume;
+ pfr.szFilename = dst;
+ ack->hProcess = (HANDLE)CallContactService((HANDLE)cid,PS_FILERESUME,(WPARAM)fth,(LPARAM)&pfr);
+ }
+ }catch(...){
+ ack->hProcess = NULL;
+ }
+
+ if(ack->hProcess){
+ g_slist.Add(ack);
+ RETURN_LONG((long)ack);
+ }
+
+ if(ack)my_memfree(ack);
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_FileStore)
+{
+ CCSDATA* css;
+ PROTORECVEVENT* prr;
+ long result = 0;
+ char* proto=NULL;
+ char* szDesc=NULL;
+ char* szFile=NULL;
+ DBEVENTINFO dbei={0};
+
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+ css = (CCSDATA*)mbe->lParam;
+
+ if(mbe->event != MBT_FILEIN || !css || !css->lParam){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(mbe->lFlags & MBOT_FLAG_STORED){
+ RETURN_FALSE;
+ }
+
+
+ prr = (PROTORECVEVENT*)css->lParam;
+ proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)css->hContact,0);
+
+ szFile = prr->szMessage + sizeof(DWORD);
+ szDesc = szFile + strlen(szFile) + 1;
+
+ dbei.cbSize = sizeof(dbei);
+ dbei.cbBlob = sizeof(DWORD) + strlen(szFile) + strlen(szDesc) + 2;
+ dbei.pBlob = (PBYTE)prr->szMessage;
+ dbei.eventType = (unsigned short)EVENTTYPE_FILE;
+ dbei.timestamp = time(0);
+ dbei.szModule = proto;
+ dbei.flags = DBEF_READ;
+
+ result = CallService(MS_DB_EVENT_ADD,(WPARAM)css->hContact,(LPARAM)&dbei);
+ if(result){
+ mbe->lFlags |= MBOT_FLAG_STORED;
+ }
+
+ RETURN_LONG(*((long*)dbei.pBlob));
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_icons.cpp b/mBot/src/mbot/functions/mb_icons.cpp
new file mode 100644
index 0000000..a5bbf55
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_icons.cpp
@@ -0,0 +1,79 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+///////////////////////////////
+//icons
+///////////////////////////////
+const static char* mb_lsi_def_icons[]={0,IDI_APPLICATION,IDI_ASTERISK,
+ IDI_ERROR,IDI_EXCLAMATION,IDI_HAND,IDI_INFORMATION,IDI_QUESTION,IDI_WARNING,IDI_WINLOGO,0};
+
+ZEND_FUNCTION(mb_IconLoadSys)
+{
+ HANDLE hIcon = NULL;
+ long iid=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&iid) == FAILURE || iid<1 || iid>9){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG((long)LoadIcon(NULL,mb_lsi_def_icons[iid]));
+}
+ZEND_FUNCTION(mb_IconLoadSkin)
+{
+ long iid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&iid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG((long)LoadSkinnedIcon((int)iid));
+}
+ZEND_FUNCTION(mb_IconLoadSkinnedProto)
+{
+ char* proto=NULL;
+ long iid=0,pl=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",&proto,&pl,&iid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG((long)LoadSkinnedProtoIcon((const char*)(*proto)?(proto):(NULL),(int)iid));
+}
+ZEND_FUNCTION(mb_IconLoadProto)
+{
+ char* proto=NULL;
+ long iid=0,pl=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",&proto,&pl,&iid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ //
+ RETURN_LONG((long)CallProtoService((const char*)proto,PS_LOADICON,(int)iid | PLIF_SMALL,0));
+}
+
+ZEND_FUNCTION(mb_IconDestroy)
+{
+ long iid=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&iid) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ try{
+ DestroyIcon((HICON)iid);
+ }catch(...){
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_irc.cpp b/mBot/src/mbot/functions/mb_irc.cpp
new file mode 100644
index 0000000..6b6ea43
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_irc.cpp
@@ -0,0 +1,357 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+ZEND_FUNCTION(mb_IrcGetGuiDataIn)
+{
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+ if(mbe->event == MBT_IRC_IN)
+ {
+ GCEVENT* gce = (GCEVENT*)mbe->p4;
+ if(array_init(return_value)==FAILURE)RETURN_FALSE;
+ add_index_long(return_value,0,gce->pDest->iType);
+ if(gce->pDest->pszID){add_index_string(return_value,1,(char*)gce->pDest->pszID,1);}else{add_index_unset(return_value,1);}
+ if(gce->pszText){add_index_string(return_value,2,(char*)gce->pszText,1);}else{add_index_unset(return_value,2);}
+ if(gce->pszNick){add_index_string(return_value,3,(char*)gce->pszNick,1);}else{add_index_unset(return_value,3);}
+ if(gce->pszUID){add_index_string(return_value,4,(char*)gce->pszUID,1);}else{add_index_unset(return_value,4);}
+ if(gce->pszStatus){add_index_string(return_value,5,(char*)gce->pszStatus,1);}else{add_index_unset(return_value,5);}
+ if(gce->pszUserInfo){add_index_string(return_value,6,(char*)gce->pszUserInfo,1);}else{add_index_unset(return_value,6);}
+ add_index_long(return_value,7,gce->bIsMe);
+ add_index_long(return_value,8,(gce->dwFlags & GCEF_ADDTOLOG) != 0);
+ add_index_long(return_value,9,gce->time);
+ add_index_long(return_value,10,((WPARAM_GUI_IN*)mbe->wParam)->wParam);
+ return;
+ }
+ else
+ {
+ PHPWSE("You cannot call this function here!");
+ }
+}
+
+void help_strrealloc(zval* v,const char** out)
+{
+ if(v){
+ mmi.mmi_free((void*)*out);
+ if((v->type == IS_BOOL && !v->value.lval) || (v->type == IS_LONG && !v->value.lval)){
+ *out = NULL;
+ }else{
+ convert_to_string(v);
+ *out = (const char*)mmi.mmi_malloc(v->value.str.len+1);
+ memcpy((void*)*out,v->value.str.val,v->value.str.len+1);
+ }
+ }
+}
+
+ZEND_FUNCTION(mb_IrcSetGuiDataIn)
+{
+ zval* itype = NULL;
+ zval* pszID = NULL;
+ zval* pszText = NULL;
+ zval* pszNick = NULL;
+ zval* pszUID = NULL;
+ zval* pszStatus = NULL;
+ zval* pszUserInfo = NULL;
+ zval* bIsMe = NULL;
+ zval* bAddToLog = NULL;
+ zval* timestamp = NULL;
+ long wParam = 0xfaaaffaa;
+
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(mbe->event != MBT_IRC_IN){
+ PHPWSE("You cannot call this function here!");
+ }
+ //mb_IrcSetGuiDataIn($iType,$pszID,$pszText,$pszNick,$pszUID,$pszStatus,$pszUserInfo,$bIsMe,$bAddToLog,$timestamp,$wParam);
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|z!z!z!z!z!z!z!z!z!l",
+ &itype,&pszID,&pszText,&pszNick,&pszUID,&pszStatus,&pszUserInfo,&bIsMe,&bAddToLog,&timestamp,&wParam) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ GCEVENT* gce = (GCEVENT*)mbe->p4;
+ if(itype && itype->type == IS_LONG){
+ gce->pDest->iType = itype->value.lval;
+ }
+
+ try{
+ help_strrealloc(pszID,(const char**)&gce->pDest->pszID);
+ help_strrealloc(pszText,&gce->pszText);
+ help_strrealloc(pszNick,&gce->pszNick);
+ help_strrealloc(pszUID,&gce->pszUID);
+ help_strrealloc(pszStatus,&gce->pszStatus);
+ help_strrealloc(pszUserInfo,&gce->pszUserInfo);
+ help_strrealloc(pszNick,&gce->pszNick);
+ }catch(...){
+ PHPWSE("Oops... some data might have got corrupted!");
+ }
+
+ if(bIsMe && bIsMe->type == IS_LONG){
+ gce->bIsMe = bIsMe->value.lval;
+ }
+ if(bAddToLog && bAddToLog->type == IS_LONG){
+ gce->dwFlags = (bAddToLog->value.lval)?GCEF_ADDTOLOG:0;
+ }
+ if(timestamp && timestamp->type == IS_LONG){
+ gce->time = timestamp->value.lval;
+ }
+ if(wParam != 0xfaaaffaa){
+ ((WPARAM_GUI_IN*)mbe->wParam)->wParam = wParam;
+ }
+ RETURN_TRUE;
+}
+
+ZEND_FUNCTION(mb_IrcSetGuiDataOut)
+{
+ //$iType,$pszID,$pszUID,$text
+ zval* itype;
+ zval* pszID;
+ zval* pszUID;
+ zval* text;
+
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(mbe->event != MBT_IRC_OUT){
+ PHPWSE("You cannot call this function here!");
+ }
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|z!z!z!",&itype,&pszID,&pszUID,&text) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ GCHOOK* gch = (GCHOOK*)mbe->p4;
+
+ if(itype && itype->type == IS_LONG){
+ gch->pDest->iType = itype->value.lval;
+ }
+
+ try{
+ help_strrealloc(text,(const char**)&gch->pszText);
+ help_strrealloc(pszUID,(const char**)&gch->pszUID);
+ help_strrealloc(pszID,(const char**)&gch->pDest->pszID);
+ }catch(...){
+ PHPWSE("Oops... some data might have got corrupted!");
+ }
+ RETURN_TRUE;
+}
+ZEND_FUNCTION(mb_IrcInsertRawIn)
+{
+ char msg[256];
+ char raw[530];
+ char* module,*body;
+ long ml,bl;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",&module,&ml,&body,&bl) == FAILURE || !*module){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(bl > 512){
+ PHPWSE("You must not provide more than 512 bytes including CRLF for this function!");
+ }
+
+ memcpy(raw,body,bl);
+ raw[bl]=0;
+
+ _snprintf(msg,sizeof(msg)-1,"%s/InsertRawIn",module);
+ RETURN_LONG(CallService(msg,NULL,(LPARAM)raw));
+}
+ZEND_FUNCTION(mb_IrcInsertRawOut)
+{
+ char msg[256];
+ char raw[530];
+ char* module,*body;
+ long ml,bl;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",&module,&ml,&body,&bl) == FAILURE || !*module){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }else if(bl > 512){
+ PHPWSE("You must not provide more than 512 bytes including CRLF for this function!");
+ }
+
+ memcpy(raw,body,bl);
+ if(raw[bl-2]!='\r'){
+ if(raw[bl-1]=='\n'){
+ raw[bl-1]='\r';
+ raw[bl]='\n';
+ raw[bl+1]=0;
+ }else{
+ raw[bl]='\r';
+ raw[bl+1]='\n';
+ raw[bl+2]=0;
+ }
+ }else{
+ raw[bl]=0;
+ }
+
+ _snprintf(msg,sizeof(msg)-1,"%s/InsertRawOut",module);
+ RETURN_LONG(CallService(msg,NULL,(LPARAM)raw));
+}
+ZEND_FUNCTION(mb_IrcInsertGuiIn)
+{
+ char* module;
+ long ml;
+ long itype = NULL;
+ zval* pszID = NULL;
+ zval* pszText = NULL;
+ zval* pszNick = NULL;
+ zval* pszUID = NULL;
+ zval* pszStatus = NULL;
+ zval* pszUserInfo = NULL;
+ char bIsMe = 0;
+ char bAddToLog = 0;
+ long timestamp = 0;
+ long wParam = 0;
+
+ char msg[256];
+ GCEVENT gce = {0};
+ GCDEST gcd = {0};
+ WPARAM_GUI_IN wpi = {0};
+
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ //mb_IrcInsertGuiIn($module,$iType,$pszID,$pszText,$pszNick,$pszUID,$pszStatus,$pszUserInfo,$bIsMe,$bAddToLog,$timestamp,$wParam);
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz!|z!z!z!z!z!bbll",&module,&ml,&itype,&pszID,
+ &pszText,&pszNick,&pszUID,&pszStatus,&pszUserInfo,&bIsMe,&bAddToLog,&timestamp,&wParam) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ gce.pDest = &gcd;
+ gcd.iType = itype;
+ gcd.pszModule = module;
+ if(pszID){
+ convert_to_string(pszID);
+ gcd.pszID = pszID->value.str.val;
+ }
+ gce.cbSize = sizeof(gce);
+ gce.dwItemData = 0x80000000;
+ gce.time = (timestamp)?timestamp:time(0);
+ gce.bIsMe = bIsMe;
+ gce.dwFlags = (bAddToLog)?GCEF_ADDTOLOG:0;
+
+ if(pszUID){
+ convert_to_string(pszUID);
+ gce.pszUID = pszUID->value.str.val;
+ }
+ if(pszText){
+ convert_to_string(pszText);
+ gce.pszText = pszText->value.str.val;
+ }
+ if(pszNick){
+ convert_to_string(pszNick);
+ gce.pszNick = pszNick->value.str.val;
+ }
+ if(pszStatus){
+ convert_to_string(pszStatus);
+ gce.pszStatus = pszStatus->value.str.val;
+ }
+ if(pszUserInfo){
+ convert_to_string(pszUserInfo);
+ gce.pszUserInfo = pszUserInfo->value.str.val;
+ }
+ wpi.wParam = wParam;
+ wpi.pszModule = module;
+
+ _snprintf(msg,sizeof(msg)-1,"%s/InsertGuiIn",module);
+ RETURN_LONG(CallService(msg,(WPARAM)&wpi,(LPARAM)&gce));
+}
+
+ZEND_FUNCTION(mb_IrcInsertGuiOut)
+{
+ //?> mb_IrcInsertGuiOut('IRC',0x0080,'#miranda',NULL,NULL);
+ char* module;
+ long iType = 0;
+ long ml = 0;
+ zval* pszText = NULL;
+ zval* pszUID = NULL;
+ zval* pszID = NULL;
+
+ char msg[256];
+ GCHOOK gch = {0};
+ GCDEST gcd = {0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz!|z!z!",&module,&ml,&iType,&pszID,&pszUID,&pszText) == FAILURE || !*module){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+
+ gch.pDest = &gcd;
+ gcd.iType = iType;
+ gcd.pszModule = module;
+ gch.dwData = 0x80000000;
+ if(pszID){
+ convert_to_string(pszID);
+ gch.pDest->pszID = pszID->value.str.val;
+ }
+ if(pszUID){
+ convert_to_string(pszUID);
+ gch.pszUID = pszUID->value.str.val;
+ }
+ if(pszText){
+ convert_to_string(pszText);
+ gch.pszText = pszText->value.str.val;
+ }
+ _snprintf(msg,sizeof(msg)-1,"%s/InsertGuiOut",module);
+ RETURN_LONG(CallService(msg,(WPARAM)module,(LPARAM)&gch));
+}
+
+ZEND_FUNCTION(mb_IrcGetData)
+{
+ char* module;
+ char* setting;
+ char* channel = 0;
+ long ml,sl,cl;
+ char msg[256];
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s",&module,&ml,&setting,&sl,&channel,&cl) == FAILURE || !*module){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ _snprintf(msg,sizeof(msg)-1,"%s/GetIrcData",module);
+ setting = (char*)CallService(msg,(WPARAM)channel,(LPARAM)setting);
+ if(setting){
+ try{
+ RETVAL_STRING(setting,1);
+ mmi.mmi_free(setting);
+ return;
+ }catch(...){
+ RETURN_FALSE;
+ }
+ }else{
+ RETURN_FALSE;
+ }
+}
+ZEND_FUNCTION(mb_IrcPostMessage)
+{
+ char* module;
+ char* text;
+ long ml,tl;
+
+ char msg[256];
+ GCHOOK gch = {0};
+ GCDEST gcd = {0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",&module,&ml,&text,&tl) == FAILURE || !*module){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ gch.pDest = &gcd;
+ gcd.iType = 1;
+ gcd.pszModule = module;
+ gcd.pszID = "Network Log";
+ gch.dwData = 0x80000000;
+ gch.pszText = text;
+ _snprintf(msg,sizeof(msg)-1,"%s/InsertGuiOut",module);
+ RETURN_LONG(CallService(msg,(WPARAM)module,(LPARAM)&gch));
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_menu.cpp b/mBot/src/mbot/functions/mb_menu.cpp
new file mode 100644
index 0000000..0942081
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_menu.cpp
@@ -0,0 +1,167 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+ZEND_FUNCTION(mb_MenuAdd)
+{
+ zval* cb = NULL;
+ zval* pb = NULL;
+ char* name = NULL;
+ char* proto = NULL;
+ char fname[24];
+ char root = 0;
+ void* temp = NULL;
+ long nl = 0;
+ long pl = 0;
+ long param = 0;
+ long icon = 0;
+ long flags = 0;
+ long position = 0x7ffffff;
+ char cm = 0;
+ CLISTMENUITEM mi={0};
+ sMFSync* mfs;
+
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz|llbslz!b",&name,&nl,&param,&cb,&icon,
+ &flags,&cm,&proto,&pl,&position,&pb,&root)==FAILURE
+ || !nl || cb->type != IS_STRING){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(pb && (!cm || !zend_is_callable(pb,0,NULL))){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(mbe->event == MBT_AUTOLOAD){
+ mbe->php = sman_getbyfile((const char*)mbe->p3);
+ }
+ if(!mbe->php){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ mfs = (sMFSync*)my_malloc(sizeof(sMFSync));
+ if(!mfs){RETURN_FALSE;}
+ memset(mfs,0,sizeof(sMFSync));
+
+ mfs->php = mbe->php;
+
+ strncpy(mfs->pszFunction,cb->value.str.val,sizeof(mfs->pszFunction));
+ _snprintf(fname,sizeof(fname),"MBot/Menu/%.8x",mfs);
+
+ temp = help_makefunct(mfs,(void*)help_callmenu);
+ if(!temp){
+ goto Error;
+ }
+ if(!CreateServiceFunction(fname,(MIRANDASERVICE)temp)){
+ goto Error;
+ }
+ mi.cbSize = sizeof(mi);
+ mi.position = position;
+ mi.hIcon = (icon)?((HICON)icon):(hMBotIcon);
+ mi.pszName = name;
+ mi.pszService = fname;
+ mi.flags = flags;
+
+ if(cm){
+ if(pl){
+ mi.pszContactOwner = proto;
+ }
+ if(pb){
+ strncpy(mfs->pszPrebuild,pb->value.str.val,sizeof(mfs->pszPrebuild));
+ lm_flags |= MBOT_FLAG_WANTPREBUILD;
+ }
+ }else{
+ mi.pszPopupName = (!root)?"MBot":NULL;
+ }
+
+ mfs->hMenu = CallService((cm)?(MS_CLIST_ADDCONTACTMENUITEM):(MS_CLIST_ADDMAINMENUITEM),0,(LPARAM)&mi);
+ if(mfs->hMenu==NULL){
+ DestroyServiceFunction(fname);
+ goto Error;
+ }
+ g_mlist.Add(mfs);
+ RETURN_LONG(mfs->hMenu);
+Error:
+ if(mbe->php){sman_decref(mbe->php);}
+ my_memfree(mfs);
+ if(temp){my_memfree(temp);}
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_MenuModify)
+{
+ long mid = 0;
+ long flags = 0xffffffff;
+ char* name = 0;
+ long nl = 0;
+ long ico = 0;
+ zval* cb = NULL;
+ CLISTMENUITEM mi = {0};
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|sllz",&mid,&name,&nl,&ico,&flags,&cb)==FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!mid){
+ RETURN_NULL();
+ }
+
+ if(cb)
+ {
+ sMFSync* mfs;
+ if(!zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_ERRORS("$cb is expected to be a valid callback function!");
+ }
+
+ g_mlist.Lock();
+ mfs = (sMFSync*)g_mlist.m_head;
+ while(mfs)
+ {
+ if(mfs->hMenu == mid){
+ strncpy(mfs->pszFunction,cb->value.str.val,sizeof(mfs->pszFunction)-1);
+ break;
+ }
+ mfs = (sMFSync*)mfs->next;
+ }
+ g_mlist.Unlock();
+ }
+
+ mi.cbSize = sizeof(mi);
+
+ if(ico){
+ mi.hIcon = (HICON)ico;
+ mi.flags |= CMIM_ICON;
+ }
+ if(nl){
+ mi.pszName = name;
+ mi.flags |= CMIM_NAME;
+ }
+ if(flags != 0xffffffff){
+ mi.flags |= flags | CMIM_FLAGS;
+ }
+
+ RETURN_LONG(CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)mid,(LPARAM)&mi));
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_misc.cpp b/mBot/src/mbot/functions/mb_misc.cpp
new file mode 100644
index 0000000..de689ce
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_misc.cpp
@@ -0,0 +1,185 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+#include "../window.h"
+
+int CtrlACPI(HANDLE hATKACPI,int code, int hasArg, int arg)
+{
+ unsigned long bytes = 0;
+ long inbuf[5];
+ struct cmbuf {
+ short cmds[2];
+ long cm2;
+ } cbuf;
+ long outbuf[192];
+ int ret;
+
+ cbuf.cmds[0] = 0;
+ cbuf.cmds[1] = 4;
+ cbuf.cm2 = arg;
+ inbuf[0] = 2;
+ inbuf[1] = code;
+ inbuf[2] = hasArg;
+ inbuf[3] = 8 * hasArg;
+ inbuf[4] = (long)&cbuf;
+
+ ret = DeviceIoControl(hATKACPI, 0x222404, inbuf, sizeof(inbuf),
+ outbuf, sizeof(outbuf), &bytes, NULL);
+ return ret;
+}
+
+ZEND_FUNCTION(mb_AsusExt)
+{
+ int code,arg,harg;
+ HANDLE hATKACPI;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll",&code,&harg,&arg) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ hATKACPI = CreateFile("\\\\.\\ATKACPI",GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,0, NULL);
+
+ if(!hATKACPI){
+ PHPWSE("This computer does not support this extension!");
+ }
+
+ code = CtrlACPI(hATKACPI,code,harg,arg);
+ CloseHandle(hATKACPI);
+ RETURN_LONG(code);
+}
+
+ZEND_FUNCTION(mb_ConsoleShow)
+{
+ extern long lConTopMost;
+ zend_bool show = 1;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",&show) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(hDialog){
+ ShowWindow(hDialog,(show)?(SW_SHOW):(SW_HIDE));
+ if(show){
+ SetWindowPos(hDialog,lConTopMost?HWND_TOPMOST:0,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
+ }
+ }
+}
+
+ZEND_FUNCTION(mb_ConsoleClear)
+{
+ if(hConsole){
+ MBotConsoleClear();
+ }
+}
+
+void __stdcall mbb_echo(void* txt)
+{
+ MBotConsoleAppendText(((char*)txt)+1,*((char*)txt));
+ my_memfree((void*)txt);
+}
+
+ZEND_FUNCTION(mb_Echo)
+{
+ char* txt=NULL;
+ char* tmp=NULL;
+ long tl=0;
+ zend_bool rtf = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",&txt,&tl,&rtf) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ tmp = (char*)my_malloc(tl + 2);
+ if(tmp){
+ memcpy(tmp+1,txt,tl+1);
+ *tmp = rtf;
+ if(CallFunctionAsync(mbb_echo,tmp)==FALSE){
+ my_memfree(tmp);
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+ }else{
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_MsgBox)
+{
+ char* body=NULL;
+ char* caption=NULL;
+ long bl=0,cl=0,type=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sl",&body,&bl,&caption,&cl,&type) == FAILURE || !bl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(MessageBox(NULL,body,(cl)?(caption):(NULL),type | MB_TOPMOST));
+}
+
+ZEND_FUNCTION(mb_CListEventAdd)
+{
+ long cid = 0;
+ long ico = 0;
+ zval *cb = NULL;
+ char *info = NULL;
+ long il = 0;
+ long param = 0;
+ CLISTEVENT cle = {0};
+ sCLESync* mfs;
+
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsz|ll",&cid,&info,&il,&cb,&param,&ico)==FAILURE || cb->type != IS_STRING){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ mfs = (sCLESync*)my_malloc(sizeof(sCLESync));
+ if(!mfs){
+ RETURN_FALSE;
+ }
+ memset(mfs,0,sizeof(sCLESync));
+
+ if(!mbe->php){goto Error;}
+ mfs->php = mbe->php;
+
+ mfs->pParam = (void*)param;
+ strncpy(mfs->pszFunction,cb->value.str.val,sizeof(mfs->pszFunction));
+
+ cle.cbSize = sizeof(cle);
+ cle.hIcon = (ico)?((HICON)ico):hMBotIcon;
+ cle.pszTooltip = info;
+ cle.hContact = (HANDLE)cid;
+ cle.pszService = MS_MBOT_CLISTEVENT;
+ cle.hDbEvent = (HANDLE)mfs;
+ cle.lParam = (LPARAM)mfs;
+
+ CallService(MS_CLIST_ADDEVENT,0,(LPARAM)&cle);
+ RETURN_TRUE;
+Error:
+ if(mfs){
+ my_memfree(mfs);
+ }
+ RETURN_FALSE;
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_msg.cpp b/mBot/src/mbot/functions/mb_msg.cpp
new file mode 100644
index 0000000..8acffcf
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_msg.cpp
@@ -0,0 +1,152 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+ZEND_FUNCTION(mb_MsgSetBody)
+{
+ char* body = NULL;
+ char* tmp;
+ long bl = 0;
+ sPHPENV* ctx = (sPHPENV*)SG(server_context);
+ mb_event* mbe = (mb_event*)(ctx->c_param);
+
+ if((mbe->event!=MBT_PRERECV && mbe->event!=MBT_SEND && mbe->event != MBT_COMMAND && mbe->event != MBT_IRC_RAW) ||
+ zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&body,&bl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(mbe->event == MBT_IRC_RAW)
+ {
+ mmi.mmi_free(*((char**)mbe->p4));
+ if(mbe->p3 == NULL && (bl < 2 || body[bl-2]!='\r'))bl += 2;
+
+ tmp = (char*)mmi.mmi_malloc(bl + 1);
+
+ *((char**)mbe->p4) = tmp;
+
+ if(tmp){
+ memcpy(tmp,body,bl);
+ if(mbe->p3 == NULL){
+ *(short*)&tmp[bl-2]='\n\r';
+ }
+ tmp[bl]=0;
+ RETURN_LONG(1);
+ }else{
+ RETURN_FALSE;
+ }
+ }
+ else if(mbe->t1 = MBE_SSTRING)
+ {
+ string* cs = (string*)mbe->p1;
+ *cs = body;
+ mbe->lFlags |= MBOT_FLAG_BODY_CHANGED;
+ }
+
+ RETURN_LONG(1);
+}
+
+ZEND_FUNCTION(mb_MsgSend)
+{
+ char* body = NULL,*proto = NULL;
+ long bl = 0,cid = 0,hp = 0,result = 0,param = 0;
+ zval* cb = NULL;
+ zend_bool log = 0;
+ zend_bool unicode = 0;
+ sACKSync* ack = NULL;
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|bz!lb",&cid,&body,&bl,&log,&cb,&param,&unicode) == FAILURE
+ || cid==NULL || bl==0){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(cb && !zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_ERRORS("$cb is expected to be a valid callback function!");
+ }
+
+ proto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)cid,0);
+ if(!proto)
+ {
+ RETURN_FALSE;
+ }
+
+ if(cb)
+ {
+ ack = (sACKSync*)my_malloc(sizeof(sACKSync));
+ if(!ack){RETURN_FALSE}
+
+ memset(ack,0,sizeof(sACKSync));
+
+ if(!(ack->php = mbe->php)){
+ goto Error;
+ }
+
+ ack->lType = ACKTYPE_MESSAGE;
+ ack->hContact = (HANDLE)cid;
+ ack->lParam = param;
+
+ strncpy(ack->pszFunction,cb->value.str.val,sizeof(ack->pszFunction)-1);
+ strncpy(ack->pszProtocol,proto,15);
+
+ if(!g_slist.Add(ack)){
+ goto Error;
+ }
+
+ ack->hProcess = (HANDLE)CallContactService((HANDLE)cid,(unicode)?(PSS_MESSAGE "W"):(PSS_MESSAGE),(WPARAM)0x800000,(LPARAM)body);
+ if(!ack->hProcess || ack->hProcess == (HANDLE)(-1))
+ {
+ g_slist.Del(ack);
+ goto Error;
+ }
+ }
+ else
+ {
+ if(!CallContactService((HANDLE)cid,(unicode)?(PSS_MESSAGE "W"):(PSS_MESSAGE),(WPARAM)0x800000,(LPARAM)body))
+ {
+ goto Error;
+ }
+ }
+
+ if(log)
+ {
+ DBEVENTINFO dbei = {sizeof(dbei),0};
+ dbei.cbBlob = bl + 1;
+ dbei.pBlob = (PBYTE)body;
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.timestamp = time(0);
+ dbei.szModule = proto;
+ dbei.flags = DBEF_SENT;
+ bl = CallService(MS_DB_EVENT_ADD,(WPARAM)cid,(LPARAM)&dbei);
+
+ if(ack && !param){
+ ack->lParam = bl;
+ }
+ }else{
+ bl = 1;
+ }
+
+ RETURN_LONG(bl);
+Error:
+ if(ack){
+ my_memfree(ack);
+ }
+ RETURN_FALSE;
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_proto.cpp b/mBot/src/mbot/functions/mb_proto.cpp
new file mode 100644
index 0000000..50a8b5f
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_proto.cpp
@@ -0,0 +1,80 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+//protocols
+ZEND_FUNCTION(mb_PGetMyStatus)
+{
+ char* proto=NULL;
+ long pl=0;
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&proto,&pl) == FAILURE || !pl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ pl = CallProtoService(proto,PS_GETSTATUS,0,0);
+ RETURN_LONG(pl);
+}
+
+ZEND_FUNCTION(mb_PSetMyStatus)
+{
+ long status=0,pl=0;
+ char* proto=NULL;
+
+ sPHPENV* ctx = (sPHPENV*)SG(server_context);
+ mb_event* mbe = (mb_event*)(ctx->c_param);
+ if(mbe->event == MBT_NEWMYSTATUS){
+ RETURN_FALSE;
+ }
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",&proto,&pl,&status) == FAILURE || !status || !proto){
+ PHP_FALSE_AND_ERROR;
+ }
+ RETURN_LONG(CallProtoService(proto,PS_SETSTATUS,status,0)==0);
+}
+ZEND_FUNCTION(mb_PSetMyAwayMsg)
+{
+ long ml=0,pl=0,status=0;
+ char* proto=NULL,*msg=NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l",&proto,&pl,&msg,&ml,&status) == FAILURE || !proto || !pl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!status){
+ status = CallProtoService(proto,PS_GETSTATUS,0,0);
+ }
+ RETVAL_LONG(CallProtoService(proto,PS_SETAWAYMSG,status,(ml)?((LPARAM)msg):(NULL))==0);
+ return;
+}
+
+ZEND_FUNCTION(mb_PGetCaps)
+{
+ long pl=0;
+ long flag=0;
+ char* proto=NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",&proto,&pl,&flag) == FAILURE || !pl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ RETVAL_LONG(CallProtoService(proto,PS_GETCAPS,flag,0));
+ return;
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_pu.cpp b/mBot/src/mbot/functions/mb_pu.cpp
new file mode 100644
index 0000000..3cafe34
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_pu.cpp
@@ -0,0 +1,198 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+/******************************************
+ * popups *
+ ******************************************/
+
+void MB_Popup(const char* title,const char* error,unsigned long flags,unsigned long timeout)
+{
+ MIRANDASYSTRAYNOTIFY mbp={0};
+ mbp.cbSize = sizeof(MIRANDASYSTRAYNOTIFY);
+ mbp.szProto = "MBot";
+ mbp.szInfoTitle = (char*)title;
+ mbp.szInfo = (char*)error;
+ mbp.dwInfoFlags = flags;
+ mbp.uTimeout = timeout;
+
+ if(flags == NIIF_ERROR && (DBGetContactSettingByte(NULL,MBOT,"SWOnError",0))){
+ ShowWindow(hDialog,SW_SHOW);
+ SetWindowPos(hDialog,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
+ }
+
+ CallService(MS_CLIST_SYSTRAY_NOTIFY, (WPARAM)NULL,(LPARAM) &mbp);
+}
+
+void WINAPI MBotPUHelperThread(void* a)
+{
+ POPUPDATAEX* pde = (POPUPDATAEX*)a;
+
+ if(pde)
+ {
+ try{
+ PUAddPopUpEx(pde);
+ }catch(...){
+ pde->lchIcon = NULL;
+ }
+ my_memfree(pde);
+ }
+}
+
+ZEND_FUNCTION(mb_PUMsg)
+{
+ char* txt=NULL;
+ long tl=0,type=0;
+ POPUPDATAEX *pd;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",&txt,&tl,&type) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!(pd = (POPUPDATAEX*)my_malloc(sizeof(POPUPDATAEX)))){
+ RETURN_FALSE;
+ }
+
+ memset(pd,0,sizeof(POPUPDATAEX));
+ pd->iSeconds = 0;
+
+ if(type == 2){
+ pd->lchIcon = (HICON)hMBotIcon;
+ }else{
+ pd->lchIcon = (type == 2)?LoadIcon(NULL,IDI_ASTERISK):LoadIcon(NULL,IDI_INFORMATION);
+ }
+
+ strncpy(pd->lpzText,txt,sizeof(pd->lpzText));
+ strcpy(pd->lpzContactName,"MBot");
+ if(CallFunctionAsync(MBotPUHelperThread,pd)==FALSE){
+ my_memfree(pd);
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+ZEND_FUNCTION(mb_PUAdd)
+{
+ char *cname,*txt;
+ long cid=0,cl=0,tl=0,bgc=0,txc=0,hico=NULL;
+ POPUPDATAEX *pd;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss|lll",
+ &cid,&cname,&cl,&txt,&tl,&bgc,&txc,&hico) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!(pd = (POPUPDATAEX*)my_malloc(sizeof(POPUPDATAEX)))){
+ PHP_FALSE_AND_WARNS("Could not allocate memory!");
+ }
+
+ memset(pd,0,sizeof(POPUPDATAEX));
+ pd->iSeconds = 0;
+
+ pd->lchContact = (HANDLE)cid;
+ pd->colorText = txc;
+ pd->colorBack = bgc;
+ pd->lchIcon = (hico)?((HICON)hico):((HICON)hMBotIcon);
+ strncpy(pd->lpzContactName,cname,sizeof(pd->lpzContactName)-1);
+ strncpy(pd->lpzText,txt,sizeof(pd->lpzText)-1);
+
+ if(CallFunctionAsync(MBotPUHelperThread,pd)==FALSE){
+ my_memfree(pd);
+ RETURN_FALSE;
+ }
+ RETURN_TRUE;
+}
+
+ZEND_FUNCTION(mb_PUAddEx)
+{
+ long cid=0,cl=0,tl=0,bgc=0,txc=0,delay=0,param=0,hico=0;
+ char* cname=NULL,*txt=NULL;
+ zval* cb = NULL;
+ sMFSync* mfs = NULL;
+ POPUPDATAEX *pd;
+
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lss|llllzl",
+ &cid,&cname,&cl,&txt,&tl,&bgc,&txc,&hico,&delay,&cb,&param) == FAILURE || (cb && cb->type != IS_STRING)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(cb && !zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!(pd = (POPUPDATAEX*)my_malloc(sizeof(POPUPDATAEX)))){
+ RETURN_FALSE;
+ }
+
+ memset(pd,0,sizeof(POPUPDATAEX));
+
+ if(cb)
+ {
+ mfs = (sMFSync*)my_malloc(sizeof(sMFSync));
+ if(!mfs)goto Error;
+ memset(mfs,0,sizeof(sMFSync));
+
+ if(!mbe->php){goto Error;}
+ mfs->php = mbe->php;
+
+ strncpy(mfs->pszFunction,cb->value.str.val,sizeof(mfs->pszFunction));
+ mfs->pParam = (void*)param;
+
+ pd->PluginWindowProc = (WNDPROC)help_popup_wndproc;
+ pd->PluginData = mfs;
+ }
+
+ pd->iSeconds = delay;
+ pd->lchContact = (HANDLE)cid;
+ pd->colorText = txc;
+ pd->colorBack = bgc;
+ pd->lchIcon = (hico)?((HICON)hico):((HICON)hMBotIcon);
+ strncpy(pd->lpzContactName,cname,sizeof(pd->lpzContactName)-1);
+ strncpy(pd->lpzText,txt,sizeof(pd->lpzText)-1);
+
+ if(CallFunctionAsync(MBotPUHelperThread,pd)==FALSE){
+ goto Error;
+ }
+ RETURN_TRUE;
+Error:
+ my_memfree(pd);
+ if(mfs)my_memfree(mfs);
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_PUSystem)
+{
+ char* body;
+ char* title;
+ unsigned long tl=0,bl=0,flags=0,timeout=5;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll",&title,&tl,&body,&bl,&flags,&timeout) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!bl || !tl){
+ RETURN_FALSE;
+ }
+
+ MB_Popup(title,body,flags,timeout * 1000);
+ RETURN_TRUE;
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_reg.cpp b/mBot/src/mbot/functions/mb_reg.cpp
new file mode 100644
index 0000000..bb2c752
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_reg.cpp
@@ -0,0 +1,432 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+#include "../smanager.h"
+#include "../cron.h"
+
+ZEND_FUNCTION(mb_SelfRegister)
+{
+ long sl=0,event=0,id=0,priority=0x7fffffff;
+ char cache = 0;
+ PPHP php;
+ PHANDLER ph;
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(mbe->event != MBT_AUTOLOAD || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|bl",&event,&cache,&priority) == FAILURE){
+ PHP_FALSE_AND_WARNS("Invalid parameters given or this function is not allowed now!");
+ }
+
+ if(DBGetContactSettingByte(NULL,MBOT,"NoCache",0)){
+ cache = 0;
+ }
+
+ if(php = sman_getbyfile((const char*)mbe->p3))
+ {
+ if(mbe->p2 != NULL){
+ sman_recache(php);
+ }
+ }else{
+ php = sman_register((const char*)mbe->p3,cache);
+ if(!php){
+ RETURN_FALSE;
+ }
+ }
+
+ //count bytes
+ for(sl=0;sl<32;sl++)
+ {
+ if(event & (1 << sl))
+ {
+ ph = sman_handler_add(php,event & (1 << sl),priority & 0x7fffffff,(cache)?(MBOT_FLAG_CACHE):(0));
+ if(ph){
+ id++;
+ }
+ }
+ }
+
+ if(!id){
+ sman_unregister(php);
+ }else{
+ lh_flags |= event;
+ mbe->php = php;
+ }
+ RETURN_LONG(id);
+}
+
+ZEND_FUNCTION(mb_SelfSetInfo)
+{
+ char* desc = NULL;
+ long dl = 0;
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(!mbe->php || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&desc,&dl) == FAILURE){
+ PHP_FALSE_AND_WARNS("Script is not registered yet, or wrong parameters given!");
+ }
+
+ if(mbe->php->szDescription){
+ my_memfree(mbe->php->szDescription);
+ }
+ mbe->php->szDescription = my_strdup(desc);
+ RETURN_LONG(mbe->php->szDescription != NULL);
+}
+
+ZEND_FUNCTION(mb_SelfEnable)
+{
+ long event;
+ char enable = 0;
+ PHANDLER ph;
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(!mbe->php || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb",&event,&enable) == FAILURE){
+ PHP_FALSE_AND_WARNS("Invalid parameters given or this function is not allowed now!");
+ }
+
+ ph = sman_handler_find(mbe->php,event);
+ if(!ph){
+ PHPWSE("Event isn't registered!");
+ }else{
+ if(enable){
+ sman_handler_enable(ph);
+ }else{
+ sman_handler_disable(ph);
+ }
+ RETURN_TRUE;
+ }
+}
+
+ZEND_FUNCTION(mb_SchReg)
+{
+ extern CSyncList g_cron;
+ char *cron=NULL,*funct=NULL,*name=NULL;
+ long cl=0,sl=0,fl=0,nl=0;
+ char async=0;
+ char cache=0;
+ sCronSync* csn = 0;
+ sCronSync cs;
+
+ sPHPENV* ctx = (sPHPENV*)SG(server_context);
+ mb_event* mbe = (mb_event*)(ctx->c_param);
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|sbb",&name,&nl,&cron,&cl,&funct,
+ &fl,&cache,&async) == FAILURE || !cl || !fl || !nl)
+ {
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ //parse cron
+ if(!cron_parse(cron,&cs.ce)){
+ PHP_FALSE_AND_WARNS("You have an error in scheduler syntax!");
+ }
+ strncpy(cs.name,name,sizeof(cs.name)-1);
+ strncpy(cs.fcn,funct,sizeof(cs.fcn)-1);
+
+ if(mbe->event == MBT_AUTOLOAD){
+ mbe->php = sman_register((const char*)mbe->p3,(cache!=0));
+ if(!mbe->php){RETURN_FALSE;}
+ }else if(mbe->php == NULL){
+ RETURN_FALSE;
+ }else{
+ sman_incref(mbe->php);
+ }
+
+ if(async){
+ cs.lFlags |= MBOT_FLAG_ASYNC;
+ }
+
+ csn = (sCronSync*)my_malloc(sizeof(sCronSync));
+ if(!csn){
+ goto Error;
+ }
+
+ *csn = cs;
+ csn->data = mbe->php;
+
+ if(!cron_register(csn)){
+ goto Error;
+ }
+ cron_calcnext(&csn->ce);
+
+ RETURN_LONG(1);
+ //error
+Error:
+ sman_decref(mbe->php);
+ if(csn)my_memfree((void*)csn);
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_SchUnreg)
+{
+ char* name = NULL;
+ long nl = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&name,&nl) == FAILURE || !nl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ RETURN_LONG(cron_unregister(name));
+}
+
+ZEND_FUNCTION(mb_SchEnable)
+{
+ char* name = NULL;
+ long nl = 0;
+ zend_bool enable = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sb",&name,&nl,&enable) == FAILURE || !nl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(cron_enable(name,enable));
+}
+
+ZEND_FUNCTION(mb_SchModify)
+{
+ char* name = NULL;
+ char* csl = NULL;
+ long nl = 0;
+ zend_bool enable = 0;
+ sCronSync cs;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",&name,&nl,&csl,&nl) == FAILURE || !nl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ RETURN_LONG(cron_modify(name,cs.ce));
+}
+
+ZEND_FUNCTION(mb_SchList)
+{
+ extern CSyncList g_cron;
+
+ zval *fname;
+ char *name;
+ zval *argv[4] = {0};
+ zval **args[4] = {0};
+ zval *rv = NULL;
+ long result = 1;
+ sCronSync *e;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&fname) == FAILURE || fname->type != IS_STRING){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(fname, 0, &name))
+ {
+ php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "First argument is expected to be a valid callback");
+ efree(name);
+ RETURN_FALSE;
+ }
+
+ MAKE_STD_ZVAL(argv[0]);
+ MAKE_STD_ZVAL(argv[1]);
+ MAKE_STD_ZVAL(argv[2]);
+ MAKE_STD_ZVAL(argv[3]);
+
+ args[0] = &argv[0];
+ args[1] = &argv[1];
+ args[2] = &argv[2];
+ args[3] = &argv[3];
+
+ g_cron.Lock();
+ e = (sCronSync*)g_cron.m_head;
+ while(e)
+ {
+ if(!(e->lFlags & MBOT_FLAG_DELETE))
+ {
+ ZVAL_STRING(argv[0],(char*)e->name,0);
+
+ if(e->lFlags & MBOT_FLAG_INACTIVE){
+ ZVAL_LONG(argv[1],0);
+ }else{
+ ZVAL_LONG(argv[1],e->lTime);
+ }
+ ZVAL_LONG(argv[2],e->lLastSpent);
+ ZVAL_LONG(argv[3],e->lSpent);
+
+ if(call_user_function_ex(CG(function_table),NULL,fname,&rv,4,args,0, NULL TSRMLS_CC) != SUCCESS){
+ result = 0;
+ break;
+ }
+ }
+ e = (sCronSync*)e->next;
+ }
+ g_cron.Unlock();
+
+ efree(name);
+ FREE_ZVAL(argv[0]);
+ FREE_ZVAL(argv[1]);
+ FREE_ZVAL(argv[2]);
+ FREE_ZVAL(argv[3]);
+ RETURN_LONG(result);
+}
+
+ZEND_FUNCTION(mb_SysShallDie)
+{
+ extern CRITICAL_SECTION sm_sync;
+
+ char* script = NULL;
+ long sl = 0;
+ PPHP php;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s",&script,&sl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!sl){
+ php = sman_getbyfile(script);
+ }else{
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+ php = mbe->php;
+ }
+
+ if(!php){
+ RETURN_FALSE;
+ }else{
+ sman_lock();
+ sl = (php->lFlags & MBOT_FLAG_SHALLDIE | MBOT_FLAG_INACTIVE)==0;
+ sman_unlock();
+ }
+ RETURN_LONG(sl);
+}
+
+ZEND_FUNCTION(mb_SysManageScript)
+{
+ extern CRITICAL_SECTION sm_sync;
+
+ char* path=NULL;
+ long action,pl;
+ long events = 0x0FffFFff;
+ PPHP php;
+ PHANDLER ph;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l",&path,&pl,&action,&events) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ php = sman_getbyfile(path);
+
+ if(!php && action<7)goto Error;
+ switch(action)
+ {
+ case 0://disable
+ for(int i=0;i<32;i++){
+ if(events & (1 << i)){
+ ph = sman_handler_find(php,1 << i);
+ if(ph)sman_handler_disable(ph);
+ }
+ }
+ events = TRUE;
+ break;
+ case 1://enable
+ for(int i=0;i<32;i++){
+ if(events & (1 << i)){
+ ph = sman_handler_find(php,1 << i);
+ if(ph)sman_handler_enable(ph);
+ }
+ }
+ events = TRUE;
+ break;
+ case 2://cache/recache
+ events = sman_recache(php);
+ break;
+ case 3://uncache
+ events = sman_uncache(php);
+ break;
+ case 4://uninstall/unload
+ events = sman_uninstall(php,events == 1);
+ break;
+ case 5://enable file
+ events = help_enable_script(php,true);
+ break;
+ case 6://disable file
+ events = help_enable_script(php,false);
+ break;
+ case 7://install script
+ events = help_loadscript(path,0);
+ break;
+ case 8://is registered
+ events = php != NULL;
+ break;
+ default:
+ goto Error;
+ }
+ RETURN_TRUE;
+Error:
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_SysEnumHandlers)
+{
+ zval *fname;
+ char *name;
+ zval *argv[4] = {0};
+ zval **args[4] = {0};
+ zval *rv = NULL;
+ long result = 1;
+ long count = 0;
+ PHANDLER ph;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&fname) == FAILURE || fname->type != IS_STRING){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(fname, 0, &name))
+ {
+ php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "First argument is expected to be a valid callback");
+ efree(name);
+ RETURN_FALSE;
+ }
+
+ MAKE_STD_ZVAL(argv[0]);
+ MAKE_STD_ZVAL(argv[1]);
+ MAKE_STD_ZVAL(argv[2]);
+ MAKE_STD_ZVAL(argv[3]);
+
+ args[0] = &argv[0];
+ args[1] = &argv[1];
+ args[2] = &argv[2];
+ args[3] = &argv[3];
+
+ for(int i=0;i<32;i++)
+ {
+ ph = sman_handler_get(1 << i);
+
+ while(ph)
+ {
+ ZVAL_LONG(argv[0],(long)ph);
+ ZVAL_STRING(argv[1],(char*)ph->php->szFilePath,0);
+ ZVAL_LONG(argv[2],(1 << i));
+ ZVAL_LONG(argv[3],ph->lFlags);
+
+ if(call_user_function_ex(CG(function_table),NULL,fname,&rv,4,args,0, NULL TSRMLS_CC) != SUCCESS){
+ result = 0;
+ goto End;
+ }
+ ph = ph->next;
+ }
+ }
+End:
+ efree(name);
+ FREE_ZVAL(argv[0]);
+ FREE_ZVAL(argv[1]);
+ FREE_ZVAL(argv[2]);
+ FREE_ZVAL(argv[3]);
+ RETURN_LONG(result);
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_search.cpp b/mBot/src/mbot/functions/mb_search.cpp
new file mode 100644
index 0000000..3f2fbcf
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_search.cpp
@@ -0,0 +1,154 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+ZEND_FUNCTION(mb_SearchBasic)
+{
+ zval *cb = NULL;
+ char *uin = NULL;
+ char *proto = NULL;
+ long pl = 0;
+ long ul = 0;
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+ sACKSync* ack;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",&proto,&pl,&uin,&ul,&cb)==FAILURE ||
+ cb->type != IS_STRING || !pl || !ul){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ack = (sACKSync*)my_malloc(sizeof(sACKSync));
+ if(!ack){RETURN_FALSE}
+ memset(ack,0,sizeof(sACKSync));
+
+ if(!(ack->php = mbe->php))goto Error;
+
+ ack->lType = ACKTYPE_SEARCH;
+ ack->hContact = NULL;
+
+ strncpy(ack->pszFunction,cb->value.str.val,sizeof(ack->pszFunction)-1);
+ strncpy(ack->pszProtocol,proto,15);
+
+ if(!g_slist.Add(ack)){goto Error;}
+
+ ack->hProcess = (HANDLE)CallProtoService(proto,PS_BASICSEARCH,0,(LPARAM)uin);
+ if(!ack->hProcess){
+ g_slist.Del(ack);
+ goto Error;
+ }
+ RETURN_LONG(1);
+Error:
+ if(ack)my_memfree(ack);
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_SearchByEmail)
+{
+ zval *cb=NULL;
+ char *email=NULL;
+ char *proto=NULL;
+ long el = 0;
+ long pl = 0;
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+ sACKSync* ack;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz",&proto,&pl,&email,&el,&cb)==FAILURE ||
+ cb->type != IS_STRING || !pl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ack = (sACKSync*)my_malloc(sizeof(sACKSync));
+ if(!ack){RETURN_FALSE}
+ memset(ack,0,sizeof(sACKSync));
+
+ if(!(ack->php = mbe->php))goto Error;
+
+ ack->lType = ACKTYPE_SEARCH;
+ ack->hContact = NULL;
+
+ strncpy(ack->pszFunction,cb->value.str.val,sizeof(ack->pszFunction)-1);
+ strncpy(ack->pszProtocol,proto,15);
+
+ if(!g_slist.Add(ack)){goto Error;}
+
+ ack->hProcess = (HANDLE)CallProtoService(proto,PS_SEARCHBYEMAIL,0,(LPARAM)email);
+ if(!ack->hProcess){
+ g_slist.Del(ack);
+ goto Error;
+ }
+ RETURN_LONG(1);
+Error:
+ if(ack)my_memfree(ack);
+ RETURN_FALSE;
+}
+
+ZEND_FUNCTION(mb_SearchByName)
+{
+ zval *cb=NULL;
+ char *proto=NULL;
+ long pl = 0;
+ long tl = 0;
+ PROTOSEARCHBYNAME psbn={0};
+ sACKSync* ack;
+
+ mb_event* mbe = (mb_event*)(((sPHPENV*)SG(server_context))->c_param);
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szsss",&proto,&pl,&cb,
+ &psbn.pszNick,&tl,&psbn.pszFirstName,&tl,&psbn.pszLastName,&tl)==FAILURE || cb->type != IS_STRING || !pl){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ ack = (sACKSync*)my_malloc(sizeof(sACKSync));
+ if(!ack){RETURN_FALSE}
+ memset(ack,0,sizeof(sACKSync));
+
+ if(!(ack->php = mbe->php))goto Error;
+
+ ack->lType = ACKTYPE_SEARCH;
+ ack->hContact = NULL;
+
+ strncpy(ack->pszFunction,cb->value.str.val,sizeof(ack->pszFunction)-1);
+ strncpy(ack->pszProtocol,proto,15);
+
+ if(!g_slist.Add(ack)){goto Error;}
+
+ ack->hProcess = (HANDLE)CallProtoService(proto,PS_SEARCHBYNAME,0,(LPARAM)&psbn);
+ if(!ack->hProcess){
+ g_slist.Del(ack);
+ goto Error;
+ }
+ RETURN_LONG(1);
+Error:
+ if(ack)my_memfree(ack);
+ RETURN_FALSE;
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_snd.cpp b/mBot/src/mbot/functions/mb_snd.cpp
new file mode 100644
index 0000000..d4ea6f0
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_snd.cpp
@@ -0,0 +1,73 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+/******************************************
+ * sounds *
+ ******************************************/
+ZEND_FUNCTION(mb_SoundPlay)
+{
+ char* snd = NULL;
+ long sl = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&snd,&sl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(SkinPlaySound(snd)==0);
+}
+
+ZEND_FUNCTION(mb_SoundAdd)
+{
+ char *s1=NULL,*s2=NULL,*s3=NULL;
+ long l1=0,l2=0,l3=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",&s1,&l1,&s2,&l2,&s3,&l3) == FAILURE)return;
+ RETURN_LONG(SkinAddNewSound(s1,(const char*)s2,(const char*)s3)==0);
+}
+
+ZEND_FUNCTION(mb_SoundAddEx)
+{
+ char *s1=NULL,*s2=NULL,*s3=NULL;
+ long l1=0,l2=0,l3=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss",&s1,&l1,&s2,&l2,&s3,&l3) == FAILURE)return;
+ RETURN_LONG(SkinAddNewSoundEx(s1,(const char*)s2,(const char*)s3)==0);
+}
+
+ZEND_FUNCTION(mb_SoundSet)
+{
+ char *s1=NULL,*s2=NULL;
+ long l1=0,l2=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",&s1,&l1,&s2,&l2) == FAILURE)return;
+
+ RETURN_LONG(DBWriteContactSettingString(NULL,"SkinSounds",s1,s2)==0);
+}
+
+ZEND_FUNCTION(mb_SoundDel)
+{
+ char *s1=NULL;
+ long l1=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&s1,&l1) == FAILURE)return;
+
+ RETURN_LONG(DBDeleteContactSetting(NULL,"SkinSounds",s1)==0);
+} \ No newline at end of file
diff --git a/mBot/src/mbot/functions/mb_sys.cpp b/mBot/src/mbot/functions/mb_sys.cpp
new file mode 100644
index 0000000..08fef2a
--- /dev/null
+++ b/mBot/src/mbot/functions/mb_sys.cpp
@@ -0,0 +1,786 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "../functions.h"
+
+/*name: mb_SysLoadModule
+params: $name{S:dll path};
+desc: Tries to load a dynamicly linked library (DLL), and returns its handle or 0;
+example:
+*/
+ZEND_FUNCTION(mb_SysLoadModule)
+{
+ char* name;
+ long nl=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&name,&nl) == FAILURE)
+ {
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ RETURN_LONG((long)LoadLibrary(name));
+}
+
+/*name: mb_SysUnLoadModule
+params: $handle{L:dll handle};
+desc: Releases a module loaded with %mb_SysLoadModule;
+example:
+*/
+ZEND_FUNCTION(mb_SysUnLoadModule)
+{
+ HMODULE hm;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&hm) == FAILURE)
+ {
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+ RETURN_LONG(FreeLibrary(hm));
+}
+
+
+/*name: mb_SysCallService
+params: $name{S:service name}|$wparam{M:WPARAM},$lparam{M:LPARAM};
+desc: Calls a miranda service specified by $name, passing up to two parameters. mb_SysCallService accepts up to two parameters (0, 1 or 3) and returns the numeric result;
+example:
+*/
+ZEND_FUNCTION(mb_SysCallService)
+{
+ zval* lparam=0;
+ zval* wparam=0;
+ char* name=0;
+ void *lp=NULL,*wp=NULL;
+ long nl=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!z!",&name,&nl,&wparam,&lparam) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!nl){
+ PHPWSE("You can't call an empty service!");
+ }
+
+ if(lparam){
+ lp = (lparam->type==IS_STRING)?((void*)lparam->value.str.val):((void*)lparam->value.lval);
+ }
+ if(wparam){
+ wp = (wparam->type==IS_STRING)?((void*)wparam->value.str.val):((void*)wparam->value.lval);
+ }
+
+ try{
+ nl = CallService(name,(WPARAM)wp,(LPARAM)lp);
+ }catch(...){
+ RETURN_FALSE;
+ }
+ RETURN_LONG(nl);
+}
+
+ZEND_FUNCTION(mb_SysCallProtoService)
+{
+ zval* lparam=0;
+ zval* wparam=0;
+ char* name=0;
+ char* proto=0;
+ long nl=0;
+ long pl=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z!z!",&proto,&pl,&name,&nl,&wparam,&lparam) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!nl || !pl){
+ PHPWSE("Specified $serivce or $protocol name is empty!");
+ }
+
+ void* lp = (lparam->type==IS_STRING)?((void*)lparam->value.str.val):((void*)lparam->value.lval);
+ void* wp = (lparam->type==IS_STRING)?((void*)wparam->value.str.val):((void*)wparam->value.lval);
+
+ try{
+ nl = CallProtoService(proto,name,(WPARAM)wp,(LPARAM)lp);
+ }catch(...){
+ RETURN_FALSE;
+ }
+ RETURN_LONG(nl);
+}
+
+
+ZEND_FUNCTION(mb_SysQuit)
+{
+ PostQuitMessage(0);
+}
+
+ZEND_FUNCTION(mb_SysCallContactService)
+{
+ zval* lparam=0;
+ zval* wparam=0;
+ char* name=0;
+ long nl=0;
+ long cid=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsz!z!",&cid,&name,&nl,&wparam,&lparam) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!nl || !cid){
+ PHPWSE("Specified $cid or $service name is empty!");
+ }
+
+ void* lp = (lparam->type==IS_STRING)?((void*)lparam->value.str.val):((void*)lparam->value.lval);
+ void* wp = (lparam->type==IS_STRING)?((void*)wparam->value.str.val):((void*)wparam->value.lval);
+
+ try{
+ nl = CallContactService((HANDLE)cid,name,(WPARAM)wp,(LPARAM)lp);
+ }catch(...){
+ RETURN_FALSE;
+ }
+ RETURN_LONG(nl);
+}
+
+ZEND_FUNCTION(mb_SysGetString)
+{
+ long str;
+ char* n=0;
+ long len = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",&str,&len) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!str){
+ PHPWSE("Null pointer given!");
+ }
+ try{
+ if(!len){
+ len = strlen((const char*)str);
+ }
+ n = (char*)emalloc(len+1);
+ if(!n){
+ RETURN_FALSE;
+ }
+ memcpy(n,(void*)str,len);
+ n[len]='\0';
+ }catch(...){
+ RETURN_FALSE;
+ }
+ RETURN_STRINGL(n,len,0);
+}
+
+ZEND_FUNCTION(mb_SysGetNumber)
+{
+ long ptr;
+ long type = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",&ptr,&type) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!ptr){
+ PHPWSE("Null pointer given!");
+ }
+
+ try
+ {
+ if(type == 0 || type == 4){
+ RETURN_LONG(*((long*)ptr));
+ }else if(type == 2){
+ RETURN_LONG(*((short*)ptr));
+ }else if(type == 1){
+ RETURN_LONG(*((char*)ptr));
+ }else{
+ RETURN_FALSE;
+ }
+ }catch(...){
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysGetPointer)
+{
+ zval* ptr;
+ long type = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&ptr) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!ptr){
+ PHPWSE("Null pointer given!");
+ }
+
+ if(ptr->type == IS_STRING){
+ RETURN_LONG(((long)ptr->value.str.val));
+ }else{
+ RETURN_LONG(((long)&ptr->value.lval));
+ }
+}
+
+ZEND_FUNCTION(mb_SysPutString)
+{
+ long ptr=0;
+ long len=0;
+ zval* val=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz|l",&ptr,&val,&len) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!ptr){
+ PHPWSE("Null pointer given!");
+ }else if(val->type != IS_STRING){
+ PHPWSE("$str must be a valid string!");
+ }else if(len > val->value.str.len){
+ PHPWSE("$str is shorter than you think it is!");
+ }
+
+ try{
+ if(!len){
+ strcpy((char*)ptr,val->value.str.val);
+ }else{
+ memcpy((void*)ptr,val->value.str.val,len);
+ }
+ RETURN_TRUE;
+ }catch(...){
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysPutNumber)
+{
+ long ptr;
+ long num;
+ long type = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|l",&ptr,&num,&type) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!ptr){
+ PHPWSE("Null pointer given!");
+ }
+
+ try
+ {
+ if(type == 0 || type == 4){
+ *((long*)ptr) = num;
+ }else if(type == 2){
+ *((short*)ptr) = *((short*)&num);
+ }else if(type == 1){
+ *((char*)ptr) = *((char*)&num);
+ }else{
+ RETURN_FALSE;
+ }
+ RETURN_LONG(num);
+ }catch(...){
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysMemCpy)
+{
+ long p1,p2,amount;
+ zval* vp2 = NULL;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lzl",&p1,&vp2,&amount) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!p1 || !vp2){
+ PHPWSE("Null pointer given!");
+ }else if(amount < 0){
+ PHPWSE("You can't copy negative number of bytes!");
+ }
+
+ if(vp2->type == IS_STRING){
+ p2 = (long)vp2->value.str.val;
+ if(!amount){amount = vp2->value.str.len;}
+ }else if(vp2->type == IS_LONG){
+ p2 = vp2->value.lval;
+ }else{
+ PHPWSE("Wrong parameter type!");
+ }
+
+ try{
+ memcpy((void*)p1,(void*)p2,(amount)?(amount):(strlen((const char*)p2)+1));
+ RETURN_TRUE;
+ }
+ catch(...)
+ {
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysMalloc)
+{
+ long amount=0;
+ void* ptr;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&amount) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(amount <= 0){
+ PHPWSE("You can't allocate nothing or even less than nothing!");
+ }
+
+ try{
+ ptr = my_malloc(amount);
+ if(ptr){memset(ptr,0,amount);}
+ RETURN_LONG((long)ptr);
+ }catch(...){
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysGlobalAlloc)
+{
+ long amount=0;
+ void* ptr;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&amount) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(amount <= 0){
+ PHPWSE("You can't allocate nothing or even less than nothing!");
+ }
+
+ try{
+ ptr = my_malloc(amount);
+ if(ptr){memset(ptr,0,amount);}
+ RETURN_LONG((long)ptr);
+ }catch(...){
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysGlobalFree)
+{
+ long ptr;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&ptr) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!ptr){
+ PHPWSE("Null pointer given!");
+ }
+ try{
+ my_memfree((void*)ptr);
+ RETURN_TRUE;
+ }
+ catch(...)
+ {
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysFree)
+{
+ long ptr;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&ptr) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!ptr){
+ PHPWSE("Null pointer given!");
+ }
+ try{
+ efree((void*)ptr);
+ RETURN_TRUE;
+ }
+ catch(...)
+ {
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysGetProcAddr)
+{
+ char* module=0;
+ char* function=0;
+ long ml=0;
+ long fl=0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",&module,&ml,&function,&fl) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ RETURN_LONG(help_getprocaddr(module,function));
+}
+struct sSysThreadHelper{
+ PPHP php;
+ char* cb;
+ lphp_vparam vp;
+ HANDLE hEvent;
+};
+
+
+long WINAPI SysThread(sSysThreadHelper* p)
+{
+ lphp_vparam vp;
+ mb_event mbe = {MBT_CALLBACK,0};
+ char cb[32];
+
+ mbe.php = p->php;
+ strncpy(cb,p->cb,sizeof(cb)-1);
+
+ //make a copy of vp
+ vp = p->vp;
+
+ if(vp.type == LPHP_STRING){
+ vp.data = strdup((const char*)vp.data);
+ }
+
+ sman_incref(mbe.php);
+ SetEvent(p->hEvent);
+
+ MBMultiParam(mbe.php,cb,&mbe,"v",&vp);
+ sman_decref(mbe.php);
+
+ if(vp.type == LPHP_STRING){
+ my_memfree(vp.data);
+ }
+ return 0;
+}
+
+ZEND_FUNCTION(mb_SysBeginThread)
+{
+ zval* cb = NULL;
+ zval* param = NULL;
+ HANDLE hThread;
+ DWORD dwID;
+ sSysThreadHelper shp;
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",&cb,&param) == FAILURE)
+ {
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!mbe->php){
+ PHPWSE("You can't register a service function here!");
+ }
+
+ if(cb->type != IS_STRING || !zend_is_callable(cb,0,NULL)){
+ PHPWSE("$cb is expected to be a valid callback function!");
+ }
+
+ if(param->type == IS_STRING)
+ {
+ shp.vp.type = LPHP_STRING;
+ shp.vp.data = (void*)param->value.str.val;
+ shp.vp.length = param->value.str.len;
+ }else{
+ shp.vp.type = LPHP_NUMBER;
+ shp.vp.data = (void*)param->value.lval;
+ shp.vp.length = 4;
+ }
+
+ shp.php = mbe->php;
+ shp.cb = cb->value.str.val;
+ shp.hEvent = CreateEvent(0,0,0,0);
+ if(shp.hEvent == INVALID_HANDLE_VALUE){
+ RETURN_FALSE;
+ }
+
+ hThread = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)SysThread,(void*)&shp,0,&dwID);
+ if(hThread){
+ CloseHandle(hThread);
+ WaitForSingleObject(shp.hEvent,INFINITE);
+ CloseHandle(shp.hEvent);
+ RETURN_LONG(dwID);
+ }else{
+ CloseHandle(shp.hEvent);
+ RETURN_FALSE;
+ }
+}
+
+ZEND_FUNCTION(mb_SysCallProc)
+{
+ extern FILE* dbgout;
+ void* p_ebp;
+ void* p_esp;
+ void* p_res = NULL;
+
+ long fcn=0;
+ long argc;
+ zval* params[10]={0};
+ void* vp[10]={0};
+
+ argc = ZEND_NUM_ARGS();
+
+ if(argc < 2){
+ WRONG_PARAM_COUNT;
+ }
+
+ if(zend_parse_parameters(argc TSRMLS_CC, "l|z!z!z!z!z!z!z!z!z!z!",&fcn,
+ &params[0],&params[1],&params[2],&params[3],&params[4],&params[5],&params[6],&params[7],&params[8],&params[9]) == FAILURE)
+ {
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!fcn){
+ PHPWSE("Null function pointer given!");
+ }
+
+ __asm{
+ mov p_ebp, ebp;
+ mov p_esp, esp;
+ }
+
+ argc --;
+
+ //fprintf(dbgout,"0x%.8x(",fcn);
+ for(int i=0;i<argc;i++)
+ {
+ if(!params[i]){
+ vp[i] = NULL;
+ }else if(params[i]->type == IS_STRING){
+ vp[i] = (void*)params[i]->value.str.val;
+ }else{
+ vp[i] = (void*)params[i]->value.lval;
+ }
+
+ //fprintf(dbgout,"%d,",vp[i]);
+ }
+ //fprintf(dbgout,");\r\n");
+ //fflush(dbgout);
+
+ try{
+ //put the params
+ p_res = (void*)vp;
+ __asm{
+ mov ecx, argc
+ mov ebx, ecx
+ shl ebx, 2d
+ sub ebx, 4d
+ add ebx, p_res
+PETLA:
+ push DWORD PTR [ebx]
+ sub ebx, 4d
+ dec ecx
+ jnz PETLA
+ //call the function
+ mov ebx, fcn
+ xor eax, eax
+ call ebx
+ mov p_res, eax
+ //cleanup
+ mov ebp, p_ebp;
+ mov esp, p_esp;
+ }
+ }catch(...){
+ __asm{
+ mov ebp, p_ebp;
+ mov esp, p_esp;
+ }
+ PHP_WARN "Execution failed :!");
+
+ RETURN_FALSE;
+ }
+
+ RETURN_LONG((long)p_res);
+}
+
+ZEND_FUNCTION(mb_SysCreateService)
+{
+ extern CSyncList g_svlist;
+
+ zval* name = NULL;
+ zval* cb = NULL;
+ sHESync* hfs = NULL;
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",&name,&cb) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!mbe->php){
+ PHPWSE("You can't register a service function here!");
+ }
+
+ if(name->type != IS_STRING || name->value.str.len < 5){
+ PHPWSE("$name must be a valid string of 5-47 characters!");
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHPWSE("$cb is expected to be a valid callback function!");
+ }
+
+ hfs = (sHESync*)my_malloc(sizeof(sHESync));
+ if(!hfs){
+ PHPWSE("Could not allocate memory!");
+ }
+ memset(hfs,0,sizeof(sHESync));
+
+ hfs->pCode = help_makefunct((void*)hfs,(void*)help_callsvc);
+ if(!hfs->pCode){
+ my_memfree((void*)hfs);
+ PHPWSE("Could not create the machine code!");
+ }
+
+ sman_incref(mbe->php);
+ hfs->php = mbe->php;
+
+ strncpy(hfs->pszFunction,cb->value.str.val,sizeof(hfs->pszFunction)-1);
+ strncpy(hfs->pszSvcName,name->value.str.val,sizeof(hfs->pszSvcName)-1);
+ hfs->hFunction = (long)CreateServiceFunction(hfs->pszSvcName,(MIRANDASERVICE)hfs->pCode);
+ if(!hfs->hFunction){
+ my_memfree((void*)hfs->pCode);
+ my_memfree((void*)hfs);
+ sman_decref(mbe->php);
+ PHPWSE("Could not create service function!");
+ }
+ g_svlist.Add(hfs);
+
+ RETURN_LONG(hfs->hFunction);
+}
+
+ZEND_FUNCTION(mb_SysHookEvent)
+{
+ extern CSyncList g_svlist;
+
+ zval* name = NULL;
+ zval* cb = NULL;
+ sHESync* hfs = NULL;
+ mb_event* mbe = (mb_event*)((sPHPENV*)SG(server_context))->c_param;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",&name,&cb) == FAILURE){
+ PHP_FALSE_AND_WARNS(PHP_WARN_INVALID_PARAMS);
+ }
+
+ if(!mbe->php){
+ PHPWSE("You can't register a service function here!");
+ }
+
+ if(name->type != IS_STRING || name->value.str.len < 1){
+ PHPWSE("$name must be a valid string of 1-47 characters!");
+ }
+
+ if(!zend_is_callable(cb,0,NULL)){
+ PHPWSE("$cb is expected to be a valid callback function!");
+ }
+
+ hfs = (sHESync*)my_malloc(sizeof(sHESync));
+ if(!hfs){
+ PHPWSE("Could not allocate memory!");
+ }
+ memset(hfs,0,sizeof(sHESync));
+
+ hfs->pCode = help_makefunct((void*)hfs,(void*)help_callsvc);
+ if(!hfs->pCode){
+ my_memfree((void*)hfs);
+ PHPWSE("Could not create the machine code!");
+ }
+
+ sman_incref(mbe->php);
+ hfs->php = mbe->php;
+
+ strncpy(hfs->pszFunction,cb->value.str.val,sizeof(hfs->pszFunction)-1);
+ hfs->hHook = (long)HookEvent(name->value.str.val,(MIRANDAHOOK)hfs->pCode);
+
+ if(!hfs->hHook){
+ my_memfree((void*)hfs->pCode);
+ my_memfree((void*)hfs);
+ sman_decref(mbe->php);
+ PHPWSE("Could not create service function!");
+ }
+ g_svlist.Add(hfs);
+
+ RETURN_LONG(hfs->hFunction);
+}
+
+ZEND_FUNCTION(mb_SysEnumProtocols)
+{
+ PROTOCOLDESCRIPTOR **proto;
+ int protoCount;
+
+ CallService(MS_PROTO_ENUMPROTOCOLS,(WPARAM)&protoCount,(LPARAM)&proto);
+ if(!protoCount || array_init(return_value)==FAILURE){
+ RETURN_FALSE;
+ }
+
+ for(int i=0;i<protoCount;i++)
+ {
+ if(proto[i]->type != PROTOTYPE_PROTOCOL) continue;
+ add_index_string(return_value,i,proto[i]->szName,1);
+ }
+ return;
+}
+int xx_enummodules(const char *szModuleName,DWORD ofsModuleName,LPARAM lParam)
+{
+ cutMemf* mf = (cutMemf*)lParam;
+ if(*szModuleName){
+ mf->write((void*)szModuleName, strlen(szModuleName) + 1);
+ }
+ return 0;
+}
+ZEND_FUNCTION(mb_SysEnumModules)
+{
+ cutMemf mf;
+ long ml=0;
+ char* mod=NULL;
+
+ if(!mf.create(2048)){
+ RETURN_FALSE;
+ }
+
+ if(CallService(MS_DB_MODULES_ENUM,(WPARAM)&mf,(LPARAM)xx_enummodules)!=0){
+ RETURN_FALSE;
+ }
+
+ mf.putc(0);
+ if(array_init(return_value)==FAILURE){
+ RETURN_FALSE;
+ }
+
+ mod = (char*)mf.getdata();
+ ml = 0;
+ while(*mod)
+ {
+ add_index_string(return_value,ml,mod,1);
+ mod = mod + strlen(mod) + 1;
+ ml++;
+ }
+ mf.close();
+}
+
+ZEND_FUNCTION(mb_SysGetProfileName)
+{
+ RETURN_STRING(g_profile,1);
+}
+
+ZEND_FUNCTION(mb_SysTranslate)
+{
+ char* str = NULL;
+ long sl = 0;
+
+ if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",&str,&sl) == FAILURE){
+ PHP_FALSE_AND_ERROR;
+ }
+
+ str = (char*)CallService(MS_LANGPACK_TRANSLATESTRING,0,(LPARAM)str);
+ RETURN_STRING((str)?(str):(""),1);
+}
+
+ZEND_FUNCTION(mb_SysGetMirandaDir)
+{
+ RETURN_STRING(g_root,1);
+} \ No newline at end of file