Removed non-const pointer-returning methods from Url class

This commit is contained in:
Ivan Skytte Jørgensen 2018-08-24 13:37:43 +02:00
parent e90f690c0d
commit 8b335971fa
7 changed files with 30 additions and 35 deletions

@ -658,7 +658,7 @@ bool Images::downloadImage ( ) {
r->m_maxOtherDocLen = 500000;
r->m_urlIp = m_latestIp;
// url is the most important
r-> ptr_url = m_imageUrl.getUrl();
r->ptr_url = const_cast<char*>(m_imageUrl.getUrl());
r->size_url = m_imageUrl.getUrlLen()+1; // include \0
// . try to download it
// . i guess we are ignoring hammers at this point

@ -569,7 +569,7 @@ bool isPermalink (
class LinkInfo *linkInfo ,
bool isRSS ,
const char **note = NULL ,
char *pathOverride= NULL ,
const char *pathOverride= NULL,
bool ignoreCgi = false ,
linkflags_t *extraFlags = NULL ) ;

@ -4169,7 +4169,7 @@ bool Links::addLink(const char *link, int32_t linkLen, int32_t nodeNum,
// href="...ami.php?url=http://lewebpedagogique.com/blog/2008/11/16/
// la-seconde-guerre-mondiale-cours ... will have its cgi ignored so
// such links as this one will not be considered permalinks
char *pathOverride = NULL;
const char *pathOverride = NULL;
bool ignoreCgi = false;
if ( (flags & LF_SUBDIR) && m_parentIsPermalink ) {
pathOverride = url.getUrl() + m_parentUrl->getUrlLen();
@ -4656,10 +4656,11 @@ bool isPermalink(Links *links,
LinkInfo *linkInfo,
bool isRSS,
const char **note,
char *pathOverride,
const char *pathOverride,
bool ignoreCgi,
linkflags_t *retFlags) {
// reset. caller will OR these into its flags
if ( retFlags ) *retFlags = 0;
@ -4718,7 +4719,7 @@ bool isPermalink(Links *links,
if ( status == 1 ) return true;
if ( status == 0 ) return false;
char *pathStart = u->getPath();
const char *pathStart = u->getPath();
// a hack by Links.cpp after setting LF_SUBDIR
if ( pathOverride ) pathStart = pathOverride;
@ -4726,14 +4727,14 @@ bool isPermalink(Links *links,
linkflags_t extraFlags = 0;
// we must have a sequence of 3 or more digits in the path
char *p = pathStart;
const char *p = pathStart;
int32_t plen = u->getPathLen();
char *pend = u->getPath() + plen;
const char *pend = u->getPath() + plen;
int32_t dcount = 0;
// now we scan the cgi stuff too!!
// http://www.rocklintoday.com/news/templates/sierra_college.asp?articleid=6848&zoneid=51
// http://www.freemarketnews.com/WorldNews.asp?nid=57373
char *uend = u->getUrl() + u->getUrlLen();
const char *uend = u->getUrl() + u->getUrlLen();
// halt at path if we should
if ( ignoreCgi ) uend -= u->getQueryLen(); // CgiLen();
// see if we find the digits in the cgi part
@ -4923,7 +4924,7 @@ bool isPermalink(Links *links,
}
char *pos;
const char *pos;
// category or tag page detection
pos = gb_strcasestr(u->getUrl(), "cat=");
if ( pos && pos > u->getUrl() && !is_alpha_a(*(pos-1))){

@ -1306,7 +1306,7 @@ bool Msg8a::getTagRec( Url *url, collnum_t collnum, int32_t niceness, void *stat
m_url = url;
// point to url
char *u = url->getUrl();
const char *u = url->getUrl();
int32_t ulen = url->getUrlLen();
// point to the TLD of the url

6
Url.h

@ -102,14 +102,12 @@ public:
int32_t getIp() const { return m_ip; }
char *getUrl() { return m_url; }
const char *getUrl() const { return m_url; }
int32_t getUrlLen() const { return m_ulen; }
const char *getScheme() const { return m_scheme; }
int32_t getSchemeLen() const { return m_slen; }
//char *getHost() { return m_host; }
const char *getHost() const { return m_host; }
int32_t getHostLen() const { return m_hlen; }
@ -123,20 +121,16 @@ public:
const char *getMidDomain() const { return m_domain; }
int32_t getMidDomainLen() const { return m_mdlen; }
char *getPath() { return m_path; }
const char *getPath() const { return m_path; }
int32_t getPathLen() const { return m_plen; }
char *getPathEnd() { return m_path + m_plen; }
const char *getPathEnd() const { return m_path + m_plen; }
char *getFilename() { return m_filename; }
const char *getFilename() const { return m_filename; }
int32_t getFilenameLen() const { return m_flen; }
const char *getExtension() const { return m_extension; }
int32_t getExtensionLen() const { return m_elen; }
char *getQuery() { return m_query; }
const char *getQuery() const { return m_query; }
int32_t getQueryLen() const { return m_qlen; }

@ -1228,7 +1228,7 @@ bool XmlDoc::setFirstUrl ( const char *u ) {
m_currentUrlValid = true;
// set this to the normalized url
ptr_firstUrl = m_firstUrl.getUrl();
ptr_firstUrl = const_cast<char*>(m_firstUrl.getUrl());
size_firstUrl = m_firstUrl.getUrlLen() + 1;
return true;
@ -1460,14 +1460,14 @@ bool XmlDoc::injectDoc(const char *url,
m_canonicalRedirUrlValid = true;
// store canonical url in titlerec as well
ptr_redirUrl = m_canonicalUrl.getUrl();
ptr_redirUrl = const_cast<char*>(m_canonicalUrl.getUrl());
size_redirUrl = m_canonicalUrl.getUrlLen()+1;
} else {
m_redirUrl.set(redirUrl);
m_redirUrlPtr = &m_redirUrl;
m_redirUrlValid = true;
ptr_redirUrl = m_redirUrl.getUrl();
ptr_redirUrl = const_cast<char*>(m_redirUrl.getUrl());
size_redirUrl = m_redirUrl.getUrlLen() + 1;
if (indexCode == 0) {
@ -2602,7 +2602,7 @@ int32_t *XmlDoc::getIndexCode ( ) {
m_indexCodeValid = true;
// store canonical url in titlerec as well
ptr_redirUrl = m_canonicalUrl.getUrl();
ptr_redirUrl = const_cast<char*>(m_canonicalUrl.getUrl());
size_redirUrl = m_canonicalUrl.getUrlLen()+1;
// make sure we store an empty document
@ -3387,7 +3387,7 @@ bool *XmlDoc::getIsSiteMap ( ) {
if ( m_isSiteMapValid ) return &m_isSiteMap;
uint8_t *ct = getContentType();
if ( ! ct || ct == (uint8_t *)-1 ) return (bool *)ct;
char *uf = m_firstUrl.getFilename();
const char *uf = m_firstUrl.getFilename();
int32_t ulen = m_firstUrl.getFilenameLen();
// sitemap.xml
m_isSiteMap = false;
@ -5564,7 +5564,7 @@ Url **XmlDoc::getRedirUrl() {
if ( strcmp ( cu->getUrl(), tt->getUrl() ) != 0 ) {
m_redirUrlValid = true;
m_redirUrlPtr = &m_redirUrl;
ptr_redirUrl = m_redirUrl.getUrl();
ptr_redirUrl = const_cast<char*>(m_redirUrl.getUrl());
size_redirUrl = m_redirUrl.getUrlLen()+1;
/// @todo ALC should we use EDOCSIMPLIFIEDREDIR
@ -5687,7 +5687,7 @@ Url **XmlDoc::getRedirUrl() {
if (httpStatus != 301 && httpStatus != 308 && !sameDom) {
m_redirUrl.set(loc->getUrl(), loc->getUrlLen(), false, true);
m_redirUrlPtr = &m_redirUrl;
ptr_redirUrl = m_redirUrl.getUrl();
ptr_redirUrl = const_cast<char*>(m_redirUrl.getUrl());
size_redirUrl = m_redirUrl.getUrlLen()+1;
logTrace( g_conf.m_logTraceXmlDoc, "END, return redirUrl. Not same domain [%s]", m_redirUrlPtr->getUrl());
return &m_redirUrlPtr;
@ -5705,7 +5705,7 @@ Url **XmlDoc::getRedirUrl() {
// . or one with a www for hostname
// . or could be same as firstUrl but with a / appended
const char *r = loc->getUrl();
char *u = f->getUrl();
const char *u = f->getUrl();
int32_t rlen = loc->getUrlLen();
int32_t ulen = f->getUrlLen();
@ -5811,7 +5811,7 @@ Url **XmlDoc::getRedirUrl() {
m_redirUrlPtr = &m_redirUrl;
// store redirUrl in titlerec as well
ptr_redirUrl = m_redirUrl.getUrl();
ptr_redirUrl = const_cast<char*>(m_redirUrl.getUrl());
size_redirUrl = m_redirUrl.getUrlLen() + 1;
// make sure we store an empty document
@ -5832,7 +5832,7 @@ Url **XmlDoc::getRedirUrl() {
// good to go
m_redirUrl.set(loc->getUrl(), loc->getUrlLen(), false, true);
m_redirUrlPtr = &m_redirUrl;
ptr_redirUrl = m_redirUrl.getUrl();
ptr_redirUrl = const_cast<char*>(m_redirUrl.getUrl());
size_redirUrl = m_redirUrl.getUrlLen()+1;
logTrace( g_conf.m_logTraceXmlDoc, "END, return [%s]", m_redirUrlPtr->getUrl());
return &m_redirUrlPtr;
@ -6356,7 +6356,7 @@ char **XmlDoc::getOldTitleRec() {
docId = m_docId;
}
// if url not valid, use NULL
char *u = NULL;
const char *u = NULL;
if (docId == 0LL) {
if (ptr_firstUrl || m_firstUrlValid) {
u = getFirstUrl()->getUrl();
@ -6502,7 +6502,7 @@ int64_t *XmlDoc::getDocId ( ) {
}
// ensure it is within probable range
char *u = getFirstUrl()->getUrl();
const char *u = getFirstUrl()->getUrl();
int64_t pd = Titledb::getProbableDocId(u);
int64_t d1 = Titledb::getFirstProbableDocId ( pd );
int64_t d2 = Titledb::getLastProbableDocId ( pd );
@ -7840,7 +7840,7 @@ LinkInfo *XmlDoc::getLinkInfo1 ( ) {
bool oneVotePerIpDom = cr->m_oneVotePerIpDom;
// call it. this is defined in Linkdb.cpp
char *url = getFirstUrl()->getUrl();
const char *url = getFirstUrl()->getUrl();
if ( ! getLinkInfo ( &m_tmpBuf12,
&m_mcast12,
mysite ,
@ -8300,7 +8300,7 @@ char **XmlDoc::getHttpReply2 ( ) {
// clear it first
r->reset();
// and set the url
r->ptr_url = cu->getUrl();
r->ptr_url = const_cast<char*>(cu->getUrl());
r->size_url = cu->getUrlLen()+1;
// sanity check
@ -11609,7 +11609,7 @@ void XmlDoc::logIt (SafeBuf *bb ) {
if ( m_docIdValid )
sb->safePrintf("docid=%" PRIu64" ",m_docId);
char *u = getFirstUrl()->getUrl();
const char *u = getFirstUrl()->getUrl();
int64_t pd = Titledb::getProbableDocId(u);
int64_t d1 = Titledb::getFirstProbableDocId ( pd );
int64_t d2 = Titledb::getLastProbableDocId ( pd );
@ -15454,7 +15454,7 @@ Msg20Reply *XmlDoc::getMsg20ReplyStepwise() {
// done if we are
if ( m_reply.m_errno && ! m_req->m_showBanned ) {
// give back the url at least
m_reply.ptr_ubuf = getFirstUrl()->getUrl();
m_reply.ptr_ubuf = const_cast<char*>(getFirstUrl()->getUrl());
m_reply.size_ubuf = getFirstUrl()->getUrlLen() + 1;
m_replyValid = true;
return &m_reply;
@ -15643,7 +15643,7 @@ Msg20Reply *XmlDoc::getMsg20ReplyStepwise() {
m_reply.m_siteRank = getSiteRank();
m_reply.m_isAdult = m_isAdult; //QQQ getIsAdult()? hmmm
m_reply.ptr_ubuf = getFirstUrl()->getUrl();
m_reply.ptr_ubuf = const_cast<char*>(getFirstUrl()->getUrl());
m_reply.ptr_rubuf = ru;
m_reply.ptr_metadataBuf = NULL;

@ -236,7 +236,7 @@ bool XmlDoc::hashNoSplit ( HashTableX *tt ) {
//
// these are now no-split terms
//
char *s = fu->getUrl ();
const char *s = fu->getUrl();
int32_t slen = fu->getUrlLen();
// . this termId is used by SiteGetter.cpp for determining subsites
// . matches what is in SiteGet::getSiteList()
@ -259,7 +259,7 @@ bool XmlDoc::hashNoSplit ( HashTableX *tt ) {
// hash it
if ( add ) {
// remove the last path component
char *end2 = s + slen - 2;
const char *end2 = s + slen - 2;
// back up over last component
for ( ; end2 > fu->getPath() && *end2 != '/' ; end2-- ) ;
// hash that part of the url