MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / PrepSocket

Method PrepSocket

legacy/inetfile/Chttpget.cpp:193–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193void ChttpGet::PrepSocket(char *URL) {
194
195 m_DataSock = socket(AF_INET, SOCK_STREAM, 0);
196 if (INVALID_SOCKET == m_DataSock) {
197 m_State = HTTP_STATE_SOCKET_ERROR;
198 return;
199 }
200
201 make_nonblocking(m_DataSock);
202
203 char *pURL = URL;
204 if (strnicmp(URL, "http:", 5) == 0) {
205 pURL += 5;
206 while (*pURL == '/') {
207 pURL++;
208 }
209 }
210 // There shouldn't be any : in this string
211 if (strchr(pURL, ':')) {
212 m_State = HTTP_STATE_URL_PARSING_ERROR;
213 return;
214 }
215 // read the filename by searching backwards for a /
216 // then keep reading until you find the first /
217 // when you found it, you have the host and dir
218 char *filestart = NULL;
219 char *dirstart;
220 for (int i = strlen(pURL); i >= 0; i--) {
221 if (pURL[i] == '/') {
222 if (!filestart) {
223 filestart = pURL + i + 1;
224 dirstart = pURL + i + 1;
225 strcpy(m_szFilename, filestart);
226 } else {
227 dirstart = pURL + i + 1;
228 }
229 }
230 }
231 if ((dirstart == NULL) || (filestart == NULL)) {
232 m_State = HTTP_STATE_URL_PARSING_ERROR;
233 return;
234 } else {
235 strcpy(m_szDir, dirstart); //,(filestart-dirstart));
236 // m_szDir[(filestart-dirstart)] = NULL;
237 strncpy(m_szHost, pURL, (dirstart - pURL));
238 m_szHost[(dirstart - pURL) - 1] = '\0';
239 }
240}
241
242void ChttpGet::GetFile(char *URL, char *localfile) {
243 m_DataSock = INVALID_SOCKET;

Callers

nothing calls this directly

Calls 1

make_nonblockingFunction · 0.85

Tested by

no test coverage detected