Exemplo n.º 1
0
/** insert one IDENTIFIER or DYN_ATTRIBUTE */
int sTableInsertId(struct Node* node, int ttype) {
    if ( ttype < DYN_STRING_T  && ttype!=DYNAMIC_T) { // take care of declare unsupported type for attribute
        ERRNO = ErrorAttributeTypeNotSupported;
        errorInfo(ERRNO, node->line, "Type `%s' is not supported for Attribute\n", sTypeName(ttype));
        return ERRNO;
    } 
    else if ( ttype == VOID_T ) {
        ERRNO = ErrorVoidTypeVariableNotSupported;
        errorInfo(ERRNO, node->line, " cannot declare `void' variable.\n");
        return ERRNO;
    }
   
    SymbolTableEntry* entry = sNewVarEty ( node->lexval.sval, ttype, node->line );
    if ( sTableInsert( entry ) == ErrorSymbolTableKeyAlreadyExsit ) {
        SymbolTableEntry * te = sTableLookup(entry->key);
        ERRNO = ErrorIdentifierAlreadyDeclared;
        errorInfo(ERRNO, node->line,"`%s%s' is already declared.\n",(ttype<0)?"@":"", node->lexval.sval);
        errorInfoNote("`%s%s' is first declared at line %d\n", 
           (ttype<0)?"@":"",node->lexval.sval, te->line);
        return ERRNO;
        // should tell where first declared
    }
    node->symbol = entry;
    node->type   = ttype;
    return 0;
}
void waitSession(){
    int pid;
    while (1) {
        printf("Server ready, wait client's connection...\n");
        recvfd = accept(listenfd, NULL, NULL);
        if (recvfd < 0) {
            errorInfo("accept failed");
            exit(-1);
        }
        int len = sizeof(client_addr);
        getpeername(recvfd, (struct sockaddr*)&client_addr, &len);
        printf("accept a connection from %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
        switch (pid = fork()) {
            case -1:
                errorInfo("The fork failed!");
                break;
            case 0:
                close(listenfd);
                if (startService() == -1) exit(-1);
                len = sizeof(client_addr);
                getpeername(recvfd, (struct sockaddr*)&client_addr, &len);
                printf("Client %s:%d quit!\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
                close(recvfd);
                exit(0);            
            default:
                close(recvfd);
                continue;
        }
    }
    return;
}
int serverStart(){
    int sockfd;
    
    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        errorInfo("Create socket failed!");
        exit(-1);
    }

    memset(&serverAddr, 0, sizeof(serverAddr));
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port = htons(server_port);
    serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    
    if (bind(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) < 0) {
        errorInfo("bind failed!");
        close(sockfd);
        exit(-1);
    }

    if (listen(sockfd, BACKLOG) < 0) {
        errorInfo("listen failed");
        close(sockfd);
        exit(-1);
    }

    printf("Create server listen socket successfully: %s:%d\n", inet_ntoa(serverAddr.sin_addr), ntohs(serverAddr.sin_port));
    return sockfd;
}
Exemplo n.º 4
0
void TinyXMLHelper::LoadFile(const char* filePath)
{
	m_metaDoc = new	TiXmlDocument(filePath);
	bool loadSuccessfully = m_metaDoc->LoadFile();
	if(!loadSuccessfully)
	{
		std::string errorInfo(filePath);
		errorInfo = "Failed to load file : " + errorInfo;
		MessageBoxA( NULL , errorInfo.c_str(), "Failed to loading files", MB_ICONERROR | MB_OK );
		exit(0);
	}

	if(m_metaDoc->ErrorId() > 0)
	{
		std::string errorInfo(filePath);
		errorInfo = "Error , can't analysis meta-data file : " + errorInfo + "\n\n";
		MessageBoxA( NULL , (LPCSTR)errorInfo.c_str() , "Load Failed!", MB_ICONERROR | MB_OK );
	}

	m_root = m_metaDoc->RootElement();
	if(!m_root)
	{
		std::string errorInfo(filePath);
		errorInfo = "Error , can't find root element of meta-data file : " + errorInfo + "\n\n";
		MessageBoxA( NULL , (LPCSTR)errorInfo.c_str() , "Load Failed!", MB_ICONERROR | MB_OK );
	}
}
void execPut(char* filename){
    char data_port[BUFFER_SIZE], buf[BUFFER_SIZE];
    int port = get_port();
    FILE *file = fopen(filename, "wb");
    if (!file){
        errorInfo("Can't open file!");
        return ;
    } 
    else{
        send(recvfd, SUCCESS, BUFFER_SIZE, 0);
    }
    sprintf(data_port, "%d", port);
    send(recvfd, data_port, BUFFER_SIZE, 0);

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = serverAddr.sin_addr.s_addr;
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    bind(sockfd, (struct sockaddr*)&addr, sizeof(addr));
    listen(sockfd, BACKLOG);
    int putfd = accept(sockfd, (struct sockaddr*)NULL, NULL);
    int len;
    while ((len = recv(putfd, buf, BUFFER_SIZE, 0)) >0){
        if (fwrite(buf, 1, len, file) != len) {
            errorInfo("File write error!");
            return;
        }
    }
    printf("file %s put successfully!\n", filename);
    close(putfd);
    close(sockfd);
    fclose(file);
    return;
}
void execDir(){
    char buf[BUFFER_SIZE], data_port[BUFFER_SIZE];
    int port = get_port();
    send(recvfd, SUCCESS, BUFFER_SIZE, 0);
    sprintf(data_port, "%d", port);
    send(recvfd, data_port, BUFFER_SIZE, 0);

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = serverAddr.sin_addr.s_addr;

    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    bind(sockfd, (struct sockaddr*)&addr, sizeof(addr));
    listen(sockfd, BACKLOG);
    int datarecvfd = accept(sockfd, (struct sockaddr*)NULL, NULL);
    
    system("ls > .temp");
    int file = open("./.temp", O_RDONLY);
    int len;
    while((len = read(file, buf, BUFFER_SIZE))>0) {
        if (send(datarecvfd, buf, len, 0) != len) {
            errorInfo("Send error!");
            close(sockfd);
            close(datarecvfd);
            return;
        }
    }
    close(sockfd);
    close(datarecvfd);
    system("rm .temp");
    printf("COMMAND DIR SUCCEED!\n");
    return;
}
void execGet(char* filename){        
    char data_port[BUFFER_SIZE], buf[BUFFER_SIZE];
    FILE* file = fopen(filename, "rb");
    if (!file) {
        send(recvfd, FAILURE, BUFFER_SIZE, 0);
        return;
    }
    send(recvfd, SUCCESS, BUFFER_SIZE, 0);
    int port = get_port();
    sprintf(data_port, "%d", port);
    send(recvfd, data_port, BUFFER_SIZE, 0);

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = serverAddr.sin_addr.s_addr;

    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    bind(sockfd, (struct sockaddr*)&addr, sizeof(addr));
    listen(sockfd, BACKLOG);
    int getfd = accept(sockfd, (struct sockaddr*)NULL, NULL);
    int len;
    while ((len = fread(buf, 1, BUFFER_SIZE, file))>0) {
        if (send(getfd, buf, len, 0) != len) {
            errorInfo("Send data error!");
            return;
        }
    }
    printf("file %s get successfully!\n", filename);
    close(getfd);
    close(sockfd);
    fclose(file);
}
Exemplo n.º 8
0
void Error(ErrorType error, ConstructPtr construct, const std::string &data) {
  if (hhvm) return;
  ErrorInfoPtr errorInfo(new ErrorInfo());
  errorInfo->m_error = error;
  errorInfo->m_construct1 = construct;
  errorInfo->m_data = data;
  s_code_errors.record(errorInfo);
}
Exemplo n.º 9
0
void Error(ErrorType error, ConstructPtr construct) {
  if (hhvm) return;
  ErrorInfoPtr errorInfo(new ErrorInfo());
  errorInfo->m_error = error;
  errorInfo->m_construct1 = construct;
  errorInfo->m_data = construct->getText();
  s_code_errors.record(errorInfo);
}
Exemplo n.º 10
0
void Error(ErrorType error, ConstructPtr construct1, ConstructPtr construct2) {
  if (!Option::RecordErrors) return;
  ErrorInfoPtr errorInfo(new ErrorInfo());
  errorInfo->m_error = error;
  errorInfo->m_construct1 = construct1;
  errorInfo->m_construct2 = construct2;
  errorInfo->m_data = construct1->getText();
  s_code_errors.record(errorInfo);
}
Exemplo n.º 11
0
/** lookup an Id from symtable, if not found report compiling error */
int sTableLookupId(struct Node* node) {
    SymbolTableEntry* entry = sTableTryLookupId(node);
    if(entry == NULL) {
        ERRNO = ErrorIdentifierUsedBeforeDeclaration;
        errorInfo(ERRNO, node->line,"`%s' is not declared before.\n", node->lexval.sval);
        return ERRNO;
    }
    node->symbol = entry;
    node->type = entry->type;
    return 0;
}
void execCd(char* path){
    int k = chdir(path);
    char newPath[BUFFER_SIZE];
    if (k == 0) {
        getcwd(newPath, BUFFER_SIZE);
        send(recvfd, SUCCESS, BUFFER_SIZE, 0);
        send(recvfd, newPath, BUFFER_SIZE, 0);        
    } 
    else {
        send(recvfd, FAILURE, BUFFER_SIZE, 0);
        errorInfo("chdir error!");
    }
    return;
}
Exemplo n.º 13
0
void Process::check_error(QVariantMap const &error_info)
{
    if (!rc())
        return;
    QVariantMap err = {{"msg", "Process error"}
                       , {"cmd", ps->program()}
                       , {"args", QVariant(ps->arguments())}
                       , {"rc", rc()}
                       , {"stderr", stderr()}
                       , {"stdout", stdout()}
                       , {"info", errorInfo()}};
    err.unite(error_info);
    error::raise(err);
}
int login(){
    char username[BUFFER_SIZE],password[BUFFER_SIZE];
    recv(recvfd, username, BUFFER_SIZE, 0);
    recv(recvfd, password, BUFFER_SIZE, 0);
    if(!strcmp(username, USERNAME) && !strcmp(password, PASSWORD)){
        printf("Client:%d login successfully!\n",ntohs(client_addr.sin_port));
        send(recvfd, SUCCESS, BUFFER_SIZE, 0);
    } 
    else{
        errorInfo("Client login failed!");
        send(recvfd, FAILURE, BUFFER_SIZE, 0);
        return -1;
    }
    return 0;
}
Exemplo n.º 15
0
void RedisServer::handleDiscoveryInfoResponceEvent(events::DiscoveryInfoResponceEvent* ev) {
  auto v = ev->value();
  common::Error er = v.errorInfo();
  if (!er) {
    RedisServerInfo * rinf = dynamic_cast<RedisServerInfo*>(v.sinfo.get());
    CHECK(rinf);
    if (rinf->replication_.role_ == "master") {
      role_ = MASTER;
    } else if(rinf->replication_.role_ == "slave") {
      role_ = SLAVE;
    } else {
      NOTREACHED();
    }
  }
  IServer::handleDiscoveryInfoResponceEvent(ev);
}
Exemplo n.º 16
0
/** insert a func_literal */
int sTableInsertFuncLiteral(struct Node* node) {
    struct Node* declSpec = node->child[1];
    struct Node* funcId   = node->child[0]->child[0];
    SymbolTableEntry* entry = sNewFunEty ( funcId->lexval.sval, FUNC_LITERAL_T, declSpec->lexval.ival, node->typeCon, node->scope[0], node->scope[1], node->line );
    if ( sTableInsert( entry ) == ErrorSymbolTableKeyAlreadyExsit ) {
        SymbolTableEntry * te = sTableLookup(entry->key);
        ERRNO = ErrorIdentifierAlreadyDeclared;
        errorInfo(ERRNO, node->line,"`%s' is already declared.\n", funcId->lexval.sval);
        errorInfoNote("`%s' is first declared at line %d\n",
           funcId->lexval.sval, te->line);
        return ERRNO;
    }
    node->symbol = entry;
    node->type = FUNC_T;
    return 0;
}
Exemplo n.º 17
0
/** lookup a func or func_literal, if not found report compiling error */
int sTableLookupFunc(struct Node* node) {
    if(node->token != AST_FUNC_CALL) {
        fprintf(stderr,"error: sTableLookupFunc: argument must be AST_FUNC_CALL\n");
        exit(EXIT_FAILURE);
    }
    SymbolTableKey key;
    SymbolTableEntry* entry;
    struct Node* funcId = node->child[0];
    // create key
    sNewKey(funcId->lexval.sval, 0, key);       // function always in scope 0
    // try lookup in Symbol Table
    entry = sTableLookup(key);
    if(entry == NULL) {
        ERRNO = ErrorFunctionCalledBeforeDeclaration;
        errorInfo(ERRNO, node->line, "`");
        FuncHead(funcId->lexval.sval, node->typeCon, ERRORIO);
        errorInfoExt("' is not declared before.\n");
        return ERRNO;
    }
    // if found, check parameter types
    GArray* caller = node->typeCon;
    GArray* ref    = entry->typeCon;
    int flag = 0;
/*    if(entry->type == FUNC_T) {   // if function
        if(caller->len != ref->len) {
            flag = (ERRNO = ErrorFunctionCallNOTEqualNumberOfParameters); 
            errorInfo(ERRNO, node->line, "function Call `");
            FuncHead(funcId->lexval.sval, caller, ERRORIO);
            errorInfoExt("' has inconsistent number of arguments to its declaration.\n");
        }
        else {
            if ( checkTwoTypeCons(caller, ref) == 0 ) { // not equal
                flag = (ERRNO = ErrorFunctionCallIncompatibleParameterType);
                errorInfo(ERRNO, node->line, "function Call `");
                FuncHead(funcId->lexval.sval, caller, ERRORIO);
                errorInfoExt("' has incompatible arguments to its declaration.\n");
            }
        }
    }
    else if(entry->type == FUNC_LITERAL_T) { // func_literal
        if ( checkTwoTypeConsExceptDyn(caller, ref) == 0 ) { // not equal
            flag = (ERRNO = ErrorFuncLiteralCallIncompatibleParameterType);
            errorInfo(ERRNO, node->line, "function literal Call `");
            FuncHead(funcId->lexval.sval, caller, ERRORIO);
            errorInfoExt("' has incompatible arguments to its declaration.\n");
        }
    }
    else {
        flag = (ERRNO = ErrorFunctionCalledBeforeDeclaration);
        errorInfo(ERRNO, node->line,"`%s' is not declared as a function or function literal\n",funcId->lexval.sval );
        errorInfoNote("`%s' is first declared at line %d\n",funcId->lexval.sval,entry->line);
        return ERRNO;
    }*/
    if (flag == ErrorFunctionCallNOTEqualNumberOfParameters ||
            flag == ErrorFunctionCallIncompatibleParameterType ||
                flag == ErrorFuncLiteralCallIncompatibleParameterType ) {
        errorInfoNote("function `");
        FuncHead(funcId->lexval.sval, ref, ERRORIO);
        errorInfoExt("' first declared at line %d\n",entry->line);    
        return ERRNO;
    }
    // found correct one
    node->symbol = entry;
    node->type = entry->rtype;
    return 0;
}