CString CMail::MPGroup(const CString& iStr, int& curPos){ /* group = phrase ":" [#mailbox] ";" */ #ifdef M_DEBUG cout << "MPGroup() - " << curPos << endl; #endif CString Result; CString Phrase = MPPhrase(iStr, curPos); if (!Phrase.StrLength()) return ""; Result+=Phrase; if (iStr[curPos]!=':') return ""; Result+=':'; int workingPos = curPos+1; CString MBox; if (iStr[workingPos]!=',') do { if (iStr[workingPos] == ',') { workingPos++; Result+=','; } MBox = MPMailbox(iStr, curPos); if (MBox.StrLength()) Result+=MBox; else break; } while (iStr[workingPos] == ','); if (iStr[workingPos] == ';'){ Result+=';'; workingPos++; curPos = workingPos; return Result; } else return ""; }
int cgi_admin_manager::write_full_admin(const CString& AdminClass, const CString& Equiv){ if ((!AdminClass.StrLength())||(!Equiv.StrLength())) return 0; if (!equiv_file.StrLength()) { current_cgi_admin_manager = this; equiv_file = entry_manager::make_equiv_path("admin.struct"); } #ifndef ANSI chmod(equiv_file.asString(), _S_IREAD | _S_IWRITE); #endif int hfile2 = v_open(equiv_file.asString(), O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); if (hfile2 == -1) { perror("<br>Error writing admin.struct:"); return 0; } write(hfile2, AdminClass.asString(), AdminClass.StrLength()); write(hfile2, ",", strlen(",")); write(hfile2, Equiv.asString(), Equiv.StrLength()); write(hfile2, "\n", strlen("\n")); close(hfile2); return 1; }
CString CMail::MPDomainLiteral(const CString& iStr, int& curPos){ /* domain-literal = "[" *(dtext / quoted-pair) "]" */ #ifdef M_DEBUG cout << "MPDomainLiteral() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { int workingPos = curPos; if (iStr[workingPos] == '[') { workingPos++; while (workingPos < iStr.StrLength()) { if (MPDtext(iStr, workingPos)) workingPos++; else if (MPQuotedPair(iStr, workingPos)) workingPos++; else break; } if (iStr[workingPos] == ']') { CString Result = iStr.Copy(curPos, workingPos - curPos); curPos = workingPos+1; return Result; } else return ""; } else return ""; } else return ""; }
CString CMail::MPMailbox(const CString& iStr, int& curPos){ /* mailbox = addr-spec ; simple address / phrase route-addr ; name & addr-spec */ #ifdef M_DEBUG cout << "MPMailBox() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { CString ASpec = MPAddressSpec(iStr, curPos); if (!ASpec.StrLength()) { CString Phrase = MPPhrase(iStr, curPos); if (Phrase.StrLength()) { CString RAddr = MPRouteAddr(iStr, curPos); if (RAddr.StrLength()) { CString Result = Phrase; Result+=RAddr; return Result; } else return ""; } else return ""; } else return ASpec; } else return ""; }
void CHttpRequest::ProcessHeader(inetSocket& Sock){ CString Line; RHeaderResponse.clear(); RStatus.Free(); ProcessRStatus((Line = ReadLine(Sock))); if (Line.StrLength()) do { Line = ReadLine(Sock); if (Line.StrLength()) { RHeader+=Line; ProcessOneLine(Line); } } while (Line.StrLength()); }
CString CHttpRequest::ReadRemaining(inetSocket& Sock){ char Buffer[MAX_BUFFER+1]; int Count = 0; CString Result; char c; FD_ZERO(&fdset); FD_SET(Sock.S,&fdset); tv.tv_sec=RTimeout; tv.tv_usec=0; while (select(Sock.S+1, &fdset, NULL, NULL, &tv) >= 0) { if ((FD_ISSET(Sock.S,&fdset))&&(recv(Sock.S, &c, 1, 0))) Buffer[Count++] = c; else break; if (Count == MAX_BUFFER) { Buffer[Count] = 0; Result.StrAppend(Buffer, Count); Count = 0; if ((RLimit > 0)&&(Result.StrLength() >= RLimit)) return Result; } //if (c == EOF) break; } if (Count) { Buffer[Count] = 0; Result.StrAppend(Buffer, Count); } return Result; }
int CHttpRequest::Send(inetSocket& Sock, const CString& Request){ if (send(Sock.S,Request.asString(),Request.StrLength(),0) == -1) { switch(errno) { case EBADF: Sock.wserror("(sending to port) The socket argument is not a valid file descriptor."); break; #ifdef ANSI case ECONNRESET: Sock.wserror("(sending to port) A connection was forcibly closed by a peer."); break; case EDESTADDRREQ: Sock.wserror("(sending to port) The socket is not connection-mode and no peer address is set."); break; case EMSGSIZE: Sock.wserror("(sending to port) The message is too large be sent all at once, as the socket requires."); break; case ENOTCONN: Sock.wserror("(sending to port) The socket is not connected or otherwise has not had the peer prespecified."); break; case ENOTSOCK: Sock.wserror("(sending to port) The socket argument does not refer to a socket."); break; case EOPNOTSUPP: Sock.wserror("(sending to port) The socket argument is associated with a socket that does not support one or more of the values set in flags."); break; case ENETDOWN: Sock.wserror("(sending to port) The local interface used to reach the destination is down."); break; case ENETUNREACH: Sock.wserror("(sending to port) No route to the network is present."); break; case ENOBUFS: Sock.wserror("(sending to port) Insufficient resources were available in the system to perform the operation."); break; #ifdef ENOSR case ENOSR: Sock.wserror("(sending to port) There were insufficient STREAMS resources available for the operation to complete."); break; #endif #endif case EINTR: Sock.wserror("(sending to port) A signal interrupted send() before any data was transmitted."); break; case EPIPE: Sock.wserror("(sending to port) The socket is shut down for writing, or the socket is connection-mode and the peer is closed or shut down for reading. In the latter case, and if the socket is of type SOCK_STREAM, the SIGPIPE signal is generated to the calling process."); break; case EAGAIN: Sock.wserror("(sending to port) The socket's file descriptor is marked O_NONBLOCK and the requested operation would block."); break; case EIO: Sock.wserror("(sending to port) An I/O error occurred while reading from or writing to the file system."); break; default : Sock.wserror("(sending to port) Unexpected error."); break; } RStatusValue = HTTPR_USER + 2; return 0; } else return 1; }
int cgi_access_manager::write_full_access(const CString& Equiv, const CString& Password){ if (!equiv_file.StrLength()) { current_cgi_access_manager = this; equiv_file = entry_manager::make_equiv_path("access.struct"); } #ifndef ANSI chmod(equiv_file.asString(), _S_IREAD | _S_IWRITE); #endif int hfile2 = v_open(equiv_file.asString(), O_WRONLY | O_APPEND | O_CREAT, S_IRWXU); if (hfile2 == -1) { perror("<br>Error writing access.struct:"); return 0; } CString EPassword(Password); write(hfile2, Equiv.asString(), Equiv.StrLength()); write(hfile2, ",", strlen(",")); CString EncryptedPassword(EPassword); EncryptedPassword.Encrypt(); write(hfile2, EncryptedPassword.asString(), EncryptedPassword.StrLength()); write(hfile2, "\n", strlen("\n")); close(hfile2); return 1; }
char CMail::MPDtext(const CString& iStr, int& curPos){ /* dtext = <any CHAR excluding "[", ; => may be folded "]", "\" & CR, & including linear-white-space> */ #ifdef M_DEBUG cout << "MPDText() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { char c = iStr[curPos]; switch(c){ case '[': case ']': case '\\': case CR: return 0; } char d; if ((d = MPLinearWhiteSpace(iStr, curPos))) return d; return c; } else return 0; }
void cgi_admin_manager::add_admin(const CString& class_, const CString& category){ if (class_.StrLength()&&(class_[0]!='#')) { CVector<CString> Tokens; category.Tokenizer('+',Tokens); for (int i=0;i<Tokens.Count();i++){ entry_manager::add_value(Tokens[i], class_, Tokens[i]); } } }
CString CMail::MPAddress(const CString& iStr, int& curPos){ /* address = mailbox ; one addressee / group ; named list */ #ifdef M_DEBUG cout << "MPAddress() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { CString Mailbox = MPMailbox(iStr, curPos); if (Mailbox.StrLength()) return Mailbox; CString Group = MPGroup(iStr, curPos); if (Group.StrLength()) return Group; return ""; } else return ""; }
int recent_manager::how_old_hours(const CString& article_date){ if (!(article_date.StrLength())) return(0); struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); struct tm thisdate = encode_date_article(article_date); int day_diff = abs(- day_count(thisdate.tm_mon, thisdate.tm_mday, thisdate.tm_year) + day_count(newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_year)); int hour_diff = newtime->tm_hour - thisdate.tm_hour; if (hour_diff < 0) {day_diff--; hour_diff+=24;} return(day_diff * 24 + hour_diff); }
CString CMail::MPDomain(const CString& iStr, int& curPos){ /* domain = sub-domain *("." sub-domain) */ #ifdef M_DEBUG cout << "MPDomain() - " << curPos << endl; #endif CString Result; CString SubDomain; int workingPos = curPos; SubDomain = MPSubDomain(iStr, workingPos); while ((iStr[workingPos] == '.') && SubDomain.StrLength() && (curPos < iStr.StrLength())){ workingPos++; if (Result.StrLength()) Result+="."; Result+=SubDomain; SubDomain = MPSubDomain(iStr, workingPos); } if (SubDomain.StrLength()) { if (Result.StrLength()) Result+="."; Result+=SubDomain; } if (Result.StrLength()) curPos = workingPos; return Result; }
void CHttpRequest::ProcessOneLine(const CString& Line){ int sPos = Line.Pos(':'); if (sPos > 0) { RHeaderResponse.set_value(Line.Copy(0, sPos), Line.Copy(sPos+1, Line.StrLength()).StrTrim()); #ifdef _U_DEBUG cout << "CHTTPREQUEST::Header:[" << Line.Copy(0, sPos) << "]:[" << Line.Copy(sPos+1, Line.StrLength()).StrTrim() << "]" << endl; #endif } else { #ifdef _U_DEBUG cout << "CHTTPREQUEST::Header (???):[" << Line << "]" << endl; #endif } }
char CMail::MPQuotedPair(const CString& iStr, int& curPos){ #ifdef M_DEBUG cout << "MPQuotedPair() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { if (iStr[curPos] == '\\') { curPos++; return iStr[curPos]; } else return 0; } else return 0; }
CString CMail::MPWord(const CString& iStr, int& curPos){ #ifdef M_DEBUG cout << "MPWord() - " << curPos << endl; #endif CString Result; Result = MPAtomSequence(iStr, curPos); if (!Result.StrLength()) { Result = MPQuotedString(iStr, curPos); } return Result; }
int recent_manager::how_old(const CString& article_date, int TimeShift){ if (!(article_date.StrLength())) return(0); struct tm ArticleTime = encode_date_article(article_date); ArticleTime.tm_mon--; time_t tclock = mktime(&ArticleTime); if (TimeShift != 0) tclock += (TimeShift * 3600); memcpy(&ArticleTime, localtime(&tclock), sizeof(ArticleTime)); time_t aclock; time( &aclock ); if (TimeShift != 0) aclock += (TimeShift * 3600); struct tm * MachineTime = localtime( &aclock ); return (abs(- day_count(ArticleTime.tm_mon + 1, ArticleTime.tm_mday, ArticleTime.tm_year) + day_count(MachineTime->tm_mon + 1, MachineTime->tm_mday, MachineTime->tm_year))); }
CString CMail::MPSubDomain(const CString& iStr, int& curPos){ /* sub-domain = domain-ref / domain-literal domain-ref = atom */ #ifdef M_DEBUG cout << "MPSubDomain() - " << curPos << endl; #endif CString Result = MPDomainRef(iStr, curPos); if (!Result.StrLength()) Result = MPDomainLiteral(iStr, curPos); return Result; }
int CHttpRequest::Post(CUrl& iUrl, const CString& RawData){ CString Server; int Port; if (ProxyURL.StrLength() && Proxy.isValid()) { Server = Proxy.GetHost(); Port = Proxy.GetPortValue(); } else if (iUrl.isValid()) { Server = iUrl.GetHost(); Port = iUrl.GetPortValue(); } else return 0; inetSocket Sock(Port, Server); if (wsLastError.StrLength()) return 0; char iE[] = "xxxx\0"; sprintf(iE, "%c%c", 13, 10); return PostHTTP(iUrl, RawData, iE, Sock); }
CString CMail::MPQuotedString(const CString& iStr, int& curPos){ /* quoted-string = <"> *(qtext/quoted-pair) <">; Regular qtext or quoted chars. */ #ifdef M_DEBUG cout << "MPQuotedString() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { if (iStr[curPos] == '\"'){ int workingPos = curPos+1; while (workingPos < iStr.StrLength()){ if (!MPQText(iStr, workingPos)) if (!MPQuotedPair(iStr, workingPos)) break; } if (iStr[workingPos] == '\"') { CString Result = iStr.Copy(curPos, workingPos - curPos); curPos = workingPos+1; return Result; } else return ""; } else return ""; } else return ""; }
CString CMail::MPLocalPart(const CString& iStr, int& curPos){ /* addr-spec = local-part "@" domain ; global address local-part = word *("." word) ; uninterpreted */ #ifdef M_DEBUG cout << "MPLocalPart() - " << curPos << endl; #endif CString Result; CString Word; int workingPos = curPos; Word = MPWord(iStr, workingPos); while ((iStr[workingPos] == '.') && Word.StrLength() && (curPos < iStr.StrLength())){ workingPos++; if (Result.StrLength()) Result+="."; Result+=Word; Word = MPWord(iStr, workingPos); } if (Word.StrLength()) Result+=Word; if (Result.StrLength()) curPos = workingPos; return Result; }
CString CMail::MPRoute(const CString& iStr, int& curPos){ /* route = 1#("@" domain) ":" ; path-relative means 1 at least "@:" or "domain:" separated eventually by commas */ #ifdef M_DEBUG cout << "MPRoute() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { int workingPos = curPos; if (iStr[workingPos] != '@') { CString FDomain = MPDomain(iStr, workingPos); if (!FDomain.StrLength()) return ""; } else workingPos++; if (iStr[workingPos] != ':') return ""; CString Result = iStr.Copy(curPos, workingPos-curPos); curPos = workingPos+1; if (iStr[curPos] == ',') return (Result+=MPRoute(iStr, curPos)); else return Result; } else return ""; }
void agnes_article::send_parent_mail(agnes_article * article_parent, article_manager * template_manager, bool bTar){ CEmail follow_bymail; if (article_parent->author_mail().StrLength()) { if (author_mail().StrLength() && !template_manager->hideEMAIL) { follow_bymail.from = author_mail(); } else { follow_bymail.from = template_manager->get_option("MAIL-FROM"); if (!follow_bymail.from.StrLength()) follow_bymail.from = "anonymous@localhost"; } follow_bymail.to = article_parent->author_mail(); if (!template_manager->hideNAME) follow_bymail.name = author_name(); else follow_bymail.name = "anonymous"; follow_bymail.subject = article_title(); follow_bymail.contents += template_manager->get_option("MAIL-HEADER"); follow_bymail.contents += article_parent->article_title(); if (!template_manager->hideDATE) { follow_bymail.contents += " ("; follow_bymail.contents += template_manager->shift_date(article_parent->article_date()); follow_bymail.contents += ")\n"; } if (!template_manager->hideNAME) follow_bymail.contents += author_name(); if (author_mail().StrLength() && (!template_manager->hideEMAIL)){ follow_bymail.contents += " ("; follow_bymail.contents += author_mail(); follow_bymail.contents += ") "; } else follow_bymail.contents += " "; follow_bymail.contents += template_manager->get_option("MAIL-WROTE"); follow_bymail.contents += "\n\n"; follow_bymail.contents += article_title(); follow_bymail.contents += " - "; follow_bymail.contents += template_manager->shift_date(article_date()); follow_bymail.contents += "\n\n"; follow_bymail.contents += get_inside(template_manager->current_root, 0, bTar); follow_bymail.contents += "\n"; follow_bymail.contents += template_manager->get_option("MAIL-FOOTER"); CString ExtMailFooter(template_manager->equivs->entry_manager::get_value("MAIL-FOOTER")); ExtMailFooter.FormatC(); follow_bymail.contents += ExtMailFooter; follow_bymail.contents += "\n[email generated by aGNeS (c) Vestris Inc., http://www.vestris.com]\n"; } CString mailServer = template_manager->get_value("MailServer"); if (!(mailServer.StrLength())) mailServer = template_manager->equivs->entry_manager::get_value("MailServer"); if (!(mailServer.StrLength())) mailServer = "mail.vestris.com"; follow_bymail.Send(mailServer); }
struct tm recent_manager::encode_date_article(const CString& date){ assert(date.StrLength()); char sep, weekday[10], month[10], hour[10]; char * months[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; char * weekdays[] = {"Sun", "Mon","Tue","Wed","Thu","Fri","Sat"}; int year; struct tm thisdate; sscanf(date.asString(), "%s%s%d%s%d", weekday, month, &thisdate.tm_mday, hour, &year); for (int i=0;i<12;i++) if (!strcmpi(month, months[i])) {thisdate.tm_mon = i + 1; break;} for (int j=0;j<7;j++) if (!strcmpi(weekday, weekdays[j])) {thisdate.tm_wday = j + 1; break;} thisdate.tm_year = year - 1900; sscanf(hour, "%d%c%d%c%d", &thisdate.tm_hour, &sep, &thisdate.tm_min, &sep, &thisdate.tm_sec); thisdate.tm_isdst = -1; return(thisdate); }
int CHttpRequest::Execute(CUrl& iUrl){ #ifdef _U_DEBUG cout << "CHttpRequest::Execute()" << endl; #endif RHeader.Free(); RData.Free(); RStatus.Free(); RStatusValue = -1; RedirectVector.Clear(); CString Server; int Port; if (ProxyURL.StrLength() && Proxy.isValid()) { Server = Proxy.GetHost(); Port = Proxy.GetPortValue(); } else if (iUrl.isValid()) { Server = iUrl.GetHost(); Port = iUrl.GetPortValue(); } else { RStatusValue = HTTPR_USER + 1; return 0; } #ifdef _U_DEBUG cout << "CHttpRequest::Execute() - creating inetSocket" << endl; #endif inetSocket Sock(Port, Server); if (wsLastError.StrLength()) { #ifdef _U_DEBUG cout << "CHttpRequest::Execute() - ERROR at inetSocket - " << wsLastError << endl; #endif RStatusValue = HTTPR_USER + 2; return 0; } #ifdef _U_DEBUG cout << "CHttpRequest::Execute() - inetSocket created" << endl; #endif char iE[] = "xxxx\0"; sprintf(iE, "%c%c", 13, 10); if (!GetHTTP10(iUrl, iE, Sock)) { if (!GetHTTP09(iUrl, iE, Sock)) { return 0; } else return 1; } else return 1; }
CString CMail::MPPhrase(const CString& iStr, int& curPos){ /* 1*word */ #ifdef M_DEBUG cout << "MPPhrase() - " << curPos << endl; #endif CString Result; CString Word; Word = MPWord(iStr, curPos); while (Word.StrLength()) { Result+=Word; Word = MPWord(iStr, curPos); } return Result; }
void ext_param::traverse_cline_internal(cgiOutStream& CGIStream, const CString& arg){ if (arg == "equiv") output_current_equivs(CGIStream); else if (arg == "nocache") entry_manager::set_value("CACHED", "0"); else if (arg == "admin") output_current_admins(CGIStream); else if (arg.StartsWith("access")) { CString passwd = arg.Copy(strlen("access"), arg.StrLength()); if (check_root_access(passwd)) cgi_error(CGIStream, "access denied"); output_current_access(CGIStream); } else if (arg == "version") { CGIStream << "(" << __DATE__ ") Daniel Doubrovkine - University of Geneva" << elf; CGIStream << "© Vestris Inc. - 1994-1998 - All Rights Reserved" << elf; } else if (arg == "environ") { #ifdef ANSI extern char **environ; char ** _environ = environ; #endif int i=0; while (_environ[i]) CGIStream << _environ[i++]<<elf; } }
void agnes_article :: agnes_article_detar(const CString& root, const CString& archive) { if (!archive.StrLength()) return; CString Command("tar fxz \""); Command += root; Command += archive; Command += ".tar.gz\" "; Command += " --directory=\""; Command += root; Command += "\" \""; Command += archive; Command.append_backslash(); Command += article_node(); Command += "\""; // cout << Command.asString() << endl; system(Command.asString()); }
long recent_manager::how_old_seconds(const CString& article_date){ if (!(article_date.StrLength())) return(0); struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); struct tm thisdate = encode_date_article(article_date); int day_diff = abs(- day_count(thisdate.tm_mon, thisdate.tm_mday, thisdate.tm_year) + day_count(newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_year)); int hour_diff = newtime->tm_hour - thisdate.tm_hour; if (hour_diff < 0) {day_diff--; hour_diff+=24;} hour_diff = day_diff * 24 + hour_diff; long min_diff = newtime->tm_min - thisdate.tm_min; if (min_diff < 0) {hour_diff--; min_diff+=60;} min_diff = hour_diff * 60 + min_diff; long sec_diff = newtime->tm_sec - thisdate.tm_sec; if (sec_diff < 0) {min_diff--; sec_diff+=60;} sec_diff = min_diff * 60 + sec_diff; return(sec_diff); }
char CMail::MPLinearWhiteSpace(const CString& iStr, int& curPos){ /* linear-white-space = 1*([CRLF] LWSP-char) ; semantics = SPACE ; CRLF => folding */ #ifdef M_DEBUG cout << "MPLinearWhiteSpace() - " << curPos << endl; #endif if (curPos < iStr.StrLength()) { int workingPos = curPos; if ((iStr[workingPos] == 13)&&(iStr[workingPos+1] == 10)) workingPos+=2; char c = iStr[workingPos]; if ((c==SPACE)||(c==HTAB)) { curPos = workingPos+1; return c; } else return 0; } else return 0; }