⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htnews.c

📁 用于linux和其他unix下面的
💻 C
📖 第 1 页 / 共 5 页
字号:
			FREE(auth->pass);			auth->pass = PassWord;		    }		} else {		    if ((auth = typecalloc(NNTPAuth)) != NULL) {			StrAllocCopy(auth->host, host);			auth->user = UserName;			auth->pass = PassWord;			HTList_appendObject(NNTP_AuthInfo, auth);		    }		}		return NNTPAUTH_OK;	    }	    /*	    **	Not success, so it must be an error. - FM	    */	    HTAlert(response_text);	    if (!auth || auth->pass != PassWord) {		FREE(PassWord);	    } else {		PassWord = NULL;	    }	    tries--;	    if ((tries > 0) && HTConfirm(gettext("Change password?"))) {		continue;	    }	    if (auth) {		if (auth->user == UserName)		    UserName = NULL;		FREE(auth->user);		FREE(auth->pass);	    }	    FREE(UserName);	    break;	}    }    return NNTPAUTH_ERROR;}/*	Find Author's name in mail address**	----------------------------------**** On exit,**	Returns allocated string which cannot be freed by the**	calling function, and is reallocated on subsequent calls**	to this function.**** For example, returns "Tim Berners-Lee" if given any of**	" Tim Berners-Lee <tim@online.cern.ch> "**  or	" tim@online.cern.ch ( Tim Berners-Lee ) "*/PRIVATE char * author_name ARGS1 (char *,email){    char *p, *e;    StrAllocCopy(name, email);    CTRACE((tfp,"Trying to find name in: %s\n",name));    if ((p = strrchr(name, '(')) && (e = strrchr(name, ')'))) {	if (e > p) {	    *e = '\0';			/* Chop off everything after the ')'  */	    return HTStrip(p+1);	/* Remove leading and trailing spaces */	}    }    if ((p = strrchr(name, '<')) && (e = strrchr(name, '>'))) {	if (e++ > p) {	    while ((*p++ = *e++) != 0)	/* Remove <...> */		;	    return HTStrip(name);	/* Remove leading and trailing spaces */	}    }    return HTStrip(name);		/* Default to the whole thing */}/*	Find Author's mail address**	--------------------------**** On exit,**	Returns allocated string which cannot be freed by the**	calling function, and is reallocated on subsequent calls**	to this function.**** For example, returns "montulli@spaced.out.galaxy.net" if given any of**	" Lou Montulli <montulli@spaced.out.galaxy.net> "**  or	" montulli@spaced.out.galaxy.net ( Lou "The Stud" Montulli ) "*/PRIVATE char * author_address ARGS1(char *,email){    char *p, *at, *e;    StrAllocCopy(address, email);    CTRACE((tfp,"Trying to find address in: %s\n",address));    if ((p = strrchr(address, '<'))) {	if ((e = strrchr(p, '>')) && (at = strrchr(p, '@'))) {	    if (at < e) {		*e = '\0';		 /* Remove > */		return HTStrip(p+1);  /* Remove leading and trailing spaces */	    }	}    }    if ((p = strrchr(address, '(')) &&	(e = strrchr(address, ')')) && (at = strchr(address, '@'))) {	if (e > p && at < e) {	    *p = '\0';			/* Chop off everything after the ')'  */	    return HTStrip(address);	/* Remove leading and trailing spaces */	}    }    if ((at = strrchr(address, '@')) && at > address) {	p = (at - 1);	e = (at + 1);	while (p > address && !isspace(UCH(*p)))	    p--;	while (*e && !isspace(UCH(*e)))	    e++;	*e = 0;	return HTStrip(p);    }    /*    **	Default to the first word.    */    p = address;    while (isspace(UCH(*p)))	p++; /* find first non-space */    e = p;    while (!isspace(UCH(*e)) && *e != '\0')	e++; /* find next space or end */    *e = '\0'; /* terminate space */    return(p);}/*	Start anchor element**	--------------------*/PRIVATE void start_anchor ARGS1(CONST char *,  href){    BOOL		present[HTML_A_ATTRIBUTES];    CONST char*		value[HTML_A_ATTRIBUTES];    int i;    for(i=0; i < HTML_A_ATTRIBUTES; i++)	present[i] = (BOOL) (i == HTML_A_HREF);    value[HTML_A_HREF] = href;    (*targetClass.start_element)(target, HTML_A, present, value, -1, 0);}/*	Start link element**	------------------*/PRIVATE void start_link ARGS2(CONST char *,  href, CONST char *, rev){    BOOL		present[HTML_LINK_ATTRIBUTES];    CONST char*		value[HTML_LINK_ATTRIBUTES];    int i;    for(i=0; i < HTML_LINK_ATTRIBUTES; i++)	present[i] = (BOOL) (i == HTML_LINK_HREF || i == HTML_LINK_REV);    value[HTML_LINK_HREF] = href;    value[HTML_LINK_REV]  = rev;    (*targetClass.start_element)(target, HTML_LINK, present, value, -1, 0);}/*	Start list element**	------------------*/PRIVATE void start_list ARGS1(int, seqnum){    BOOL		present[HTML_OL_ATTRIBUTES];    CONST char*		value[HTML_OL_ATTRIBUTES];    char SeqNum[20];    int i;    for (i = 0; i < HTML_OL_ATTRIBUTES; i++)	present[i] = (BOOL) (i == HTML_OL_SEQNUM || i == HTML_OL_START);    sprintf(SeqNum, "%d", seqnum);    value[HTML_OL_SEQNUM] = SeqNum;    value[HTML_OL_START]  = SeqNum;    (*targetClass.start_element)(target, HTML_OL, present, value, -1, 0);}/*	Paste in an Anchor**	------------------****** On entry,**	HT	has a selection of zero length at the end.**	text	points to the text to be put into the file, 0 terminated.**	addr	points to the hypertext reference address,**		terminated by white space, comma, NULL or '>'*/PRIVATE void write_anchor ARGS2(CONST char *,text, CONST char *,addr){    char href[LINE_LENGTH+1];    CONST char * p;    char *q;    for (p = addr; *p && (*p != '>') && !WHITE(*p) && (*p!=','); p++)	;    if (strlen(NewsHREF) + (p - addr) + 1 < sizeof(href)) {	q = href;	strcpy(q, NewsHREF);	strncat(q, addr, p-addr);	/* Make complete hypertext reference */    } else {	q = NULL;	HTSprintf0(&q, "%s%.*s", NewsHREF, p-addr, addr);    }    start_anchor(q);    PUTS(text);    END(HTML_A);    if (q != href)	FREE(q);}/*	Write list of anchors**	---------------------****	We take a pointer to a list of objects, and write out each,**	generating an anchor for each.**** On entry,**	HT	has a selection of zero length at the end.**	text	points to a comma or space separated list of addresses.** On exit,**	*text	is NOT any more chopped up into substrings.*/PRIVATE void write_anchors ARGS1 (char *,text){    char * start = text;    char * end;    char c;    for (;;) {	for (; *start && (WHITE(*start)); start++)	    ;  /* Find start */	if (!*start)	    return;			/* (Done) */	for (end = start;	     *end && (*end != ' ') && (*end != ','); end++)	    ;/* Find end */	if (*end)	    end++;	/* Include comma or space but not NULL */	c = *end;	*end = '\0';	if (*start == '<')	    write_anchor(start, start+1);	else	    write_anchor(start, start);	START(HTML_BR);	*end = c;	start = end;			/* Point to next one */    }}/*	Abort the connection					abort_socket**	--------------------*/PRIVATE void abort_socket NOARGS{    CTRACE((tfp, "HTNews: EOF on read, closing socket %d\n", s));    NEWS_NETCLOSE(s);	/* End of file, close socket */    if (rawtext) {	RAW_PUTS("Network Error: connection lost\n");    } else {	PUTS("Network Error: connection lost");	PUTC('\n');    }    s = -1;		/* End of file on response */}/***  Determine if a line is a valid header line.			valid_header**  -------------------------------------------*/PRIVATE BOOLEAN valid_header ARGS1(	char *,		line){    char *colon, *space;    /*    **	Blank or tab in first position implies    **	this is a continuation header.    */    if (line[0] == ' ' || line[0] == '\t')	return(TRUE);    /*    **	Just check for initial letter, colon, and space to make    **	sure we discard only invalid headers.    */    colon = strchr(line, ':');    space = strchr(line, ' ');    if (isalpha(UCH(line[0])) && colon && space == colon + 1)	return(TRUE);    /*    **	Anything else is a bad header -- it should be ignored.    */    return(FALSE);}/*	post in an Article					post_article**	------------------**			(added by FM, modeled on Lynx's previous mini inews)****	Note the termination condition of a single dot on a line by itself.****  On entry,**	s		Global socket number is OK**	postfile	file with header and article to post.*/PRIVATE void post_article ARGS1(	char *,		postfile){    char line[512];    char buf[512];    char crlf[3];    char *cp;    int status;    FILE *fd;    int in_header = 1, seen_header = 0, seen_fromline = 0;    int blen = 0, llen = 0;    /*    **	Open the temporary file with the    **	nntp headers and message body. - FM    */    if ((fd = fopen((postfile ? postfile : ""), TXT_R)) == NULL) {	HTAlert(FAILED_CANNOT_OPEN_POST);	return;    }    /*    **	Read the temporary file and post    **	in maximum 512 byte chunks. - FM    */    buf[0] = '\0';    sprintf(crlf, "%c%c", CR, LF);    while (fgets(line, sizeof(line)-2, fd) != NULL) {	if ((cp = strchr(line, '\n')) != NULL)	    *cp = '\0';	if (line[0] == '.') {	    /*	    **	A single '.' means end of transmission	    **	for nntp.  Lead dots on lines normally	    **	are trimmed and the EOF is not registered	    **	if the dot was not followed by CRLF.	    **	We prepend an extra dot for any line	    **	beginning with one, to retain the one	    **	intended, as well as avoid a false EOF	    **	signal.  We know we have room for it in	    **	the buffer, because we normally send when	    **	it would exceed 510. - FM	    */	    strcat(buf, ".");	    blen++;	}	llen = strlen(line);	if (in_header && !strncasecomp(line, "From:", 5)) {	    seen_header = 1;	    seen_fromline = 1;	}	if (in_header && line[0] == '\0') {	    if (seen_header) {		in_header = 0;		if (!seen_fromline) {		    if (blen >= (int) sizeof(buf) - 35) {			NEWS_NETWRITE(s, buf, blen);			buf[blen = 0] = 0;		    }		    strcat(buf, "From: anonymous@nowhere.you.know");		    strcat(buf, crlf);		    blen += 34;		}	     } else {		continue;	    }	} else if (in_header) {	    if (valid_header(line)) {		seen_header = 1;	    } else {		continue;	    }	}	strcat(line, crlf);	llen += 2;	if ((blen + llen) >= (int) sizeof(buf)-1) {	    NEWS_NETWRITE(s, buf, blen);	    buf[blen = 0] = 0;	}	strcat(buf, line);	blen += llen;    }    fclose(fd);    HTSYS_remove(postfile);    /*    **	Send the nntp EOF and get the server's response. - FM    */    if (blen >= (int) sizeof(buf)-4) {	NEWS_NETWRITE(s, buf, blen);	buf[blen = 0] = 0;    }    strcat(buf, ".");    strcat(buf, crlf);    blen += 3;    NEWS_NETWRITE(s, buf, blen);    status = response(NULL);    if (status == 240) {	/*	**  Successful post. - FM	*/	HTProgress(response_text);    } else {	/*	**  Shucks, something went wrong. - FM	*/	HTAlert(response_text);    }}#ifdef SH_EX	/* for MIME */#define NEWS_DEBUG 0#if NEWS_DEBUG/* for DEBUG 1997/11/07 (Fri) 17:20:16 */void debug_print(unsigned char *p){    while (*p) {	if (*p == '\0')	    break;	if (*p == 0x1b)	   printf("[ESC]");	else if (*p == '\n')	   printf("[NL]");	else if (*p < ' ' || *p >= 0x80)	   printf("(%02x)", *p);	else	   putchar(*p);       p++;    }    printf("]\n");}#endifstatic char *decode_mime(char *str){    char temp[LINE_LENGTH];	/* FIXME: what determines the actual size? */    char *p, *q;    if (str == NULL)	return "";    if (HTCJK != JAPANESE)	return str;    LYstrncpy(temp, str, sizeof(temp) - 1);    q = temp;    while ((p = strchr(q, '=')) != 0) {	if (p[1] == '?') {	    HTmmdecode(p, p);	    q = p + 2;	} else {	    q = p + 1;	}    }#if NEWS_DEBUG    printf("new=[");    debug_print(temp);#endif    HTrjis(temp, temp);    strcpy(str, temp);    return str;}#else /* !SH_EX */static char *decode_mime ARGS1(char *, str){    HTmmdecode(str, str);    HTrjis(str, str);    return str;}#endif/*	Read in an Article					read_article**	------------------****	Note the termination condition of a single dot on a line by itself.**	RFC 977 specifies that the line "folding" of RFC850 is not used, so we**	do not handle it here.**** On entry,**	s	Global socket number is OK**	HT	Global hypertext object is ready for appending text*/PRIVATE int read_article ARGS1(	HTParentAnchor *,	thisanchor){    char line[LINE_LENGTH+1];    char *full_line = NULL;    char *subject = NULL;			/* Subject string	    */    char *from = NULL;				/* From string		    */    char *replyto = NULL;			/* Reply-to string	    */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -