Ejemplo n.º 1
0
static unsigned char *
get_nntp_title(struct connection *conn)
{
	struct nntp_connection_info *nntp = conn->info;
	struct string title;

	if (!init_string(&title))
		return NULL;

	switch (nntp->target) {
	case NNTP_TARGET_ARTICLE_RANGE:
		add_format_to_string(&title, "Articles in the range %ld to %ld",
				     nntp->current_article, nntp->end_article);
		break;

	case NNTP_TARGET_ARTICLE_NUMBER:
	case NNTP_TARGET_MESSAGE_ID:
	case NNTP_TARGET_GROUP_MESSAGE_ID:
	{
		unsigned char *subject;

		subject = parse_header(conn->cached->head, "Subject", NULL);
		if (subject) {
			add_to_string(&title, subject);
			mem_free(subject);
			break;
		}

		add_format_to_string(&title, "Article "),
		add_string_to_string(&title, &nntp->message);

		if (nntp->target == NNTP_TARGET_MESSAGE_ID)
			break;

		add_format_to_string(&title, " in ");
		add_string_to_string(&title, &nntp->group);
		break;
	}
	case NNTP_TARGET_GROUP:
		add_format_to_string(&title, "Articles in "),
		add_string_to_string(&title, &nntp->group);
		break;

	case NNTP_TARGET_GROUPS:
		add_format_to_string(&title, "Newsgroups on "),
		add_uri_to_string(&title, conn->uri, URI_PUBLIC);
		break;

	case NNTP_TARGET_QUIT:
		break;
	}

	return title.source;
}
Ejemplo n.º 2
0
Archivo: smb2.c Proyecto: Efreak/elinks
/** First information such as permissions is gathered for each directory entry.
 * All entries are then sorted. */
static struct directory_entry *
get_smb_directory_entries(int dir, struct string *prefix)
{
	struct directory_entry *entries = NULL;
	
	int size = 0;
	struct smbc_dirent *entry;

	while ((entry = smbc_readdir(dir))) {
		struct stat st, *stp;
		struct directory_entry *new_entries;
		struct string attrib;
		struct string name;

		if (!strcmp(entry->name, "."))
			continue;

		new_entries = mem_realloc(entries, (size + 2) * sizeof(*new_entries));
		if (!new_entries) continue;
		entries = new_entries;

		if (!init_string(&attrib)) {
			continue;
		}

		if (!init_string(&name)) {
			done_string(&attrib);
			continue;
		}

		add_string_to_string(&name, prefix);
		add_to_string(&name, entry->name);

		stp = (smbc_stat(name.source, &st)) ? NULL : &st;

		stat_type(&attrib, stp);
		stat_mode(&attrib, stp);
		stat_links(&attrib, stp);
		stat_user(&attrib, stp);
		stat_group(&attrib, stp);
		stat_size(&attrib, stp);
		stat_date(&attrib, stp);

		entries[size].name = stracpy(entry->name);
		entries[size].attrib = attrib.source;
		done_string(&name);
		size++;
	}
	smbc_closedir(dir);

	if (!size) {
		/* We may have allocated space for entries but added none. */
		mem_free_if(entries);
		return NULL;
	}
	qsort(entries, size, sizeof(*entries), compare_dir_entries);
	memset(&entries[size], 0, sizeof(*entries));
	return entries;
}
Ejemplo n.º 3
0
static inline void
add_char_true_color(struct string *screen, const struct string *seq, unsigned char *colors)
{
	unsigned char color_buf[3];
	int i;

	check_string_magic(seq);
	add_string_to_string(screen, seq);
	for (i = 0; i < 3; i++) {
		unsigned char *color_pos = color_buf;
		int color_len = 1;
		unsigned char color = colors[i];

		add_char_to_string(screen, ';');

		if (color < 10) {
			color_pos += 2;
		} else {
			int color2;

			++color_len;
			if (color < 100) {
				++color_pos;
			} else {
				++color_len;

				if (color < 200) {
					color_buf[0] = '1';
					color -= 100;
				} else {
					color_buf[0] = '2';
					color -= 200;
				}
			}

			color2 = (color % 10);
			color /= 10;
			color_buf[1] = '0' + color;
			color = color2;
		}
		color_buf[2] = '0' + color;

		add_bytes_to_string(screen, color_pos, color_len);
	}
	add_char_to_string(screen, 'm');
}
Ejemplo n.º 4
0
char *owsrequest_getenv(const char *name, void *thread_context)
{
    zval **val, **ppzval;
    zval *cookie_result, *key;
    HashTable *cookies;
    char *string_key = NULL, *cookie_tmp;
    ulong num_key;
    int numElements, i = 0;
    TSRMLS_FETCH_FROM_CTX(thread_context);

    if  (STRING_EQUAL(name, "HTTP_COOKIE"))
    {
        cookies = PG(http_globals)[TRACK_VARS_COOKIE]->value.ht;
        numElements = zend_hash_num_elements(cookies);
        MAKE_STD_ZVAL(cookie_result);
        ZVAL_STRING(cookie_result, "",1);
        for(zend_hash_internal_pointer_reset(cookies); 
            zend_hash_has_more_elements(cookies) == SUCCESS; 
            zend_hash_move_forward(cookies), ++i)
        { 
            zend_hash_get_current_data(cookies, (void **)&ppzval);
            zend_hash_get_current_key(cookies, &string_key, &num_key, 1);
            cookie_tmp = malloc((strlen(string_key)+Z_STRLEN_PP(ppzval)+3) * sizeof(char));
            sprintf(cookie_tmp, "%s=%s;",string_key,Z_STRVAL_PP(ppzval));
            MAKE_STD_ZVAL(key);
            ZVAL_STRING(key, cookie_tmp,1);
            add_string_to_string(cookie_result,cookie_result, key);
            zval_dtor(key);
            free(cookie_tmp);
        }
        return Z_STRVAL_P(cookie_result);
    }
    else 
    {
        zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
        if ( PG(http_globals)[TRACK_VARS_SERVER] &&
             (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, name, strlen(name)+1, (void **) &val) == SUCCESS) &&
             (Z_TYPE_PP(val) == IS_STRING))
        {
            return Z_STRVAL_PP(val);
        }
    }
    
    return NULL;
}
Ejemplo n.º 5
0
Archivo: smb2.c Proyecto: Efreak/elinks
static void
add_smb_dir_entry(struct directory_entry *entry, struct string *page,
	      int pathlen, unsigned char *dircolor)
{
	unsigned char *lnk = NULL;
	struct string html_encoded_name;
	struct string uri_encoded_name;

	if (!init_string(&html_encoded_name)) return;
	if (!init_string(&uri_encoded_name)) {
		done_string(&html_encoded_name);
		return;
	}

	encode_uri_string(&uri_encoded_name, entry->name + pathlen, -1, 1);
	add_html_to_string(&html_encoded_name, entry->name + pathlen,
			   strlen(entry->name) - pathlen);

	/* add_to_string(&fragment, &fragmentlen, "   "); */
	add_html_to_string(page, entry->attrib, strlen(entry->attrib));
	add_to_string(page, "<a href=\"");
	add_string_to_string(page, &uri_encoded_name);

	if (entry->attrib[0] == 'd') {
		add_char_to_string(page, '/');

#ifdef FS_UNIX_SOFTLINKS
	} else if (entry->attrib[0] == 'l') {
		struct stat st;
		unsigned char buf[MAX_STR_LEN];
		int readlen = readlink(entry->name, buf, MAX_STR_LEN);

		if (readlen > 0 && readlen != MAX_STR_LEN) {
			buf[readlen] = '\0';
			lnk = straconcat(" -> ", buf, (unsigned char *) NULL);
		}

		if (!stat(entry->name, &st) && S_ISDIR(st.st_mode))
			add_char_to_string(page, '/');
#endif
	}

	add_to_string(page, "\">");

	if (entry->attrib[0] == 'd' && *dircolor) {
		/* The <b> is for the case when use_document_colors is off. */
		string_concat(page, "<font color=\"", dircolor, "\"><b>",
			      (unsigned char *) NULL);
	}

	add_string_to_string(page, &html_encoded_name);
	done_string(&uri_encoded_name);
	done_string(&html_encoded_name);

	if (entry->attrib[0] == 'd' && *dircolor) {
		add_to_string(page, "</b></font>");
	}

	add_to_string(page, "</a>");
	if (lnk) {
		add_html_to_string(page, lnk, strlen(lnk));
		mem_free(lnk);
	}

	add_char_to_string(page, '\n');
}
Ejemplo n.º 6
0
struct connection_state
init_directory_listing(struct string *page, struct uri *uri)
{
	struct string dirpath = NULL_STRING;
	struct string decoded = NULL_STRING;
	struct string location = NULL_STRING;
	unsigned char *info;
	int local = (uri->protocol == PROTOCOL_FILE);

	if (!init_string(page)
	    || !init_string(&dirpath)
	    || !init_string(&decoded)
	    || !init_string(&location)
	    || !add_uri_to_string(&dirpath, uri, URI_DATA)
	    || !add_uri_to_string(&location, uri, URI_DIR_LOCATION))
		goto out_of_memory;

	if (dirpath.length > 0
	    && !dir_sep(dirpath.source[dirpath.length - 1])
	    && !add_char_to_string(&dirpath, local ? CHAR_DIR_SEP : '/'))
		goto out_of_memory;

	/* Decode uri for displaying.  */
	if (!add_string_to_string(&decoded, &dirpath))
		goto out_of_memory;
	decode_uri_string(&decoded);

	if (!local && !add_char_to_string(&location, '/'))
		goto out_of_memory;

	if (!add_to_string(page, (const unsigned char *)"<html>\n<head><title>"))
		goto out_of_memory;

	if (!local && !add_html_to_string(page, location.source, location.length))
		goto out_of_memory;

	if (!add_html_to_string(page, decoded.source, decoded.length)
	    || !add_to_string(page, (const unsigned char *)"</title>\n<base href=\"")
	    || !add_html_to_string(page, location.source, location.length)
	    || !add_html_to_string(page, dirpath.source, dirpath.length))
		goto out_of_memory;

	if (!add_to_string(page, (const unsigned char *)"\" />\n</head>\n<body>\n<h2>"))
		goto out_of_memory;

	/* Use module names? */
	switch (uri->protocol) {
	case PROTOCOL_FILE:
		info = (unsigned char *)"Local";
		break;
	case PROTOCOL_FSP:
		info = (unsigned char *)"FSP";
		break;
	case PROTOCOL_FTP:
		info = (unsigned char *)"FTP";
		break;
	case PROTOCOL_GOPHER:
		info = (unsigned char *)"Gopher";
		break;
	case PROTOCOL_SMB:
		info = (unsigned char *)"Samba";
		break;
	default:
		info = (unsigned char *)"?";
	}

	if (!add_to_string(page, info)
	    || !add_to_string(page, (const unsigned char *)" directory "))
		goto out_of_memory;

	if (!local && !add_string_to_string(page, &location))
		goto out_of_memory;

	/* Make the directory path with links to each subdir. */
	{
		const unsigned char *slash = dirpath.source;
		const unsigned char *pslash = slash;
		const unsigned char sep = local ? CHAR_DIR_SEP :  '/';

		while ((slash = (const unsigned char *)strchr((char *)slash, sep)) != NULL) {
			done_string(&decoded);
			if (!init_string(&decoded)
			    || !add_bytes_to_string(&decoded, pslash, slash - pslash))
				goto out_of_memory;
			decode_uri_string(&decoded);

			if (!add_to_string(page, (const unsigned char *)"<a href=\"")
			    || !add_html_to_string(page, location.source, location.length)
			    || !add_html_to_string(page, dirpath.source, slash + 1 - dirpath.source)
			    || !add_to_string(page, (const unsigned char *)"\">")
			    || !add_html_to_string(page, decoded.source, decoded.length)
			    || !add_to_string(page, (const unsigned char *)"</a>")
			    || !add_html_to_string(page, &sep, 1))
				goto out_of_memory;

			pslash = ++slash;
		}
	}

	if (!add_to_string(page, (const unsigned char *)"</h2>\n<pre>")) {
out_of_memory:
		done_string(page);
	}

	done_string(&dirpath);
	done_string(&decoded);
	done_string(&location);

	return page->length > 0
		? connection_state(S_OK)
		: connection_state(S_OUT_OF_MEM);
}