diff options
Diffstat (limited to 'doc/html/networkprotocol-example.html')
-rw-r--r-- | doc/html/networkprotocol-example.html | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/doc/html/networkprotocol-example.html b/doc/html/networkprotocol-example.html index e47d8020d..7f634b736 100644 --- a/doc/html/networkprotocol-example.html +++ b/doc/html/networkprotocol-example.html @@ -33,7 +33,7 @@ body { background: #ffffff; color: black; } <p> -<p> This example shows how to implement your own <a href="ntqnetworkprotocol.html">TQNetworkProtocol</a>. The +<p> This example shows how to implement your own <a href="tqnetworkprotocol.html">TQNetworkProtocol</a>. The protocol that was chosen for this example is NTTP. Please note that this implementation is very simple since it is designed to be an example. It should not be used as a real NNTP implemention. @@ -52,10 +52,10 @@ should not be used as a real NNTP implemention. #ifndef NNTP_H #define NNTP_H -#include <<a href="qsocket-h.html">ntqsocket.h</a>> -#include <<a href="qnetworkprotocol-h.html">ntqnetworkprotocol.h</a>> +#include <<a href="tqsocket-h.html">tqsocket.h</a>> +#include <<a href="tqnetworkprotocol-h.html">tqnetworkprotocol.h</a>> -class Nntp : public <a href="ntqnetworkprotocol.html">TQNetworkProtocol</a> +class Nntp : public <a href="tqnetworkprotocol.html">TQNetworkProtocol</a> { <a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a> @@ -65,16 +65,16 @@ public: virtual int supportedOperations() const; protected: - virtual void operationListChildren( <a href="qnetworkoperation.html">TQNetworkOperation</a> *op ); - virtual void operationGet( <a href="qnetworkoperation.html">TQNetworkOperation</a> *op ); + virtual void operationListChildren( <a href="tqnetworkoperation.html">TQNetworkOperation</a> *op ); + virtual void operationGet( <a href="tqnetworkoperation.html">TQNetworkOperation</a> *op ); - <a href="ntqsocket.html">TQSocket</a> *commandSocket; + <a href="tqsocket.html">TQSocket</a> *commandSocket; bool connectionReady; bool readGroups; bool readArticle; private: - bool checkConnection( <a href="qnetworkoperation.html">TQNetworkOperation</a> *op ); + bool checkConnection( <a href="tqnetworkoperation.html">TQNetworkOperation</a> *op ); void close(); void parseGroups(); void parseArticle(); @@ -104,27 +104,27 @@ protected slots: *****************************************************************************/ #include "nntp.h" -#include <<a href="qurlinfo-h.html">ntqurlinfo.h</a>> +#include <<a href="tqurlinfo-h.html">tqurlinfo.h</a>> #include <stdlib.h> -#include <<a href="qurloperator-h.html">ntqurloperator.h</a>> +#include <<a href="tqurloperator-h.html">tqurloperator.h</a>> #include <<a href="tqstringlist-h.html">tqstringlist.h</a>> #include <<a href="tqregexp-h.html">tqregexp.h</a>> <a name="f288"></a>Nntp::Nntp() - : <a href="ntqnetworkprotocol.html">TQNetworkProtocol</a>(), connectionReady( FALSE ), + : <a href="tqnetworkprotocol.html">TQNetworkProtocol</a>(), connectionReady( FALSE ), readGroups( FALSE ), readArticle( FALSE ) { // create the command socket and connect to its signals - commandSocket = new <a href="ntqsocket.html">TQSocket</a>( this ); -<a name="x684"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="ntqsocket.html#hostFound">hostFound</a>() ), + commandSocket = new <a href="tqsocket.html">TQSocket</a>( this ); +<a name="x684"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="tqsocket.html#hostFound">hostFound</a>() ), this, TQ_SLOT( hostFound() ) ); -<a name="x681"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="ntqsocket.html#connected">connected</a>() ), +<a name="x681"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="tqsocket.html#connected">connected</a>() ), this, TQ_SLOT( connected() ) ); -<a name="x682"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="ntqsocket.html#connectionClosed">connectionClosed</a>() ), +<a name="x682"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="tqsocket.html#connectionClosed">connectionClosed</a>() ), this, TQ_SLOT( closed() ) ); -<a name="x687"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="ntqsocket.html#readyRead">readyRead</a>() ), +<a name="x687"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="tqsocket.html#readyRead">readyRead</a>() ), this, TQ_SLOT( readyRead() ) ); -<a name="x683"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="ntqsocket.html#error">error</a>( int ) ), +<a name="x683"></a> <a href="tqobject.html#connect">connect</a>( commandSocket, TQ_SIGNAL( <a href="tqsocket.html#error">error</a>( int ) ), this, TQ_SLOT( error( int ) ) ); } @@ -134,15 +134,15 @@ Nntp::~Nntp() delete commandSocket; } -<a name="x675"></a>void Nntp::<a href="ntqnetworkprotocol.html#operationListChildren">operationListChildren</a>( <a href="qnetworkoperation.html">TQNetworkOperation</a> * ) +<a name="x675"></a>void Nntp::<a href="tqnetworkprotocol.html#operationListChildren">operationListChildren</a>( <a href="tqnetworkoperation.html">TQNetworkOperation</a> * ) { // create a command - <a href="tqstring.html">TQString</a> path = <a href="ntqnetworkprotocol.html#url">url</a>()->path(), cmd; + <a href="tqstring.html">TQString</a> path = <a href="tqnetworkprotocol.html#url">url</a>()->path(), cmd; <a name="x691"></a> if ( path.<a href="tqstring.html#isEmpty">isEmpty</a>() || path == "/" ) { // if the path is empty or we are in the root dir, // we want to read the list of available newsgroups cmd = "list newsgroups\r\n"; - } else if ( <a href="ntqnetworkprotocol.html#url">url</a>()->isDir() ) { + } else if ( <a href="tqnetworkprotocol.html#url">url</a>()->isDir() ) { // if the path is a directory (in our case a news group) // we want to list the articles of this group <a name="x694"></a> path = path.<a href="tqstring.html#replace">replace</a>( "/", "" ); @@ -151,60 +151,60 @@ Nntp::~Nntp() return; // write the command to the socket -<a name="x693"></a><a name="x692"></a><a name="x689"></a> commandSocket-><a href="ntqsocket.html#writeBlock">writeBlock</a>( cmd.<a href="tqstring.html#latin1">latin1</a>(), cmd.<a href="tqstring.html#length">length</a>() ); +<a name="x693"></a><a name="x692"></a><a name="x689"></a> commandSocket-><a href="tqsocket.html#writeBlock">writeBlock</a>( cmd.<a href="tqstring.html#latin1">latin1</a>(), cmd.<a href="tqstring.html#length">length</a>() ); readGroups = TRUE; } -<a name="x674"></a>void Nntp::<a href="ntqnetworkprotocol.html#operationGet">operationGet</a>( <a href="qnetworkoperation.html">TQNetworkOperation</a> *op ) +<a name="x674"></a>void Nntp::<a href="tqnetworkprotocol.html#operationGet">operationGet</a>( <a href="tqnetworkoperation.html">TQNetworkOperation</a> *op ) { // get the dirPath of the URL (this is our news group) // and the filename (which is the article we want to read) -<a name="x672"></a> <a href="ntqurl.html">TQUrl</a> u( op-><a href="qnetworkoperation.html#arg">arg</a>( 0 ) ); -<a name="x696"></a><a name="x695"></a> <a href="tqstring.html">TQString</a> dirPath = u.<a href="ntqurl.html#dirPath">dirPath</a>(), file = u.<a href="ntqurl.html#fileName">fileName</a>(); +<a name="x672"></a> <a href="tqurl.html">TQUrl</a> u( op-><a href="tqnetworkoperation.html#arg">arg</a>( 0 ) ); +<a name="x696"></a><a name="x695"></a> <a href="tqstring.html">TQString</a> dirPath = u.<a href="tqurl.html#dirPath">dirPath</a>(), file = u.<a href="tqurl.html#fileName">fileName</a>(); dirPath = dirPath.<a href="tqstring.html#replace">replace</a>( "/", "" ); // go to the group in which the article is <a href="tqstring.html">TQString</a> cmd; cmd = "group " + dirPath + "\r\n"; - commandSocket-><a href="ntqsocket.html#writeBlock">writeBlock</a>( cmd.<a href="tqstring.html#latin1">latin1</a>(), cmd.<a href="tqstring.html#length">length</a>() ); + commandSocket-><a href="tqsocket.html#writeBlock">writeBlock</a>( cmd.<a href="tqstring.html#latin1">latin1</a>(), cmd.<a href="tqstring.html#length">length</a>() ); // read the head of the article cmd = "article " + file + "\r\n"; - commandSocket-><a href="ntqsocket.html#writeBlock">writeBlock</a>( cmd.<a href="tqstring.html#latin1">latin1</a>(), cmd.<a href="tqstring.html#length">length</a>() ); + commandSocket-><a href="tqsocket.html#writeBlock">writeBlock</a>( cmd.<a href="tqstring.html#latin1">latin1</a>(), cmd.<a href="tqstring.html#length">length</a>() ); readArticle = TRUE; } -<a name="x673"></a>bool Nntp::<a href="ntqnetworkprotocol.html#checkConnection">checkConnection</a>( <a href="qnetworkoperation.html">TQNetworkOperation</a> * ) +<a name="x673"></a>bool Nntp::<a href="tqnetworkprotocol.html#checkConnection">checkConnection</a>( <a href="tqnetworkoperation.html">TQNetworkOperation</a> * ) { // we are connected, return TRUE -<a name="x670"></a> if ( commandSocket-><a href="ntqiodevice.html#isOpen">isOpen</a>() && connectionReady ) +<a name="x670"></a> if ( commandSocket-><a href="tqiodevice.html#isOpen">isOpen</a>() && connectionReady ) return TRUE; // seems that there is no chance to connect - if ( commandSocket-><a href="ntqiodevice.html#isOpen">isOpen</a>() ) + if ( commandSocket-><a href="tqiodevice.html#isOpen">isOpen</a>() ) return FALSE; // don't call connectToHost() if we are already trying to connect -<a name="x688"></a> if ( commandSocket-><a href="ntqsocket.html#state">state</a>() == TQSocket::Connecting ) +<a name="x688"></a> if ( commandSocket-><a href="tqsocket.html#state">state</a>() == TQSocket::Connecting ) return FALSE; // start connecting connectionReady = FALSE; -<a name="x680"></a> commandSocket-><a href="ntqsocket.html#connectToHost">connectToHost</a>( <a href="ntqnetworkprotocol.html#url">url</a>()->host(), - <a href="ntqnetworkprotocol.html#url">url</a>()->port() != -1 ? url()->port() : 119 ); +<a name="x680"></a> commandSocket-><a href="tqsocket.html#connectToHost">connectToHost</a>( <a href="tqnetworkprotocol.html#url">url</a>()->host(), + <a href="tqnetworkprotocol.html#url">url</a>()->port() != -1 ? url()->port() : 119 ); return FALSE; } void <a name="f289"></a>Nntp::close() { // close the command socket - if ( commandSocket-><a href="ntqiodevice.html#isOpen">isOpen</a>() ) { - commandSocket-><a href="ntqsocket.html#writeBlock">writeBlock</a>( "quit\r\n", strlen( "quit\r\n" ) ); -<a name="x679"></a> commandSocket-><a href="ntqsocket.html#close">close</a>(); + if ( commandSocket-><a href="tqiodevice.html#isOpen">isOpen</a>() ) { + commandSocket-><a href="tqsocket.html#writeBlock">writeBlock</a>( "quit\r\n", strlen( "quit\r\n" ) ); +<a name="x679"></a> commandSocket-><a href="tqsocket.html#close">close</a>(); } } -<a name="x676"></a>int Nntp::<a href="ntqnetworkprotocol.html#supportedOperations">supportedOperations</a>() const +<a name="x676"></a>int Nntp::<a href="tqnetworkprotocol.html#supportedOperations">supportedOperations</a>() const { // we only support listing children and getting data return OpListChildren | OpGet; @@ -212,24 +212,24 @@ void <a name="f289"></a>Nntp::close() void <a name="f290"></a>Nntp::hostFound() { - if ( <a href="ntqnetworkprotocol.html#url">url</a>() ) - emit connectionStateChanged( ConHostFound, tr( "Host %1 found" ).arg( <a href="ntqnetworkprotocol.html#url">url</a>()->host() ) ); + if ( <a href="tqnetworkprotocol.html#url">url</a>() ) + emit connectionStateChanged( ConHostFound, tr( "Host %1 found" ).arg( <a href="tqnetworkprotocol.html#url">url</a>()->host() ) ); else emit connectionStateChanged( ConHostFound, tr( "Host found" ) ); } void <a name="f291"></a>Nntp::connected() { - if ( <a href="ntqnetworkprotocol.html#url">url</a>() ) - emit connectionStateChanged( ConConnected, tr( "Connected to host %1" ).arg( <a href="ntqnetworkprotocol.html#url">url</a>()->host() ) ); + if ( <a href="tqnetworkprotocol.html#url">url</a>() ) + emit connectionStateChanged( ConConnected, tr( "Connected to host %1" ).arg( <a href="tqnetworkprotocol.html#url">url</a>()->host() ) ); else emit connectionStateChanged( ConConnected, tr( "Connected to host" ) ); } void <a name="f292"></a>Nntp::closed() { - if ( <a href="ntqnetworkprotocol.html#url">url</a>() ) - emit connectionStateChanged( ConClosed, tr( "Connection to %1 closed" ).arg( <a href="ntqnetworkprotocol.html#url">url</a>()->host() ) ); + if ( <a href="tqnetworkprotocol.html#url">url</a>() ) + emit connectionStateChanged( ConClosed, tr( "Connection to %1 closed" ).arg( <a href="tqnetworkprotocol.html#url">url</a>()->host() ) ); else emit connectionStateChanged( ConClosed, tr( "Connection closed" ) ); } @@ -252,8 +252,8 @@ void <a name="f293"></a>Nntp::readyRead() // read the new data from the socket <a href="tqcstring.html">TQCString</a> s; -<a name="x677"></a><a name="x668"></a> s.<a href="tqcstring.html#resize">resize</a>( commandSocket-><a href="ntqsocket.html#bytesAvailable">bytesAvailable</a>() + 1 ); -<a name="x685"></a><a name="x671"></a> commandSocket-><a href="ntqsocket.html#readBlock">readBlock</a>( s.<a href="tqmemarray.html#data">data</a>(), commandSocket-><a href="ntqsocket.html#bytesAvailable">bytesAvailable</a>() ); +<a name="x677"></a><a name="x668"></a> s.<a href="tqcstring.html#resize">resize</a>( commandSocket-><a href="tqsocket.html#bytesAvailable">bytesAvailable</a>() + 1 ); +<a name="x685"></a><a name="x671"></a> commandSocket-><a href="tqsocket.html#readBlock">readBlock</a>( s.<a href="tqmemarray.html#data">data</a>(), commandSocket-><a href="tqsocket.html#bytesAvailable">bytesAvailable</a>() ); if ( !url() ) return; @@ -266,19 +266,19 @@ void <a name="f293"></a>Nntp::readyRead() void <a name="f294"></a>Nntp::parseGroups() { -<a name="x678"></a> if ( !commandSocket-><a href="ntqsocket.html#canReadLine">canReadLine</a>() ) +<a name="x678"></a> if ( !commandSocket-><a href="tqsocket.html#canReadLine">canReadLine</a>() ) return; // read one line after the other - while ( commandSocket-><a href="ntqsocket.html#canReadLine">canReadLine</a>() ) { -<a name="x686"></a> <a href="tqstring.html">TQString</a> s = commandSocket-><a href="ntqsocket.html#readLine">readLine</a>(); + while ( commandSocket-><a href="tqsocket.html#canReadLine">canReadLine</a>() ) { +<a name="x686"></a> <a href="tqstring.html">TQString</a> s = commandSocket-><a href="tqsocket.html#readLine">readLine</a>(); // if the line starts with a dot, all groups or articles have been listed, // so we finished processing the listChildren() command if ( s[ 0 ] == '.' ) { readGroups = FALSE; - <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StDone ); - emit finished( <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); + <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StDone ); + emit finished( <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); return; } @@ -286,8 +286,8 @@ void <a name="f294"></a>Nntp::parseGroups() // the next line will be the first group or article (depending on what we read). // So let others know that we start reading now... if ( s.<a href="tqcstring.html#left">left</a>( 3 ) == "215" || s.<a href="tqcstring.html#left">left</a>( 3 ) == "211" ) { - <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StInProgress ); - emit start( <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); + <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StInProgress ); + emit start( <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); continue; } @@ -295,14 +295,14 @@ void <a name="f294"></a>Nntp::parseGroups() // which describes the child (group or article) <a name="x663"></a> bool tab = s.<a href="tqcstring.html#find">find</a>( '\t' ) != -1; <a name="x666"></a> <a href="tqstring.html">TQString</a> group = s.<a href="tqcstring.html#mid">mid</a>( 0, s.<a href="tqcstring.html#find">find</a>( tab ? '\t' : ' ' ) ); - <a href="ntqurlinfo.html">TQUrlInfo</a> inf; -<a name="x700"></a> inf.<a href="ntqurlinfo.html#setName">setName</a>( group ); - <a href="tqstring.html">TQString</a> path = <a href="ntqnetworkprotocol.html#url">url</a>()->path(); -<a name="x698"></a> inf.<a href="ntqurlinfo.html#setDir">setDir</a>( path.<a href="tqstring.html#isEmpty">isEmpty</a>() || path == "/" ); -<a name="x702"></a> inf.<a href="ntqurlinfo.html#setSymLink">setSymLink</a>( FALSE ); -<a name="x699"></a><a name="x697"></a> inf.<a href="ntqurlinfo.html#setFile">setFile</a>( !inf.<a href="ntqurlinfo.html#isDir">isDir</a>() ); -<a name="x703"></a> inf.<a href="ntqurlinfo.html#setWritable">setWritable</a>( FALSE ); -<a name="x701"></a> inf.<a href="ntqurlinfo.html#setReadable">setReadable</a>( TRUE ); + <a href="tqurlinfo.html">TQUrlInfo</a> inf; +<a name="x700"></a> inf.<a href="tqurlinfo.html#setName">setName</a>( group ); + <a href="tqstring.html">TQString</a> path = <a href="tqnetworkprotocol.html#url">url</a>()->path(); +<a name="x698"></a> inf.<a href="tqurlinfo.html#setDir">setDir</a>( path.<a href="tqstring.html#isEmpty">isEmpty</a>() || path == "/" ); +<a name="x702"></a> inf.<a href="tqurlinfo.html#setSymLink">setSymLink</a>( FALSE ); +<a name="x699"></a><a name="x697"></a> inf.<a href="tqurlinfo.html#setFile">setFile</a>( !inf.<a href="tqurlinfo.html#isDir">isDir</a>() ); +<a name="x703"></a> inf.<a href="tqurlinfo.html#setWritable">setWritable</a>( FALSE ); +<a name="x701"></a> inf.<a href="tqurlinfo.html#setReadable">setReadable</a>( TRUE ); // let others know about our new child emit newChild( inf, operationInProgress() ); @@ -312,18 +312,18 @@ void <a name="f294"></a>Nntp::parseGroups() void <a name="f295"></a>Nntp::parseArticle() { - if ( !commandSocket-><a href="ntqsocket.html#canReadLine">canReadLine</a>() ) + if ( !commandSocket-><a href="tqsocket.html#canReadLine">canReadLine</a>() ) return; // read an article one line after the other - while ( commandSocket-><a href="ntqsocket.html#canReadLine">canReadLine</a>() ) { - <a href="tqstring.html">TQString</a> s = commandSocket-><a href="ntqsocket.html#readLine">readLine</a>(); + while ( commandSocket-><a href="tqsocket.html#canReadLine">canReadLine</a>() ) { + <a href="tqstring.html">TQString</a> s = commandSocket-><a href="tqsocket.html#readLine">readLine</a>(); // if the line starts with a dot, we finished reading something if ( s[ 0 ] == '.' ) { readArticle = FALSE; - <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StDone ); - emit finished( <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); + <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StDone ); + emit finished( <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); return; } @@ -340,13 +340,13 @@ void <a name="f296"></a>Nntp::error( int code ) if ( code == TQSocket::ErrHostNotFound || code == TQSocket::ErrConnectionRefused ) { // this signal is called if connecting to the server failed - if ( <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ) { + if ( <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ) { <a href="tqstring.html">TQString</a> msg = <a href="tqobject.html#tr">tr</a>( "Host not found or couldn't connect to: \n" + url()->host() ); - <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StFailed ); - <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setProtocolDetail( msg ); - <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setErrorCode( (int)ErrHostNotFound ); - <a href="ntqnetworkprotocol.html#clearOperationQueue">clearOperationQueue</a>(); - emit finished( <a href="ntqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); + <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setState( StFailed ); + <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setProtocolDetail( msg ); + <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>()->setErrorCode( (int)ErrHostNotFound ); + <a href="tqnetworkprotocol.html#clearOperationQueue">clearOperationQueue</a>(); + emit finished( <a href="tqnetworkprotocol.html#operationInProgress">operationInProgress</a>() ); } } } |