aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorGravatar Noldor2010-07-22 14:50:48 +0000
committerGravatar Noldor2010-07-22 14:50:48 +0000
commitf61de507fe9be2ff339fb153d927e4641277d626 (patch)
tree76a9e3a635c6f97a870aff736e335609fea64ac8 /src/modules
parentimplemented #799 (and fixed some serverdb module docs) (diff)
downloadKVIrc-f61de507fe9be2ff339fb153d927e4641277d626.tar.gz
KVIrc-f61de507fe9be2ff339fb153d927e4641277d626.tar.bz2
KVIrc-f61de507fe9be2ff339fb153d927e4641277d626.zip
KVS code improvements
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4686 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/objects/class_file.cpp14
-rw-r--r--src/modules/objects/class_file.h1
-rw-r--r--src/modules/objects/class_socket.cpp26
3 files changed, 35 insertions, 6 deletions
diff --git a/src/modules/objects/class_file.cpp b/src/modules/objects/class_file.cpp
index 6c3867a2c..acc9a00fe 100644
--- a/src/modules/objects/class_file.cpp
+++ b/src/modules/objects/class_file.cpp
@@ -160,6 +160,7 @@ KVSO_BEGIN_REGISTERCLASS(KviKvsObject_file,"file","object")
KVSO_REGISTER_HANDLER(KviKvsObject_file,"flush",flush)
KVSO_REGISTER_HANDLER(KviKvsObject_file,"size",size)
+ KVSO_REGISTER_HANDLER(KviKvsObject_file,"resize",resize)
KVSO_REGISTER_HANDLER(KviKvsObject_file,"atEnd",atEnd)
KVSO_REGISTER_HANDLER(KviKvsObject_file,"where",where)
@@ -311,6 +312,19 @@ KVSO_CLASS_FUNCTION(file,seek)
return true;
}
+
+KVSO_CLASS_FUNCTION(file,resize)
+{
+ CHECK_INTERNAL_POINTER(m_pFile)
+ kvs_int_t iSize;
+ KVSO_PARAMETERS_BEGIN(c)
+ KVSO_PARAMETER("size",KVS_PT_INTEGER,0,iSize)
+ KVSO_PARAMETERS_END(c)
+ CHECK_FILE_IS_OPEN
+ m_pFile->resize(iSize);
+ return true;
+}
+
KVSO_CLASS_FUNCTION(file,putch)
{
CHECK_INTERNAL_POINTER(m_pFile)
diff --git a/src/modules/objects/class_file.h b/src/modules/objects/class_file.h
index e184a95c8..f708440b7 100644
--- a/src/modules/objects/class_file.h
+++ b/src/modules/objects/class_file.h
@@ -46,6 +46,7 @@ public:
bool close(KviKvsObjectFunctionCall *c);
bool flush(KviKvsObjectFunctionCall *c);
bool size(KviKvsObjectFunctionCall *c);
+ bool resize(KviKvsObjectFunctionCall *c);
bool atEnd(KviKvsObjectFunctionCall *c);
// int QFile at() const
diff --git a/src/modules/objects/class_socket.cpp b/src/modules/objects/class_socket.cpp
index 74dee6ac7..c572f4d5f 100644
--- a/src/modules/objects/class_socket.cpp
+++ b/src/modules/objects/class_socket.cpp
@@ -412,16 +412,29 @@ KVSO_CLASS_FUNCTION(socket,read)
c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects"));
return true;
}
- if (!pObject->inheritsClass("memorybuffer"))
+ if (pObject->inheritsClass("memorybuffer"))
+ {
+ QByteArray *pBuffer=((KviKvsObject_memorybuffer *)pObject)->pBuffer();
+ int oldsize=pBuffer->size();
+ pBuffer->resize(oldsize+uLen);
+ kvi_memmove(pBuffer->data()+oldsize,m_pInBuffer,uLen);
+
+ }
+ else if (pObject->inheritsClass("file"))
+ {
+ KviFile *pFile=((KviKvsObject_file *)pObject)->file();
+ if (!pFile->isOpen())
+ {
+ c->warning(__tr2qs_ctx("File is not open!","objects"));
+ return true;
+ }
+ pFile->write(m_pInBuffer,uLen);
+ }
+ else
{
c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer object","objects"));
return true;
}
-
- QByteArray *pBuffer=((KviKvsObject_memorybuffer *)pObject)->pBuffer();
- int oldsize=pBuffer->size();
- pBuffer->resize(oldsize+uLen);
- kvi_memmove(pBuffer->data()+oldsize,m_pInBuffer,uLen);
eatInData(uLen);
return true;
}
@@ -441,6 +454,7 @@ KVSO_CLASS_FUNCTION(socket,read)
}
+
KVSO_CLASS_FUNCTION(socket,write)
{
kvs_uint_t uLen;