bool HTTPClient::Clean(void* _ptr) { if(curl) { if(!is_raise_error_multi_handle) curl_multi_remove_handle(HTTPManager::Share()->GetCURLMulti(), curl); curl_easy_cleanup(curl); curl = NULL; } if(header_chunk) { curl_slist_free_all(header_chunk); header_chunk = NULL; } if(http_post) { curl_formfree(http_post); http_post = NULL; } if(body.is_open()) { body.close(); CLOSE_FD(); } if(header.is_open()) { header.close(); CLOSE_FD(); } if(access(body_file_path.c_str(), F_OK) == 0) remove(body_file_path.c_str()); if(access(header_file_path.c_str(), F_OK) == 0) remove(header_file_path.c_str()); return true; }
void HTTPClient::MessageReciever(CURLcode _code) { if(header.is_open()) { header.close(); CLOSE_FD(); } if(body.is_open()) { body.close(); CLOSE_FD(); } code = _code; is_recieve = true; }
int im_bsd_close (struct i_module *im) { CLOSE_FD(im->im_fd); return (0); }
void StreamClient::teardown(bool gracefull) { _watchdog = 0; _canClose = true; if (!gracefull) { _sessionID = "-1"; _ip_addr = "0.0.0.0"; CLOSE_FD(_rtspFD); } _rtspFD = -1; }
int readlines(char *lineptr[], int maxlines) { int len, nlines; char *p, line[MAXLEN]; OPEN_FD(); nlines = 0; while ((len = _getline(line, MAXLEN)) > 1) if (nlines >= MAXLINES ) { CLOSE_FD(); return nlines*(-1) - 1; } else if(!(p=malloc(len))) { CLOSE_FD(); return nlines*(-1) - 1; } else { line[len - 1] = '\0'; strcpy(p, line); int ans; int ff=myAtoi(p,&ans); if(numeric) { myItoa(ans,p); } if(numeric && ff==-1) { drop_error_string_format(); CLOSE_FD(); free(p); strcpy(line,""); return nlines*(-1) - 1; } lineptr[nlines++] = p; } CLOSE_FD(); return nlines; }
int om_udp_close(struct filed *f, void *ctx) { struct om_udp_ctx *c; c = (struct om_udp_ctx *) ctx; FREE_PTR(c->host); FREE_PTR(c->port); FREE_PTR(c->addr); CLOSE_FD(c->fd); return (1); }
int HttpServer::readFile(const char *file, std::string &data) { int file_size = 0; int fd_file; if ((fd_file = open(file, O_RDONLY | O_NONBLOCK)) < 0) { SI_LOG_ERROR("readFile %s", file); PERROR("File not found"); return 0; } const off_t size = lseek(fd_file, 0, SEEK_END); lseek(fd_file, 0, SEEK_SET); char *buf = new char[size]; if (buf != nullptr) { file_size = read(fd_file, buf, size); data.assign(buf, file_size); DELETE_ARRAY(buf); } CLOSE_FD(fd_file); // SI_LOG_DEBUG("GET %s (size %d)", file, file_size); return file_size; }
bool HTTPClient::UpdateDB() { if(!is_recieve) return false; if(code != CURLE_OK) return false; if(header.is_open()) { header.close(); CLOSE_FD(); } if(body.is_open()) { body.close(); CLOSE_FD(); } if(request.GetUseCache()) { if(request.force_max_age > 0) { max_age = request.force_max_age; if(expires == 0 && max_age != 0) { expires = HTTP::CurrentTime() + max_age; } } } std::stringstream _query; bool _need_update = false; bool _is_insert = false; if(cache_type == HTTPResponse::CacheType_None) { if(!db_id.length()) { _query << "INSERT OR REPLACE INTO request (url, Expires, Last_Modified, Last_Updated, Max_Age) VALUES ('" << request.url << "', '" << expires << "', '" << last_modified << "', '" << last_updated << "', '" << max_age << "')"; _is_insert = true; } else { _query << "UPDATE request SET Expires='" << expires << "', Last_Modified='" << last_modified << "', Last_Updated='" << last_updated << "', Max_Age='" << max_age << "' WHERE id='" << db_id << "'"; } _need_update = true; } else if(cache_type == HTTPResponse::CacheType_Last_Modified) { if(last_modified && db_last_modified) { if(last_modified != db_last_modified) { _query << "UPDATE request SET Last_Modified='" << last_modified << "', Last_Updated='" << last_updated << "' WHERE id='" << db_id << "'"; _need_update = true; } } } if(!_need_update) { return false; } sqlite3* _db = NULL; char* _db_message = NULL; HTTP_DEBUG((sqlite3_open(HTTPManager::Share()->GetDBPath().c_str(), &_db)), "열기실패" << "\nError Message:" << sqlite3_errmsg(_db) << "\n"); HTTP_DEBUG((sqlite3_exec(_db, _query.str().c_str(), NULL, NULL, &_db_message)), "error:" << _db_message); if(_is_insert) { _query.str(""); _query << "SELECT * FROM request WHERE url='" << request.url << "' LIMIT 1"; HTTP_DEBUG((sqlite3_exec(_db, _query.str().c_str(), SQLMatchURLCallback, this, &_db_message)), "sqllite 디비 검색에 실패하였습니다." << "\nError Message:" << _db_message); } HTTP_DEBUG((sqlite3_close(_db)), "닫기실패" << "\nError Message:" << sqlite3_errmsg(_db) << "\n"); rename(header_file_path.c_str(), cache_header_file_path.c_str()); rename(body_file_path.c_str(), cache_body_file_path.c_str()); response = HTTPResponse(cache_header_file_path, cache_body_file_path, cache_type); return true; }