BString.cpp File Reference#include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string> #include <vector> #include <map> #include <openssl/sha.h> #include "BTObject.h" #include "BTDictionary.h" #include "BTList.h" #include "BTInteger.h" #include "BTString.h" #include "BString.h" #include "ParseBT.h" #include "BTException.h" Include dependency graph for BString.cpp: Go to the source code of this file.
Define Documentation
File ......... BString.cpp Published .... 2005-06-14 Author ....... grymse@alhem.net Definition at line 48 of file BString.cpp. Referenced by Session::AddFile(), PeerHandler::CheckDownloadRate(), pSocket::cmdBitfield(), pSocket::cmdCancel(), pSocket::cmdChoke(), pSocket::cmdHave(), pSocket::cmdInterested(), pSocket::cmdNotinterested(), pSocket::cmdPiece(), pSocket::cmdRequest(), pSocket::cmdUnchoke(), BString::End(), StatusSocket::Exec(), FileManager::FileManager(), StatusSocket::FormInput(), ParseBT::getword(), MetainfoSocket::InitSession(), MetainfoSocket::MetainfoSocket(), pSocket::OnAccept(), MetainfoSocket::OnAccept(), pSocket::OnConnect(), MetainfoSocket::OnConnect(), tSocket::OnDelete(), pSocket::OnDelete(), MetainfoSocket::OnDelete(), tSocket::OnFirst(), tSocket::OnHeader(), pSocket::OnRead(), MetainfoSocket::OnRead(), FileManager::OpenFiles(), Peer::Peer(), FileManager::ReadPiece(), Session::Save(), pSocket::SendBitmap(), pSocket::SendCancel(), pSocket::SendChoke(), pSocket::SendHave(), pSocket::SendHello(), pSocket::SendInterest(), pSocket::SendPiece(), pSocket::SendRequest(), Session::Session(), tSocket::tSocket(), Session::Update(), FileManager::Verify(), FileManager::Write(), FileManager::~FileManager(), MetainfoSocket::~MetainfoSocket(), and tSocket::~tSocket().
Function Documentation
Definition at line 103 of file BString.cpp. 00108 { 00109 for (int i = 0; i < x; i++) 00110 printf(" "); 00111 } 00112 ) 00113 00114 00115 bool BString::reg_char(char c) 00116 { 00117 m_bstring += c; 00118 switch (m_state) 00119 { 00120 case 0: // 00121 switch (c) 00122 { 00123 case 'd': // dictionary 00124 DEB( lt[lvl] = c; 00125 lvl++; 00126 plvl(lvl); 00127 printf("Dictionary\n");) 00128 00129 AddDictionary(); 00130 break; 00131 case 'l': // list 00132 DEB( lt[lvl] = c; 00133 lvl++; 00134 plvl(lvl); 00135 printf("List\n");) 00136 00137 AddList(); 00138 break; 00139 case 'i': // integer 00140 DEB( plvl(lvl); 00141 printf(" Integer");) 00142 00143 m_state = 1; 00144 m_str = ""; 00145 break; 00146 case 'e': // lvl end 00147 DEB( if (lvl) 00148 { 00149 lvl--; 00150 plvl(lvl + 1); 00151 printf("End of %s\n",(lt[lvl] == 'd') ? "Dictionary" : 00152 (lt[lvl] == 'l') ? "List" : "<err>"); 00153 }) 00154 End(); 00155 break; 00156 00157 default: 00158 if (!isdigit(c)) 00159 { 00160 // assert(!"no good"); 00161 throw(BTException("Digit expected")); 00162 } 00163 // string 00164 DEB( plvl(lvl); 00165 printf(" String");) 00166 00167 m_state = 2; 00168 m_str = c; 00169 } 00170 break; 00171 case 1: // read integer 00172 if (c == 'e') 00173 { 00174 DEB( printf(" value '%s'\n",m_str.c_str());) 00175 00176 m_state = 0; 00177 AddInteger( m_str ); 00178 } 00179 else 00180 { 00181 m_str += c; 00182 } 00183 break; 00184 case 2: // read string length 00185 if (isdigit(c)) 00186 { 00187 m_str += c; 00188 } 00189 else 00190 { 00191 m_strlen = atoi(m_str.c_str()); 00192 m_str = ""; 00193 DEB( printf(" (length %d)",m_strlen);) 00194 00195 // assert(c == ':'); 00196 if (c != ':') 00197 { 00198 throw(BTException("':' expected")); 00199 } 00200 if (m_strlen) 00201 { 00202 m_state = 3; 00203 } 00204 else 00205 { 00206 // add empty string 00207 DEB( printf(" '%s' (%d)\n",printable(m_str).c_str(),m_str.size());) 00208 00209 m_state = 0; 00210 AddString( m_str ); 00211 } 00212 } 00213 break; 00214 case 3: // read string 00215 m_str += c; 00216 m_strlen--; 00217 if (m_strlen <= 0) 00218 { 00219 DEB( printf(" '%s' (%d)\n",printable(m_str).c_str(),m_str.size());) 00220 00221 m_state = 0; 00222 AddString( m_str ); 00223 } 00224 break; 00225 } 00226 m_current -> Increase(); 00227 m_bindex++; 00228 return true; 00229 }
|