コード例 #1
0
ファイル: utmpsync.c プロジェクト: ChunHungLiu/pttbbs
int main(int argc, char **argv)
{
    int     sfd, index, i;
    attach_SHM();
    if( (sfd = toconnect(UTMPD_ADDR)) < 0 ) {
	printf("connect fail\n");
	return 1;
    }

    index = -1;
    towrite(sfd, &index, sizeof(index));
    for( i = 0 ; i < USHM_SIZE ; ++i )
	if( towrite(sfd, &SHM->uinfo[i].uid, sizeof(SHM->uinfo[i].uid)) <= 0 ||
	    towrite(sfd, SHM->uinfo[i].myfriend,
		    sizeof(SHM->uinfo[i].myfriend)) <= 0                     ||
	    towrite(sfd, SHM->uinfo[i].reject,
		    sizeof(SHM->uinfo[i].reject)) <= 0                       ){
	    fprintf(stderr, "sync error %d\n", i);
	}
    return 0;
}
コード例 #2
0
ファイル: regmailc.c プロジェクト: ChunHungLiu/pttbbs
int main(int argc, char *argv[])
{
    int fd, ret = 0;
    int op = 0;
    regmaildb_req req = {0};

    if (argc < 4) {
	fprintf(stderr, "Usage: %s operation userid email\n", argv[0]);
	return 0;
    }

    if ( (fd = toconnect(REGMAILD_ADDR)) < 0 ) {
	perror("toconnect");
	return 1;
    }

    if (strcmp(argv[1], "count") == 0)
    {
	op = REGMAILDB_REQ_COUNT;
	strlcpy(req.userid, argv[2], sizeof(req.userid));
	strlcpy(req.email,  argv[3], sizeof(req.email));
    }
    else if (strcmp(argv[1], "set") == 0)
    {
	op = REGMAILDB_REQ_SET;
	strlcpy(req.userid, argv[2], sizeof(req.userid));
	strlcpy(req.email,  argv[3], sizeof(req.email));
    }
    else if (strcmp(argv[1], "amb") == 0)
    {
	op = REGCHECK_REQ_AMBIGUOUS;
	strlcpy(req.userid, argv[2], sizeof(req.userid));
	strlcpy(req.email,  "*****@*****.**", sizeof(req.email));
    }
    else
	return 0;

    req.cb = sizeof(req);
    req.operation = op;

    if (towrite(fd, &req, sizeof(req)) != sizeof(req)) {
	perror("towrite");
	return 1;
    }

    if (toread(fd, &ret, sizeof(ret)) != sizeof(ret)) {
	perror("toread");
	return 1;
    }

    printf("result: %d\n", ret);
    return 0;
}
コード例 #3
0
ファイル: regmaild.c プロジェクト: OmniBus/hkday-pttbbs
static void 
client_cb(int fd, short event, void *arg)
{
    struct event *ev = (struct event*) arg;
    regmaildb_req req = {0};
    int ret = -1;

    assert(ev);

    if ( (event & EV_TIMEOUT) ||
        !(event & EV_READ) ||
         toread(fd, &req, sizeof(req)) != sizeof(req) ||
         req.cb != sizeof(req))
    {
        fprintf(stderr, "error: corrupted request.\r\n");
        close(fd);
        free(ev);
        return;
    }


    switch(req.operation)
    {
        case REGMAILDB_REQ_COUNT:
            if (!*req.userid || !*req.email) {
                err_request(&req, fd, ev);
                return;
            }
            ret = regmaildb_check_email(req.email, strlen(req.email), req.userid);
            fprintf(stderr, "%-*s check  mail (result: %d): [%s]\r\n", 
                    IDLEN, req.userid, ret, req.email);
            if (towrite(fd, &ret, sizeof(ret)) != sizeof(ret))
            {
                fprintf(stderr, " error: cannot write response...\r\n");
            }
            break;

        case REGMAILDB_REQ_SET:
            if (!*req.userid || !*req.email) {
                err_request(&req, fd, ev);
                return;
            }
            ret = regmaildb_update_email(req.userid, strlen(req.userid),
                    req.email, strlen(req.email));
            fprintf(stderr, "%-*s UPDATE mail (result: %d): [%s]\r\n", 
                    IDLEN, req.userid, ret, req.email);
            if (towrite(fd, &ret, sizeof(ret)) != sizeof(ret))
            {
                fprintf(stderr, " error: cannot write response...\r\n");
            }
            break;

        case REGCHECK_REQ_AMBIGUOUS:
            ret = regcheck_ambiguous_id(req.userid);
            fprintf(stderr, "%-*s check ambiguous id exist (result: %d)\r\n", 
                    IDLEN, req.userid, ret);
            if (towrite(fd, &ret, sizeof(ret)) != sizeof(ret))
            {
                fprintf(stderr, " error: cannot write response...\r\n");
            }
            break;

        default:
            fprintf(stderr, "error: invalid operation: %d.\r\n", req.operation);
            close(fd);
            free(ev);
            return;
    }

    // close connection anyway
    close(fd);
    free(ev);
}
コード例 #4
0
ファイル: loginc.c プロジェクト: ChunHungLiu/pttbbs
int main(int argc, char *argv[])
{
    int fd;
    char buf[64];

    Signal(SIGPIPE, SIG_IGN);
    memset(buf, 0, sizeof(buf));

    if (argc < 2) {
	fprintf(stderr, "Usage: %s tunnel_path\n", argv[0]);
	return 0;
    }

    if ( (fd = toconnect(argv[1])) < 0 ) {
	perror("toconnect");
	return 1;
    }

    puts("start waiting!\n");
    while (1)
    {
	int xfd = 0, i;
	const char *encoding = "";
	login_data dat = {0};

	if ((xfd = recv_remote_fd(fd, argv[1])) < 0) 
	{
	    fprintf(stderr, "recv_remote_fd error. abort.\r\n");
	    break;
	}
	puts("got recv_remote_fd");
	if (toread(fd, &dat, sizeof(dat)) <= 0)
	{
	    fprintf(stderr, "toread error. abort.\r\n");
	    break;
	}
	if (towrite(fd, &dat.ack, sizeof(dat.ack)) <= 0) {
	    fprintf(stderr, "towrite error. abort.\r\n");
	    break;
	}
#ifdef CONVERT
	switch (dat.encoding)
	{
	    case CONV_UTF8:
		encoding = "[UTF-8] ";
		break;
	}
#endif
	fprintf(stderr, "got login data: userid=%s, (%dx%d) %sfrom: %s\r\n", 
		dat.userid, dat.t_cols, dat.t_lines, 
		encoding, dat.hostip);

	if (xfd != 0) dup2(xfd, 0);
	if (xfd != 1) dup2(xfd, 1);

	// write something to user!
	printf("\r\nwelcome, %s from %s! greetings from loginc!\r\n", dat.userid, dat.hostip);
	printf("please give me 3 key hits to test i/o!\r\n");

	for (i = 0; i < 3; i++)
	{
	    char c;
	    read(0, &c, sizeof(c));
	    printf("you hit %02X\r\n", c);
	}
	printf("\r\ntest complete. connection closed.\r\n");
	close(0);
	close(1);
	if (xfd != 0 && xfd != 1) close(xfd);
    }
    return 0;
}
コード例 #5
0
ファイル: abc.c プロジェクト: ChunHungLiu/pttbbs
int main(int argc, char *argv[])
{
    int fd;
    angel_beats_data req = {0};
    angel_beats_report rpt = {0};
    angel_beats_uid_list list = {0};
    attach_SHM();

    if (argc < 2) {
	fprintf(stderr, "Usage: %s operation [uid]\n", argv[0]);
	return 0;
    }
    if ( (fd = toconnect(ANGELBEATS_ADDR)) < 0 ) {
	perror("toconnect");
	return 1;
    }

    // start commands
    if (strcmp(argv[1], "reload") == 0) {
        req.operation = ANGELBEATS_REQ_RELOAD;
    } else if (strcmp(argv[1], "suggest") == 0) {
        req.operation = ANGELBEATS_REQ_SUGGEST;
        if (argc > 2) {
            req.operation = ANGELBEATS_REQ_SUGGEST_AND_LINK;
            req.master_uid = searchuser(argv[2], NULL);
        }
    } else if (strcmp(argv[1], "unlink") == 0) {
        if (argc != 3) {
            printf("need target id.\n");
            return -1;
        }
        req.operation = ANGELBEATS_REQ_REMOVE_LINK;
        req.master_uid = 0; // anyone, just unlink
        req.angel_uid = searchuser(argv[2], NULL);
        if (!req.angel_uid) {
            printf("invalid user id: %s\n", argv[2]);
            return -1;
        }
    } else if (strcmp(argv[1], "report") == 0) {
        req.operation = ANGELBEATS_REQ_REPORT;
        if (argc > 2 && !(req.angel_uid = searchuser(argv[2], NULL))) {
            printf("invalid user id: %s\n", argv[2]);
            return -1;
        }
    } else if (strcmp(argv[1], "list") == 0) {
        req.operation = ANGELBEATS_REQ_GET_ONLINE_LIST;
    } else if (strcmp(argv[1], "save") == 0) {
        req.operation = ANGELBEATS_REQ_SAVE_STATE;
    } else if (strcmp(argv[1], "perf") == 0) {
        req.operation = ANGELBEATS_REQ_EXPORT_PERF;
    } else {
        fprintf(stderr, "Sorry, unknown command: %s\n", argv[1]);
	return 0;
    }

    req.cb = sizeof(req);
    if (towrite(fd, &req, sizeof(req)) != sizeof(req)) {
	perror("towrite");
	return 1;
    }
    if (req.operation == ANGELBEATS_REQ_REPORT) {
        if (toread(fd, &rpt, sizeof(rpt)) != sizeof(rpt)) {
            perror("toread");
            return 1;
        }
        assert(rpt.cb == sizeof(rpt));
        printf("total_angels=%d\n"
               "total_online_angels=%d\n"
               "total_active_angels=%d\n"
               "min_masters_of_online_angels=%d\n"
               "max_masters_of_online_angels=%d\n"
               "min_masters_of_active_angels=%d\n"
               "max_masters_of_active_angels=%d\n"
               "my_index=%d\n"
               "my_active_index=%d\n"
               "my_active_masters=%d\n",
               rpt.total_angels,
               rpt.total_online_angels,
               rpt.total_active_angels,
               rpt.min_masters_of_online_angels,
               rpt.max_masters_of_online_angels,
               rpt.min_masters_of_active_angels,
               rpt.max_masters_of_active_angels,
               rpt.my_index,
               rpt.my_active_index,
               rpt.my_active_masters);
    } else if (req.operation == ANGELBEATS_REQ_GET_ONLINE_LIST) {
        int i;
        if (toread(fd, &list, sizeof(list)) != sizeof(list)) {
            perror("toread");
            return 1;
        }
        assert(list.cb == sizeof(list));
        printf("angels=%d\n", list.angels);
        for (i = 0; i < list.angels; i++) {
            printf("%3d. %s\n", i + 1, getuserid(list.uids[i]));
        }
    } else {
        if (toread(fd, &req, sizeof(req)) != sizeof(req)) {
            perror("toread");
            return 1;
        }
        printf("result: angel_uid=%d\n", req.angel_uid);
    }

    return 0;
}
コード例 #6
0
ファイル: helpbox.cpp プロジェクト: Kytuzu/PCHex-plusplus
void Helpbox::draw() {
    std::string towrite(button+": "+msg);
    int textsize = sftd_get_text_width(font, 6, towrite.c_str());
    sf2d_draw_texture(this->texture, this->posx, this->posy);
    sftd_draw_text(font, (this->posx)+(this->texture->width/2)-(textsize/2), this->posy+3,  RGBA8(0, 0, 0, 255), 6, towrite.c_str());
}
コード例 #7
0
int main ()
{
  try 
  {
 
    /********** Setup ************/
    saga::session s;
    saga::context c ("opencloud");
    s.add_context  (c) ; 

    /********** Write File************/
    std::cout << std::endl ; 
    std::cout << std::endl ; 
    saga::filesystem::file f (s, "sector://test", saga::filesystem::ReadWrite ) ; 
    std::string towrite ("hello world !\n") ; 
    saga::const_buffer buf ( towrite.c_str(), towrite.length()) ; 
    f.write( buf, towrite.length()) ;  
    std::cout << "Written data: " << towrite ; 


    /********** Read File************/
    saga::mutable_buffer bufread ( towrite.length()) ; 
    f.read( bufread, towrite.length()) ; 
    std::cout << "Data read: " << (char*) bufread.get_data() ;  


    /********* Seek File ************/
    std::cout << "Seek to the end .. " << std::endl ; 
    f.seek( towrite.length(), saga::filesystem::Start ) ; 
    std::string w2 (" clouds!") ; 
    std::cout << "Write some more: " << w2 << std::endl ; 
    saga::const_buffer buf2( w2.c_str(), w2.length()) ; 
    f.write( buf2, w2.length()) ; 

    /********* Read new data ************/
    f.seek( 0, saga::filesystem::Start ) ; 
    saga::mutable_buffer bufread2( towrite.length() + w2.length() + 1 ) ; 
    f.read( bufread2, towrite.length() + w2.length() + 1 ) ; 
    std::cout << "Data read after seek and write: " << (char*) bufread2.get_data() << std::endl ; 

    f.close() ; 

    
    /********* Directory ***************/

    /*Create directories 
     */
    std::cout << std::endl ; 
    std::cout << "Create directory my_dir..." << std::endl ; 
    std::cout << "Create directory my_dir/another_dir..." << std::endl ; 
    saga::url dir ("sector://my_dir") ;
    saga::url dir2 ("sector://my_dir/another_dir") ;
    saga::filesystem::directory d( s, dir ) ; 
    saga::filesystem::directory d2( s, dir2 ) ; 

    /* Change working directory
     */
    std::cout << "Changing cwd to  my_dir/another_dir..." << std::endl ; 
    d.change_dir("another_dir") ; 
    std::cout << "Creating my_dir/another_dir/nested_dir ... " << std::endl ; 
    d.make_dir("nested_dir") ; 

    /* Populate Directories
     */
    std::cout << "Populate files in nested_dir ... " << std::endl ; 
    saga::filesystem::file f2 (s, "my_dir/another_dir/nested_dir/file1", saga::filesystem::ReadWrite ) ; 
    saga::filesystem::file f3 (s, "my_dir/another_dir/nested_dir/file2", saga::filesystem::ReadWrite ) ; 
    saga::filesystem::file f4 (s, "my_dir/another_dir/nested_dir/file3", saga::filesystem::ReadWrite ) ; 
    saga::filesystem::file f5 (s, "/makeme/file3", saga::filesystem::ReadWrite ) ; 
    f2.close() ; 
    f3.close() ; 
    f4.close() ; 
    f5.close() ; 

    /* List directory
     */
    d.change_dir("nested_dir") ; 
    std::vector <saga::url> listing = d.list() ; 
    std::cout << "List nested_dir ..." << std::endl ; 
    for ( std::vector<saga::url>::iterator i = listing.begin(); i != listing.end(); ++ i) 
    {
       std::cout << i->get_string() << std::endl ;  
    }

    /* Copy Files */
    d.copy( "file1", "sector:///" )  ; 

    return 0 ; 
   
  }
  catch ( const saga::exception & e )
  {
    std::cerr << e.what ();
  }
}