Пример #1
0
static void
add_test (const char *path,
	  gboolean    mixed,
	  int         test_type,
	  gboolean    use_align,
	  gdouble     row_align,
	  void (* setup) (ScrollFixture *, gconstpointer),
	  void (* scroll_func) (ScrollFixture *, gconstpointer))
{
	gchar *test_path;
	gchar *align;

	align = align_string (use_align, row_align);

	test_path = g_strdup_printf ("/TreeView/scrolling/%s/%s-height/path-%s-%s",
				     test_type_string (test_type),
				     mixed ? "mixed" : "constant",
				     path, align);
	g_free (align);

	g_test_add (test_path, ScrollFixture, path,
		    setup, scroll_func, scroll_fixture_teardown);

	g_free (test_path);
}
Пример #2
0
void nvpair_print_html_with_link(struct nvpair *n, FILE * s, struct nvpair_header *h, const char *linkname, const char *linktext)
{
	fprintf(s, "<tr bgcolor=%s>\n", color_counter % 2 ? COLOR_ONE : COLOR_TWO);
	color_counter++;
	while(h->name) {
		const char *text = nvpair_lookup_string(n, h->name);
		if(!text)
			text = "???";
		fprintf(s, "<td align=%s>", align_string(h));
		if(h->mode == NVPAIR_MODE_URL) {
			fprintf(s, "<a href=%s>%s</a>\n", text, text);
		} else if(h->mode == NVPAIR_MODE_METRIC) {
			char line[1024];
			string_metric(atof(text), -1, line);
			fprintf(s, "%sB\n", line);
		} else {
			if(linkname && !strcmp(linkname, h->name)) {
				fprintf(s, "<a href=%s>%s</a>\n", linktext, text);
			} else {
				fprintf(s, "%s\n", text);
			}
		}
		h++;
	}
}
Пример #3
0
void nvpair_print_html_header(FILE * s, struct nvpair_header *h)
{
	fprintf(s, "<table bgcolor=%s>\n", COLOR_TWO);
	fprintf(s, "<tr bgcolor=%s>\n", COLOR_ONE);
	while(h->name) {
		fprintf(s, "<td align=%s><b>%s</b>\n", align_string(h), h->title);
		h++;
	}
	color_counter = 0;
}
Пример #4
0
/* stringlist: <# listitems>
               <pos of listend (bytes)>
               <string:(size)(aligned string)>
*/
static int bc_stringlist_emit(int fd, int *codep, bytecode_info_t *bc)
{
    int len = bc->data[(*codep)++].len;
    int i;
    int ret;
    int wrote = 2*sizeof(int);
    int begin,end;

    /* Write out number of items in the list */
    if (write_int(fd, len)== -1) return -1 ;

    /* skip one spot end of list position*/
    begin=lseek(fd,0,SEEK_CUR);
    lseek(fd,sizeof(int),SEEK_CUR);

    /* Loop through all the items of the list, writing out length and string
     * in sequence */
    for(i=0; i < len; i++)
    {
        int datalen = bc->data[(*codep)++].len;

        if(write_int(fd, datalen) == -1) return -1;
        wrote += sizeof(int);

        if(write(fd, bc->data[(*codep)++].str, datalen) == -1) return -1;
        wrote += datalen;

        ret = align_string(fd,datalen);
        if(ret == -1) return -1;

        wrote+=ret;
    }
    end=lseek(fd,0,SEEK_CUR);
    if (end < 0) return -1;

    /* go back and write end of list position */
    lseek(fd,begin,SEEK_SET);
    if(write_int(fd, end) == -1) return -1;

    /* return to the end */
    lseek(fd,end,SEEK_SET);
    return wrote;
}
Пример #5
0
size_t clistr_align_in(struct cli_state *cli, const void *p, int flags)
{
	return align_string(cli->inbuf, (const char *)p, flags);
}
Пример #6
0
/* emit the bytecode to a file descriptor given a flattened parse tree
 * returns -1 on failure, size of emitted bytecode on success.
 *
 * this takes care of everything except the comparisons */
static int bc_action_emit(int fd, int codep, int stopcodep,
                          bytecode_info_t *bc, int filelen)
{
    int len; /* Temporary Length Variable */
    int ret; /* Temporary Return Value Variable */
    int start_filelen = filelen;
    int i;

    /*debugging variable to check filelen*/
    /*int location;*/

    syslog(LOG_DEBUG, "entered bc_action_emit with filelen: %d", filelen);

    /* All non-string data MUST be sizeof(int)
       byte alligned so the end of each string may require a pad */
    /*
     * Note that for purposes of jumps you must multiply codep by sizeof(int)
     */
    while(codep < stopcodep) {
        /* Output this opcode */
        if(write_int(fd, bc->data[codep].op) == -1)
            return -1;

        filelen+=sizeof(int);

        switch(bc->data[codep++].op) {

        case B_IF:
        {
            /* IF
             *  test
             *  jump (false condition)
             *  then
             * (if there is an else) jump(finish)
             * (if there is an else) else
             */

            int testEndLoc=-1;
            int testdist, thendist, elsedist;
            int c;

            int jumpFalseLoc=-1;/*this is the location that is being reserved
                                  for the first jump command
                                  we jump to the false condition of the test*/

            int jumpEndLoc=-1; /* this is the location that is being reserved
                                  for the optional jump command
                                  it jumps over the else statement to the end*/
            int jumpto=-1;
            int jumpop= B_JUMP;

            /*leave space to store the location of end of the test*/
            ret = lseek(fd, sizeof(int), SEEK_CUR);
            if(ret == -1) return ret;

            testEndLoc=filelen;
            filelen+=sizeof(int);

            /* spew the test */

            c=codep+3;
            testdist = bc_test_emit(fd, &c, bc);
            if(testdist == -1)return -1;
            filelen +=testdist;

            /*store the location for the end of the test
             *this is important for short circuiting of allof/anyof*/
            jumpto=filelen/4;
            if(lseek(fd, testEndLoc, SEEK_SET) == -1)
                return -1;
            if(write_int(fd,jumpto) == -1)
                return -1;

            if(lseek(fd,filelen,SEEK_SET) == -1)
                return -1;

            /* leave space for jump */
            if(write_int(fd, jumpop) == -1)
                return -1;
            ret = lseek(fd, sizeof(int), SEEK_CUR);
            if(ret == -1)
                return ret;
            jumpFalseLoc=filelen+sizeof(int);

            filelen +=2*sizeof(int); /*jumpop + jump*/

            /* spew the then code */
            thendist = bc_action_emit(fd, bc->data[codep].value,
                                      bc->data[codep+1].value, bc,
                                      filelen);

            filelen+=thendist;

            /* there is an else case */
            if(bc->data[codep+2].value != -1)
            {
                /* leave space for jump */
                if(write_int(fd, jumpop) == -1)
                    return -1;
                ret = lseek(fd, sizeof(int), SEEK_CUR);
                if(ret == -1)
                    return ret;

                jumpEndLoc=filelen+sizeof(int);
                filelen+=2*sizeof(int);/*jumpop + jump*/
            }

            /*put previous jump to the end of the then code,
             *or the end of the jump if there is an else case */
            jumpto=filelen/4;
            if(lseek(fd, jumpFalseLoc, SEEK_SET) == -1)
                return -1;
            if(write_int(fd,jumpto) == -1)
                return -1;
            if(lseek(fd,filelen,SEEK_SET) == -1)
                return -1;

            /* there is an else case */
            if(bc->data[codep+2].value != -1) {
                /* spew the else code */
                elsedist = bc_action_emit(fd, bc->data[codep+1].value,
                                         bc->data[codep+2].value, bc,
                                         filelen);

                filelen+=elsedist;

                /*put jump to the end of the else code*/
                jumpto=filelen/4;
                if(lseek(fd, jumpEndLoc, SEEK_SET) == -1)
                    return -1;
                if(write_int(fd,jumpto) == -1)
                    return -1;
                if(lseek(fd,filelen,SEEK_SET) == -1)
                    return -1;

                codep = bc->data[codep+2].value;
            } else {
                codep = bc->data[codep+1].value;
            }

            break;
        }

        case B_KEEP:
            /* Flags Stringlist, Copy (word) */

            /* Dump a stringlist of flags */
            ret = bc_stringlist_emit(fd, &codep, bc);
            if(ret < 0)
                return -1;
            filelen += ret;

            if(write_int(fd,bc->data[codep++].value) == -1)
                return -1;

            filelen += sizeof(int);
            break;

        case B_FILEINTO:
            /* Flags Stringlist, Copy (word), Folder String */

            /* Dump a stringlist of flags */
            ret = bc_stringlist_emit(fd, &codep, bc);
            if(ret < 0)
                return -1;
            filelen += ret;

            /* Write Copy */
            if(write_int(fd,bc->data[codep++].value) == -1)
                return -1;

            filelen += sizeof(int);

            /* Write string length of Folder */
            len = bc->data[codep++].len;
            if(write_int(fd,len) == -1)
                return -1;

            filelen+=sizeof(int);

            /* Write Folder */
            if(write(fd,bc->data[codep++].str,len) == -1)
                return -1;

            ret = align_string(fd, len);
            if(ret == -1)
                return -1;

            filelen += len + ret;

            break;

        case B_REDIRECT:
            /* Copy (word), Address String */

            if(write_int(fd,bc->data[codep++].value) == -1)
                return -1;

            filelen += sizeof(int);

            len = bc->data[codep++].len;
            if(write_int(fd,len) == -1)
                return -1;

            filelen+=sizeof(int);

            if(write(fd,bc->data[codep++].str,len) == -1)
                return -1;

            ret = align_string(fd, len);
            if(ret == -1)
                return -1;

            filelen += len + ret;

            break;

        case B_REJECT:
            /*just a string*/
            len = bc->data[codep++].len;
            if(write_int(fd,len) == -1)
                return -1;

            filelen+=sizeof(int);

            if(write(fd,bc->data[codep++].str,len) == -1)
                return -1;

            ret = align_string(fd, len);
            if(ret == -1)
                return -1;

            filelen += len + ret;

            break;

        case B_SETFLAG:
        case B_ADDFLAG:
        case B_REMOVEFLAG:
            /* Dump just a stringlist */
            ret = bc_stringlist_emit(fd, &codep, bc);
            if(ret < 0)
                return -1;
            filelen += ret;
            break;

        case B_NOTIFY:
            /* method string, id string, options string list,
               priotity, Message String */
            /*method and id*/
            for(i=0; i<2; i++) {
                len = bc->data[codep++].len;
                if(write_int(fd,len) == -1)
                    return -1;
                filelen += sizeof(int);
                if(len == -1)
                {
                    /* this will probably only happen for the id */
                    /* this is a nil string */
                    /* skip the null pointer and make up for it
                     * by adjusting the offset */
                    codep++;
                }
                else
                {
                    if(write(fd,bc->data[codep++].str,len) == -1)
                        return -1;

                    ret = align_string(fd, len);
                    if(ret == -1)
                        return -1;

                    filelen += len + ret;
                }

            }
            /*options */
            ret = bc_stringlist_emit(fd, &codep, bc);
            if(ret < 0)
                return -1;
            filelen+=ret;

            /*priority*/
            if(write_int(fd, bc->data[codep].value) == -1)
                return -1;
            codep++;
            filelen += sizeof(int);

            len = bc->data[codep++].len;
            if(write_int(fd,len) == -1)
                return -1;
            filelen += sizeof(int);

            if(write(fd,bc->data[codep++].str,len) == -1)
                return -1;

            ret = align_string(fd, len);
            if(ret == -1) return -1;

            filelen += len + ret;
            break;


        case B_DENOTIFY:
            /* priority num,comptype  num,relat num, comp string*/

            /* priority*/
            if(write_int(fd, bc->data[codep].value) == -1)
                return -1;
            filelen += sizeof(int);
            codep++;
            /* comptype */
            if(write_int(fd, bc->data[codep].value) == -1)
                return -1;
            filelen += sizeof(int);
            codep++;
            /* relational*/
            if(write_int(fd, bc->data[codep].value) == -1)
                return -1;
            filelen += sizeof(int);
            codep++;
            /* comp string*/

            len = bc->data[codep++].len;
            if(write_int(fd,len) == -1)
                return -1;
            filelen += sizeof(int);

            if(len == -1)
            {
                /* this is a nil string */
                /* skip the null pointer and make up for it
                 * by adjusting the offset */
                codep++;
            }
            else
            {
                if(write(fd,bc->data[codep++].str,len) == -1)
                    return -1;

                ret = align_string(fd, len);
                if(ret == -1) return -1;

                filelen += len + ret;
            }
                    break;
        case B_VACATION:
            /* Address list, Subject String, Message String,
               Seconds (word), Mime (word), From String, Handle String */

                /*new code-this might be broken*/
            ret = bc_stringlist_emit(fd, &codep, bc);
            if(ret < 0) return -1;
            filelen += ret;
            /*end of new code*/

            for(i=0; i<2; i++) {/*writing strings*/

                /*write length of string*/
                len = bc->data[codep++].len;
                if(write_int(fd,len) == -1)
                    return -1;
                filelen += sizeof(int);

                if(len == -1)
                {
                    /* this is a nil string */
                    /* skip the null pointer and make up for it
                     * by adjusting the offset */
                    codep++;
                }
                else
                {
                    /*write string*/
                    if(write(fd,bc->data[codep++].str,len) == -1)
                        return -1;

                    ret = align_string(fd, len);
                    if(ret == -1) return -1;

                    filelen += len + ret;
                }

            }
            /* Seconds*/
            if(write_int(fd,bc->data[codep].value) == -1)
                return -1;
            codep++;
            filelen += sizeof(int);
            /*Mime */
            if(write_int(fd,bc->data[codep].value) == -1)
                return -1;
            codep++;

            for(i=0; i<2; i++) {/*writing strings*/

                /*write length of string*/
                len = bc->data[codep++].len;
                if(write_int(fd,len) == -1)
                    return -1;
                filelen += sizeof(int);

                if(len == -1)
                {
                    /* this is a nil string */
                    /* skip the null pointer and make up for it
                     * by adjusting the offset */
                    codep++;
                }
                else
                {
                    /*write string*/
                    if(write(fd,bc->data[codep++].str,len) == -1)
                        return -1;

                    ret = align_string(fd, len);
                    if(ret == -1) return -1;

                    filelen += len + ret;
                }

            }
            filelen += sizeof(int);

            break;
        case B_INCLUDE:
            /* Location + (Once<<6) + (Optional<<7) (word), Filename String */

            /* Location + (Once<<6) + (Optional<<7) */
            if(write_int(fd, bc->data[codep].value) == -1)
                return -1;
            filelen += sizeof(int);
            codep++;
            /* Filename */
            len = bc->data[codep++].len;
            if(write_int(fd,len) == -1)
                return -1;

            filelen += sizeof(int);

            if(write(fd,bc->data[codep++].str,len) == -1)
                return -1;

            ret = align_string(fd, len);
            if(ret == -1) return -1;

            filelen += len + ret;
            break;
        case B_NULL:
        case B_STOP:
        case B_DISCARD:
        case B_MARK:
        case B_UNMARK:
        case B_RETURN:
            /* No Parameters! */
            break;

        default:
            /* Unknown opcode? */
            return -1;
        }
    }
    return filelen - start_filelen;
}
Пример #7
0
/* emit the bytecode for a test.  returns -1 on failure or size of
 * emitted bytecode on success */
static int bc_test_emit(int fd, int *codep, bytecode_info_t *bc)
{
    int opcode;
    int wrote=0;/* Relative offset to account for interleaved strings */

    int ret; /* Temporary Return Value Variable */

    /* Output this opcode */
    opcode = bc->data[(*codep)++].op;
    if(write_int(fd, opcode) == -1)
        return -1;
    wrote += sizeof(int);

    switch(opcode) {
    case BC_TRUE:
    case BC_FALSE:
        /* No parameter opcodes */
        break;

    case BC_NOT:
    {
        /* Single parameter: another test */
        ret = bc_test_emit(fd, codep, bc);
        if(ret < 0)
            return -1;
        else
            wrote+=ret;
        break;
    }

    case BC_ALLOF:
    case BC_ANYOF:
        /*where we jump to?*/
        /* Just drop a testlist */
        ret = bc_testlist_emit(fd, codep, bc);
        if(ret < 0)
            return -1;
        else
            wrote+=ret;
        break;

    case BC_SIZE:
        /* Drop tag and number */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        if(write_int(fd, bc->data[(*codep)+1].value) == -1)
            return -1;

        wrote += 2 * sizeof(int);
        (*codep) += 2;
        break;

    case BC_EXISTS:
    {
        int ret;
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote += ret;
        break;
    }

    case BC_HEADER:
    case BC_HASFLAG:
    {
        int ret;
        if (BC_HEADER == opcode) {
        /* drop index */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        }
        /* Drop match type */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*now drop relation*/
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*drop comparator */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /* Now drop haystacks */
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote+=ret;
        /* Now drop needles */
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote+=ret;
        break;
    }

    case BC_ADDRESS:
        /* drop index */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;

        /* fall-through */
    case BC_ENVELOPE:
    {
        int ret;
        /* Drop match type */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*drop comparator */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*now drop relation*/
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*now drop address part*/
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /* Now drop headers */
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote+=ret;
        /* Now drop data */
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote+=ret;
        break;
    }

    case BC_BODY:
    {
        int ret;
        /* Drop match type */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*drop comparator */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*now drop relation*/
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*now drop transform*/
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*now drop offset*/
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;
        /*now drop content-types*/
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote+=ret;
        /* Now drop data */
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote+=ret;
        break;
    }

    case BC_DATE:
    case BC_CURRENTDATE:
    {
        int ret;
        int datalen;
        int tmp;

        /* drop index */
        if(BC_DATE == opcode) {
                if(write_int(fd, bc->data[(*codep)].value) == -1)
                    return -1;
                wrote += sizeof(int);
                (*codep)++;
        }

        /* drop zone tag */
        tmp = bc->data[(*codep)].value;
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;

        /* drop timezone offset */
        if (tmp == B_TIMEZONE) {
                if(write_int(fd, bc->data[(*codep)].value) == -1)
                    return -1;
                wrote += sizeof(int);
                (*codep)++;
        }

        /* drop match type */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;

        /* drop relation */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;

        /* drop comparator */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;

        /* drop date-part */
        if(write_int(fd, bc->data[(*codep)].value) == -1)
            return -1;
        wrote += sizeof(int);
        (*codep)++;

        if (BC_DATE == opcode) {
                /* drop header-name */
                datalen = bc->data[(*codep)++].len;

                if(write_int(fd, datalen) == -1) return -1;
                wrote += sizeof(int);

                if(write(fd, bc->data[(*codep)++].str, datalen) == -1) return -1;
                wrote += datalen;

                ret = align_string(fd,datalen);
                if(ret == -1) return -1;

                wrote+=ret;
        }

        /* drop keywords */
        ret = bc_stringlist_emit(fd, codep, bc);
        if(ret < 0) return -1;
        wrote+=ret;

        break;
    }

    default:
        /* Unknown testcode? */
        return -1;
    }
    return wrote;
}
Пример #8
0
/*
 * This command allows you to do a search for any user names that match
 * a particular pattern
 */
void
grep_users(UR_OBJECT user)
{
    int found, x;
    char name[USER_NAME_LEN + 1], pat[ARR_SIZE];
    UD_OBJECT entry;

    if (word_count < 2) {
        write_user(user, "Usage: grepu <pattern>\n");
        return;
    }
    if (strstr(word[1], "**")) {
        write_user(user, "You cannot have ** in your pattern.\n");
        return;
    }
    if (strstr(word[1], "?*")) {
        write_user(user, "You cannot have ?* in your pattern.\n");
        return;
    }
    if (strstr(word[1], "*?")) {
        write_user(user, "You cannot have *? in your pattern.\n");
        return;
    }
    start_pager(user);
    write_user(user,
            "\n+----------------------------------------------------------------------------+\n");
    sprintf(text, "| ~FC~OLUser grep for pattern:~RS ~OL%-51s~RS |\n", word[1]);
    write_user(user, text);
    write_user(user,
            "+----------------------------------------------------------------------------+\n");
    x = 0;
    found = 0;
    *pat = '\0';
    strcpy(pat, word[1]);
    strtolower(pat);
    for (entry = first_user_entry; entry; entry = entry->next) {
        strcpy(name, entry->name);
        *name = tolower(*name);
        if (pattern_match(name, pat)) {
            if (!x) {
                vwrite_user(user, "| %-*s  ~FC%-20s~RS   ", USER_NAME_LEN,
                        entry->name, user_level[entry->level].name);
            } else {
                vwrite_user(user, "   %-*s  ~FC%-20s~RS |\n", USER_NAME_LEN,
                        entry->name, user_level[entry->level].name);
            }
            x = !x;
            ++found;
        }
    }
    if (x) {
        write_user(user, "                                      |\n");
    }
    if (!found) {
        write_user(user,
                "|                                                                            |\n");
        write_user(user,
                "| ~OL~FRNo users have that pattern~RS                                                 |\n");
        write_user(user,
                "|                                                                            |\n");
        write_user(user,
                "+----------------------------------------------------------------------------+\n");
        stop_pager(user);
        return;
    }
    write_user(user,
            "+----------------------------------------------------------------------------+\n");
    write_user(user,
            align_string(0, 78, 1, "|",
            "  ~OL%d~RS user%s had the pattern ~OL%s~RS ",
            found, PLTEXT_S(found), word[1]));
    write_user(user,
            "+----------------------------------------------------------------------------+\n\n");
    stop_pager(user);
}
Пример #9
0
/*
 * see list of pictures availiable--file dictated in "go" script
 */
void
preview(UR_OBJECT user)
{
#if !!0
    static const char usage[] = "Usage: preview [<picture>]\n";
#endif
    sds filename;
    char line[100];
    FILE *fp;
    DIR *dirp;
    struct dirent *dp;
    int cnt, total;

    if (word_count < 2) {
        /* open the directory file up */
        dirp = opendir(PICTFILES);
        if (!dirp) {
            write_user(user, "No list of the picture files is availiable.\n");
            return;
        }
        *line = '\0';
        cnt = total = 0;
        /* go through directory and list files */
        for (dp = readdir(dirp); dp; dp = readdir(dirp)) {
            if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) {
                continue;
            }
            if (!total++) {
                write_user(user,
                        "+----------------------------------------------------------------------------+\n");
                write_user(user,
                        "| ~OL~FCPictures available to view~RS                                                 |\n");
                write_user(user,
                        "+----------------------------------------------------------------------------+\n");
            }
            sprintf(text, "%-12.12s   ", dp->d_name);
            strcat(line, text);
            if (++cnt == 5) {
                write_user(user, align_string(0, 78, 1, "|", "  %s", line));
                *line = '\0';
                cnt = 0;
            }
        }
        closedir(dirp);
        if (total) {
            if (cnt) {
                write_user(user, align_string(0, 78, 1, "|", "  %s", line));
            }
            write_user(user,
                    "+----------------------------------------------------------------------------+\n");
            write_user(user,
                    align_string(0, 78, 1, "|", "  There are %d picture%s  ",
                    total, PLTEXT_S(total)));
            write_user(user,
                    "+----------------------------------------------------------------------------+\n\n");
        } else {
            write_user(user, "There are no pictures available to be viewed.\n");
        }
        return;
    }
    if (strpbrk(word[1], "./")) {
        write_user(user, "Sorry, there is no picture with that name.\n");
        return;
    }
    filename = sdscatfmt(sdsempty(), "%s/%s", PICTFILES, word[1]);
    fp = fopen(filename, "r");
    if (!fp) {
        write_user(user, "Sorry, there is no picture with that name.\n");
        return;
    }
    fclose(fp);
    write_user(user, "You ~OL~FGpreview the following picture...\n\n");
    switch (more(user, user->socket, filename)) {
    case 0:
        break;
    case 1:
        user->misc_op = 2;
        break;
    }
    sdsfree(filename);
}
Пример #10
0
void
show_spodlist(UR_OBJECT user)
{
    int start_pos = 1, end_pos, listed, pos = 0, hilight = 0;
    SP_OBJECT sp;

    calc_spodlist();
    sp = first_spod;

    listed = people_in_spodlist();

    if (*word[1]) {
        /* We will assume it is a position they want. If it is a name then we
           can easily overwrite it */
        hilight = atoi(word[1]);

        if (!hilight) {
            if (!find_user_listed(word[1])) {
                write_user(user, nosuchuser);
                return;
            } else {
                hilight = find_spodlist_position(word[1]);
            }
        }

        if (hilight > listed) {
            start_pos = listed - 16;
            hilight = 0;
        } else {
            start_pos = hilight - 8;
            if (start_pos < 1) {
                start_pos = 1;
            }
        }
    } else {
        /* I personally like it defaulting to a user name */
        hilight = find_spodlist_position(user->name);
        start_pos = hilight - 8;
        if (start_pos < 1) {
            start_pos = 1;
        }
    }

    end_pos = start_pos + 16;
    if (end_pos > listed) {
        end_pos = listed;
        start_pos = end_pos - 16;
    }


    /* Create the page */
    write_user(user,
            "+----------------------------------------------------------------------------+\n");
    write_user(user,
            "| ~FC~OLSpod List~RS                                                                  |\n");
    write_user(user,
            "+----------------------------------------------------------------------------+\n");


    for (pos = 1; pos <= end_pos && sp; ++pos, sp = sp->next) {
        if (pos >= start_pos) {
            vwrite_user(user, "| %s%4d. %-20s   %45s~RS |\n",
                    (pos == hilight ? "~OL~FG" : ""), pos, sp->name,
                    word_time(sp->login));
        }
    }

    if (start_pos < 1) {
        start_pos = 1;
    }
    write_user(user,
            "+----------------------------------------------------------------------------+\n");
    write_user(user,
            align_string(0, 78, 1, "|",
            "  Positions %d to %d (out of %d users) ",
            start_pos, end_pos, listed));
    write_user(user,
            "+----------------------------------------------------------------------------+\n");
}
Пример #11
0
static size_t interpret_long_filename(TALLOC_CTX *ctx,
					struct cli_state *cli,
					int level,
					const char *base_ptr,
					uint16_t recv_flags2,
					const char *p,
					const char *pdata_end,
					struct file_info *finfo,
					uint32 *p_resume_key,
					DATA_BLOB *p_last_name_raw)
{
	int len;
	size_t ret;
	const char *base = p;

	data_blob_free(p_last_name_raw);

	if (p_resume_key) {
		*p_resume_key = 0;
	}
	ZERO_STRUCTP(finfo);

	switch (level) {
		case SMB_FIND_INFO_STANDARD: /* OS/2 understands this */
			/* these dates are converted to GMT by
                           make_unix_date */
			if (pdata_end - base < 27) {
				return pdata_end - base;
			}
			finfo->ctime_ts = convert_time_t_to_timespec(
				make_unix_date2(p+4, cli_state_server_time_zone(cli)));
			finfo->atime_ts = convert_time_t_to_timespec(
				make_unix_date2(p+8, cli_state_server_time_zone(cli)));
			finfo->mtime_ts = convert_time_t_to_timespec(
				make_unix_date2(p+12, cli_state_server_time_zone(cli)));
			finfo->size = IVAL(p,16);
			finfo->mode = CVAL(p,24);
			len = CVAL(p, 26);
			p += 27;
			p += align_string(base_ptr, p, 0);

			/* We can safely use len here (which is required by OS/2)
			 * and the NAS-BASIC server instead of +2 or +1 as the
			 * STR_TERMINATE flag below is
			 * actually used as the length calculation.
			 * The len is merely an upper bound.
			 * Due to the explicit 2 byte null termination
			 * in cli_receive_trans/cli_receive_nt_trans
			 * we know this is safe. JRA + kukks
			 */

			if (p + len > pdata_end) {
				return pdata_end - base;
			}

			/* the len+2 below looks strange but it is
			   important to cope with the differences
			   between win2000 and win9x for this call
			   (tridge) */
			ret = clistr_pull_talloc(ctx,
						base_ptr,
						recv_flags2,
						&finfo->name,
						p,
						len+2,
						STR_TERMINATE);
			if (ret == (size_t)-1) {
				return pdata_end - base;
			}
			p += ret;
			return PTR_DIFF(p, base);

		case SMB_FIND_EA_SIZE: /* this is what OS/2 uses mostly */
			/* these dates are converted to GMT by
                           make_unix_date */
			if (pdata_end - base < 31) {
				return pdata_end - base;
			}
			finfo->ctime_ts = convert_time_t_to_timespec(
				make_unix_date2(p+4, cli_state_server_time_zone(cli)));
			finfo->atime_ts = convert_time_t_to_timespec(
				make_unix_date2(p+8, cli_state_server_time_zone(cli)));
			finfo->mtime_ts = convert_time_t_to_timespec(
				make_unix_date2(p+12, cli_state_server_time_zone(cli)));
			finfo->size = IVAL(p,16);
			finfo->mode = CVAL(p,24);
			len = CVAL(p, 30);
			p += 31;
			/* check for unisys! */
			if (p + len + 1 > pdata_end) {
				return pdata_end - base;
			}
			ret = clistr_pull_talloc(ctx,
						base_ptr,
						recv_flags2,
						&finfo->name,
						p,
					 	len,
						STR_NOALIGN);
			if (ret == (size_t)-1) {
				return pdata_end - base;
			}
			p += ret;
			return PTR_DIFF(p, base) + 1;

		case SMB_FIND_FILE_BOTH_DIRECTORY_INFO: /* NT uses this, but also accepts 2 */
		{
			size_t namelen, slen;

			if (pdata_end - base < 94) {
				return pdata_end - base;
			}

			p += 4; /* next entry offset */

			if (p_resume_key) {
				*p_resume_key = IVAL(p,0);
			}
			p += 4; /* fileindex */

			/* Offset zero is "create time", not "change time". */
			p += 8;
			finfo->atime_ts = interpret_long_date(p);
			p += 8;
			finfo->mtime_ts = interpret_long_date(p);
			p += 8;
			finfo->ctime_ts = interpret_long_date(p);
			p += 8;
			finfo->size = IVAL2_TO_SMB_BIG_UINT(p,0);
			p += 8;
			p += 8; /* alloc size */
			finfo->mode = CVAL(p,0);
			p += 4;
			namelen = IVAL(p,0);
			p += 4;
			p += 4; /* EA size */
			slen = SVAL(p, 0);
			if (slen > 24) {
				/* Bad short name length. */
				return pdata_end - base;
			}
			p += 2;
			ret = clistr_pull_talloc(ctx,
						base_ptr,
						recv_flags2,
						&finfo->short_name,
						p,
						slen,
						STR_UNICODE);
			if (ret == (size_t)-1) {
				return pdata_end - base;
			}
			p += 24; /* short name? */
			if (p + namelen < p || p + namelen > pdata_end) {
				return pdata_end - base;
			}
			ret = clistr_pull_talloc(ctx,
						base_ptr,
						recv_flags2,
						&finfo->name,
						p,
				    		namelen,
						0);
			if (ret == (size_t)-1) {
				return pdata_end - base;
			}

			/* To be robust in the face of unicode conversion failures
			   we need to copy the raw bytes of the last name seen here.
			   Namelen doesn't include the terminating unicode null, so
			   copy it here. */

			if (p_last_name_raw) {
				*p_last_name_raw = data_blob(NULL, namelen+2);
				memcpy(p_last_name_raw->data, p, namelen);
				SSVAL(p_last_name_raw->data, namelen, 0);
			}
			return calc_next_entry_offset(base, pdata_end);
		}
	}

	DEBUG(1,("Unknown long filename format %d\n",level));
	return calc_next_entry_offset(base, pdata_end);
}