Exemple #1
0
void C_RLibrary::initdll()
{
  ext_info.global_registers=NSEEL_getglobalregs();

  HANDLE h;
  WIN32_FIND_DATA d;
  char dirmask[MAX_PATH*2];
#ifdef LASER
  wsprintf(dirmask,"%s\\*.lpe",g_path);
#else
  wsprintf(dirmask,"%s\\*.ape",g_path);
#endif
  h = FindFirstFile(dirmask,&d);
	if (h != INVALID_HANDLE_VALUE)
	{
		do {
      char s[MAX_PATH];
      HINSTANCE hlib;
      wsprintf(s,"%s\\%s",g_path,d.cFileName);
      hlib=LoadLibrary(s);
      if (hlib)
      {
        int cre;
        char *inf;

        void (*sei)(HINSTANCE hDllInstance, APEinfo *ptr);
        *(void**)&sei = (void *) GetProcAddress(hlib,"_AVS_APE_SetExtInfo");
        if (sei)
          sei(hlib,&ext_info);

#ifdef LASER
        int (*retr)(HINSTANCE hDllInstance, char **info, int *create, C_LineListBase *linelist);
        retr = (int (*)(HINSTANCE, char ** ,int *, C_LineListBase*)) GetProcAddress(hlib,"_AVS_LPE_RetrFunc");
        if (retr && retr(hlib,&inf,&cre,g_laser_linelist))
        {
          _add_dll(hlib,(class C_RBASE *(__cdecl *)(char *))cre,inf,0);
        }
        else FreeLibrary(hlib);
#else
        int (*retr)(HINSTANCE hDllInstance, char **info, int *create);
        retr = (int (*)(HINSTANCE, char ** ,int *)) GetProcAddress(hlib,"_AVS_APE_RetrFuncEXT2");
        if (retr && retr(hlib,&inf,&cre))
        {
          _add_dll(hlib,(class C_RBASE *(__cdecl *)(char *))cre,inf,1);
        }
        else
        {
          retr = (int (*)(HINSTANCE, char ** ,int *)) GetProcAddress(hlib,"_AVS_APE_RetrFunc");
          if (retr && retr(hlib,&inf,&cre))
          {
            _add_dll(hlib,(class C_RBASE *(__cdecl *)(char *))cre,inf,0);
          }
          else FreeLibrary(hlib);
        }
#endif
      }	  	
		} while (FindNextFile(h,&d));
		FindClose(h);
  }	
}
Exemple #2
0
int
request_type14(int id,int major,int minor,int* cxt,
	       int* aux0,char* buf,int bufsize)
{
  canna_server* svr = &server[id];
  canna_request_type14 req;
  int size;
  int sub;

  if (retr(svr,&req.size,2)) return -1;
  size = ntohs(req.size);
  size -= 6;
  if (size < 2 || bufsize < size) return -1;
  req.data = malloc(size);
  if (req.data == 0) return -1;
  if (retr(svr,&req.mode,4)) return -1;
  if (retr(svr,&req.cxt,2)) return -1;
  *cxt = (int16_t)ntohs(req.cxt);
  *aux0 = ntohl(req.mode);
  if (retr(svr,req.data,size)) return -1;
  sub = narrow(buf,bufsize,req.data,size/2);
  if (sub == -1) return -1;
  if (*(buf+sub-1) != 0) return -1;
  free(req.data);
  return 0;
}
Exemple #3
0
int
request_type10(int id,int major,int minor,int* cxt,
	       int* aux0,int* aux1,char* buf,int bufsize)
{
  canna_server* svr = &server[id];
  canna_request_type10 req;
  int32_t* data = (int32_t*)buf;
  int size;
  int i;

  if (retr(svr,&req.size,2)) return -1;
  size = ntohs(req.size);
  size -= 8;
  if (size < 0) return -1;
  req.data = malloc(size);
  if (req.data == 0) return -1;
  if (retr(svr,&req.cxt,2)) return -1;
  if (retr(svr,&req.num,2)) return -1;
  if (retr(svr,&req.mode,4)) return -1;
  if (retr(svr,req.data,size)) return -1;
  *cxt = (int16_t)ntohs(req.cxt);
  *aux0 = (int16_t)ntohs(req.num);
  *aux1 = ntohl(req.mode);
  for (i = 0; i < *aux0; i++)
    data[i] = (int16_t)ntohs(req.data[i]);
  free(req.data);
  return 0;
}
// ------------------------------------retr----------------------------------------------- 
// Description: recursively finds a given leaf and sets sub to that leaf
// -------------------------------------------------------------------------------------------------------------
BinTree::Node *BinTree::retr(const NodeData &key, Node *sub) const
{
    if(sub == NULL)
        return NULL;
    else if(key == *sub->data)
        return sub;
    else if(key < *sub->data)
        return retr(key, sub->left);
    else
        return retr(key, sub->right);
}
Exemple #5
0
int
request_type2(int id,int major,int minor,int* cxt)
{
  canna_server* svr = &server[id];
  canna_request_type2 req;
  int size;

  if (retr(svr,&req.size,2)) return -1;
  size = ntohs(req.size);
  if (size != 2) return -1;
  if (retr(svr,&req.data,2)) return -1;
  *cxt = (int16_t)ntohs(req.data);
  return 0;
}
// ------------------------------------getHeight----------------------------------------------- 
// Description: sets a Node pointer to the calling objects root. 
//      sets another node pointer to the value of the recursive call to retr
//          uses that result to call recursive getH function
// -------------------------------------------------------------------------------------------------------------
int BinTree::getHeight (const NodeData &key) const
{
    Node *node = this->root;
    Node *pointer = retr(key, node);

    return getH(pointer);
}
Exemple #7
0
int
request_type7(int id,int major,int minor,int* cxt,int* aux0,int* aux1)
{
  canna_server* svr = &server[id];
  canna_request_type7 req;
  int size;

  if (retr(svr,&req.size,2)) return -1;
  size = ntohs(req.size);
  if (size != 6) return -1;
  if (retr(svr,&req.cxt,2)) return -1;
  if (retr(svr,&req.idx,2)) return -1;
  if (retr(svr,&req.data,2)) return -1;
  *cxt = (int16_t)ntohs(req.cxt);
  *aux0 = (int16_t)ntohs(req.idx);
  *aux1 = (int16_t)ntohs(req.data);
  return 0;
}
// ------------------------------------Retreive----------------------------------------------- 
// Description: sets NodeData *p to the value of the desired leaf if it exists
//  calls recursive retr to set pointer
//      if it does not exist, returns false and pointer is NULL
// -------------------------------------------------------------------------------------------------------------
bool BinTree::retrieve(const NodeData &key, NodeData* &p) const
{
    Node *node = this->root;
    Node *pointer = retr(key, node);

    if(pointer != NULL)
        p = pointer->data;
    else return false;

    return true;
}
Exemple #9
0
int
canna_accept(int id,int* major,int* minor,int* aux0,char* buf,int bufsize)
{
  canna_server* svr = &server[id];
  canna_request_type0 req;
  int maj;
  int size;
  char* token;

  if (svr->sock == -1) {
    svr->in = svr->in; svr->out = svr->out;
  } else {
    svr->in = svr->out = accept(svr->sock,0,0);
    if (svr->in == -1) {
      perror("accept");
      return -1;
    }
  }
  if (svr->mode == 0) {
    if (retr(svr,&req.maj,4)) return -1;
    maj = ntohl(req.maj);
    if (maj != 1) return -1;
    if (retr(svr,&req.size,4)) return -1;
    size = ntohl(req.size);
    if (bufsize < size) return -1;
    req.data = (uint8_t*)buf;
    if (retr(svr,req.data,size)) return -1;
    *major = maj;
    *minor = 0;
    *aux0 = size;
  } else {
    *major = 1;
    *minor = 0;
    token = getenv("CANNATOKEN");
    if (token == 0 || *token == 0)
      return -1;
    strcpy(buf,token);
    *aux0  = strlen(buf) + 1;
  }
  return 0;
}
Exemple #10
0
int
request_type1(int id,int major,int minor)
{
  canna_server* svr = &server[id];
  canna_request_type1 req;
  int size;

  if (retr(svr,&req.size,2)) return -1;
  size = ntohs(req.size);
  if (size != 0) return -1;
  return 0;
}
Exemple #11
0
int
request_type12(int id,int major,int minor,int* cxt,
	       char* buf,int bufsize)
{
  canna_server* svr = &server[id];
  canna_request_type12 req;
  int size;
  int i;
  int init,last,sub;
  uint16_t* p;

  if (retr(svr,&req.size,2)) return -1;
  size = ntohs(req.size);
  size -= 2;
  if (size < 0) return -1;
  req.data = malloc(size);
  if (req.data == 0) return -1;
  if (retr(svr,&req.cxt,2)) return -1;
  if (retr(svr,req.data,size)) return -1;
  *cxt = (int16_t)ntohs(req.cxt);
  init = 0; last = size;
  p = (uint16_t*)req.data;
  for (i = 0; i < (size / 2); i++) {
    init += 2; last -= 2;
    if (*p == 0) break;
    p++;
  }
  if (*p != 0) return -1;
  sub = narrow(0,0,(uint16_t*)req.data,init/2);
  if (sub == -1) return -1;
  if (bufsize < (sub + last)) return -1;
  sub = narrow(buf,bufsize,(uint16_t*)req.data,init/2);
  if (*(buf+sub-1) != 0) return -1;
  *(buf+sub-1) = '\t';
  memcpy(buf+sub,req.data+init,last);
  if (*(buf+sub+last-1) != 0) return -1;
  free(req.data);
  return 0;
}
Exemple #12
0
int
request_type15(int id,int major,int minor,int* cxt,
	       int* aux0,int* aux1,char* buf,int bufsize)
{
  canna_server* svr = &server[id];
  canna_request_type15 req;
  int size;

  if (retr(svr,&req.size,2)) return -1;
  size = ntohs(req.size);
  size -= 6;
  if (size <= 0 || bufsize < size) return -1;
  req.data = (uint8_t*)buf;
  if (retr(svr,&req.mode,4)) return -1;
  if (retr(svr,&req.cxt,2)) return -1;
  if (retr(svr,req.data,size)) return -1;
  if (*(buf+size-1) != 0) return -1;
  *cxt = (int16_t)ntohs(req.cxt);
  *aux0 = ntohl(req.mode);
  *aux1 = size;
  return 0;
}
Exemple #13
0
static void
session_imsgev(struct imsgev *iev, int code, struct imsg *imsg)
{
	struct m_backend	*mb = iev->data;

	switch (code) {
	case IMSGEV_IMSG:
		switch (imsg->hdr.type) {
		case IMSG_MAILDROP_INIT:
			maildrop_init(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_UPDATE:
			update(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_RETR:
			retr(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_DELE:
			dele(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_RSET:
			rset(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_LIST:
			list(iev, imsg, mb);
			break;
		case IMSG_MAILDROP_LISTALL:
			list_all(iev, imsg, mb);
			break;
		default:
			logit(LOG_DEBUG, "%s: unexpected imsg %u",
			    __func__, imsg->hdr.type);
			break;
		}
		break;
	case IMSGEV_EREAD:
	case IMSGEV_EWRITE:
	case IMSGEV_EIMSG:
		fatal("maildrop: imsgev read/write error");
		break;
	case IMSGEV_DONE:
		event_loopexit(NULL);
		break;
	}
}
void
dsi_send(globus_gfs_operation_t       Operation,
         globus_gfs_transfer_info_t * TransferInfo,
         void                       * UserArg)
{
	globus_result_t result = GLOBUS_SUCCESS;

	GlobusGFSName(dsi_send);

	if (dsi_partial_transfer(TransferInfo) || dsi_restart_transfer(TransferInfo))
	{
		result = GlobusGFSErrorGeneric("Non-zero offsets are not supported");
		globus_gridftp_server_finished_transfer(Operation, result);
		return;
	}

	retr(UserArg, Operation, TransferInfo);
}
Exemple #15
0
int main(int argc, char* argv[])
{
    string driver_name;
    string server_name;
    string user_name;
    string passwd;
    string query;
    string table_name= kEmptyStr;
    string blob_key;

    if(argc < 2) {
        cerr << argv[0]
             << " [-d<driver_name>] [-S<server_name>]"
             << " [-U<user_name>] [-P<password>] [-Q<query> | -T<table_name> -K<blob_id>] [-Z<compress_method>]"
             << endl;
        return 0;
    }

    const char* p= getParam('S', argc, argv);
    if(p == 0) {
        p= getenv("SQL_SERVER");
    }
    server_name= p? p : "MS_DEV1";

    p= getParam('d', argc, argv);
    if (p) {
        driver_name= p;
    } else {
        p= getenv("DBAPI_DRIVER");
        if(p == 0) {
            driver_name= (server_name.find("MS") != NPOS)? "ftds" : "ctlib";
        }
        else driver_name= p;
    }

    p= getParam('U', argc, argv);
    if(p == 0) {
        p= getenv("SQL_USER");
    }
    user_name= p? p : "anyone";

    p= getParam('P', argc, argv);
    if(p == 0) {
        p= getenv("SQL_PASSWD");
    }
    passwd= p? p : "allowed";

    ECompressMethod cm= eNone;
    p= getParam('Z', argc, argv);
    if(p) {
        if(*p == 'z') cm= eZLib;
        else cm= eBZLib;
    }

    bool f;
    p= getParam('Q', argc, argv, &f);
    if(p) {
        query= string("set TEXTSIZE 2147483647 ") + p;
    }
    else {
        if(f) { // query is on stdin
            query= "set TEXTSIZE 2147483647 ";
            cout << "query is on ctdin" << endl;
            char c;
            c= cin.get();
            while(!cin.eof()) {
                cout << c;
                query+= c;
                c= cin.get();
            }
            cout << endl;
        }
        if(query.empty()) {
            p= getParam('T', argc, argv);
            if(p == 0)
                p= getenv("DATA_TABLE");
            table_name= p? p : "";
            p= getParam('K', argc, argv);
            blob_key= p? p : "";
        }
    }

    try {
        C_DriverMgr drv_mgr;
        string err_msg;
        map<string, string> packet;
        packet.insert (map<string, string>::value_type (string("packet"),
                                                        string("2048")));
        I_DriverContext* my_context= drv_mgr.GetDriverContext(driver_name,
                                                              &err_msg, &packet);
        if(!my_context) {
            cerr << "blobreader: Cannot load a driver " << driver_name << " ["
                 << err_msg << "] " << endl;
            return 1;
        }
        if(!table_name.empty()) {
            CDB_Connection* con= my_context->Connect(server_name, user_name, passwd, 0, true);

            query= "select * from " + table_name + " where 0=1";
            CDB_LangCmd* lcmd = con->LangCmd(query);

            lcmd->Send();

            unsigned int n;
            int k= 0;
            string key_col_name;
            string num_col_name;

            query= "set TEXTSIZE 2147483647 select ";

            while (lcmd->HasMoreResults()) {
                CDB_Result* r = lcmd->Result();
                if (!r)
                    continue;

                if (r->ResultType() == eDB_RowResult) {
                    n= r->NofItems();
                    if(n < 2) {
                        delete r;
                        continue;
                    }


                    for(unsigned int j= 0; j < n; j++) {
                        switch (r->ItemDataType(j)) {
                        case eDB_VarChar:
                        case eDB_Char:
                        case eDB_LongChar:
                            key_col_name= r->ItemName(j);
                            break;

                        case eDB_Int:
                        case eDB_SmallInt:
                        case eDB_TinyInt:
                        case eDB_BigInt:
                            num_col_name= r->ItemName(j);
                            break;

                        case eDB_Text:
                        case eDB_Image:
                        case eDB_VarCharMax:
                        case eDB_VarBinaryMax:
                            if(k++) query+= ",";
                            query+= r->ItemName(j);
                        default:
                            break;
                        }
                    }
                    while(r->Fetch());
                }
                delete r;
            }
            delete lcmd;
            delete con;

            if(k < 1) {
                query+= "*";
            }
            query+= " from " + table_name;
            if((!blob_key.empty()) && (!key_col_name.empty())) {
                query+= " where " + key_col_name + "= '" + blob_key + "'";
                if(!num_col_name.empty()) {
                    query+= " order by " + num_col_name;
                }
            }
            else if(!key_col_name.empty()) {
                query+= " order by " + key_col_name;
                if(!num_col_name.empty()) {
                    query+= "," + num_col_name;
                }
            }
        }


        CBlobRetriever retr(my_context, server_name, user_name, passwd, query);
        while(retr.IsReady()) {
            retr.Dump(cout, cm);
        }
    } catch (CDB_Exception& e) {
        CDB_UserHandler_Stream myExHandler(&cerr);

        myExHandler.HandleIt(&e);
        return 1;
    }
    return 0;
}
Exemple #16
0
void PopCommand::execute()
{
    if ( d->done )
        return;

    switch ( d->cmd ) {
    case Quit:
        log( "Closing connection due to QUIT command", Log::Debug );
        d->pop->setState( POP::Update );
        d->pop->ok( "Goodbye" );
        break;

    case Capa:
        {
            EString c( "TOP\r\n"
                      "UIDL\r\n"
                      "SASL\r\n"
                      "USER\r\n"
                      "RESP-CODES\r\n"
                      "PIPELINING\r\n"
                      "IMPLEMENTATION Archiveopteryx POP3 Server, "
                      "http://archiveopteryx.org.\r\n" );
            if ( Configuration::toggle( Configuration::UseTls ) )
                c.append( "STLS\r\n" );
            c.append( ".\r\n" );
            d->pop->ok( "Capabilities:" );
            d->pop->enqueue( c );
        }
        break;

    case Stls:
        if ( !startTls() )
            return;
        break;

    case Auth:
        if ( !auth() )
            return;
        break;

    case User:
        if ( !user() )
            return;
        break;

    case Pass:
        if ( !pass() )
            return;
        break;

    case Apop:
        if ( !apop() )
            return;
        break;

    case Session:
        if ( !session() )
            return;
        break;

    case Stat:
        if ( !stat() )
            return;
        break;

    case List:
        if ( !list() )
            return;
        break;

    case Top:
        if ( !retr( true ) )
            return;
        break;

    case Retr:
        if ( !retr( false ) )
            return;
        break;

    case Dele:
        if ( !dele() )
            return;
        break;

    case Noop:
        d->pop->ok( "Done" );
        break;

    case Rset:
        d->pop->ok( "Done" );
        break;

    case Uidl:
        if ( !uidl() )
            return;
        break;
    }

    finish();
}
void exec_comm(int cl){

	int size,j=0,i=0, port;
	char buff[1024], *param,*command, *param1,*filename;
	char commands[100],buff2[200],dir[200];
	fd_set fds;

	memset(buff, '\0', 1024);

	if((recv(clients[cl]->sock, buff, sizeof(buff), 0))<0){
		perror("error in Receiving");
		exit(1);
		}
	printf("%s\n",buff);
	command = strtok (buff," ");		
	
	//buff[size-2]=0;  // -'\r' et  -'\n'
	/*while(buff[j]){
		param[i]=buff[j+1];
		i++;j++;
	}*/
	//param = strchr(buff," "); // param <- commande
	param = strtok (NULL, " ");
	
	for (j = 0; j < strlen(command); j++)
    		command[j]=toupper(command[j]);
  	printf("%s\n",command);
  	
  	printf("%s\n",param);
	for (j = 0; j < 8; j++)

		if (!strcmp(command,commandes[j])) break;

	

	switch(j){

		case QUIT:	if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM);
				clients[cl]->pid=0;
				close(clients[cl]->sock);
				clients[cl]->sock=0; 
  				clients[cl]->dataport=0;
				nb_users--;
				printf("%s\n", commandes[j]);
				break;	

		case  PORT:	port = atoi(param);
				clients[cl]->dataport = port;
				printf("%s %s\n", commandes[j], param);
				send(clients[cl]->sock, ok, strlen(ok)+1, 0);
				break;	
	
		case CWD:	strcpy(tmp,clients[cl]->curdir);
				strcat(tmp,"/");
				strcat(tmp,param);
				if(chdir(tmp)<0){
					perror("error");
					memset(msz,'\0',sizeof(msz));
					sprintf(msz,"%s","No Such Directory");
					send(clients[cl]->sock, msz, strlen(msz)+1, 0);
				}
				else{	
					memset(clients[cl]->curdir, '\0', (strlen(clients[cl]->curdir)+1));
					strcpy(clients[cl]->curdir,tmp);
					memset(msz,'\0',sizeof(msz));
					sprintf(msz,"%s","Directory Changed");
					send(clients[cl]->sock, msz, strlen(msz)+1, 0);
					printf("%s  %s\n", commandes[j],clients[cl]->curdir);
				}	
				prompt();
				break;	

		

		case RGET:	//param1 = strtok(param,"-");
				//filename = strtok(NULL,"-");
				//port = atoi(param1);
				//clients[cl]->dataport = port;
				//send(clients[cl]->sock, ok, strlen(ok)+1, 0);
				//	printf("%s %s\n", commandes[j], filename);
				
				strcat(commands,"ls -R ");
				system("ls");
				strcat(commands,param);
				printf("%s",param);
				system(commands);
				FILE *fd = popen(commands,"r");
				while(fgets(buff, sizeof(buff), fd)!=NULL){
					if(buff[(strlen(buff)-1)]==':'){
						//strcpy(dir,buff);
						//printf("%s",dir);
						memcpy(dir,buff,strlen(buff)-2);
						if(send(clients[cl]->sock,buff, strlen(buff), 0)<0)
								perror("Send");
					}
					else{
					strcat(dir,"param/");
					strcat(dir,buff);
					strcpy(buff,dir);
					if(send(clients[cl]->sock,buff, strlen(buff), 0)<0)
						perror("Send");
					}		
				}
				//rget(cl,param);
				break;
		 
		 case MGET:				
				strcat(commands,"ls ");
				//system("ls");
				strcat(commands,param);
				printf("%s",param);
				//system(commands);
				fd = popen(commands,"r");
				while(fgets(buff, sizeof(buff), fd)!=NULL){
					printf("\n%s",buff);
					if(send(clients[cl]->sock,buff, strlen(buff), 0)<0)
						perror("Send");
					}
				
				//rget(cl,param);
				break;
		
		
		// Since the list of files can be a considerable size, it is better to create a child
		// Which will deal with the client
		case LIST:	port = atoi(param);
				printf("%d",port);
				clients[cl]->dataport = port;
				if( (clients[cl]->pid = fork()) == 0 ){ 
					send(clients[cl]->sock, ok, strlen(ok)+1, 0);
					my_list(cl);
				}
				//send(clients[cl]->sock, ok, strlen(ok)+1, 0);
				printf("%s %s\n", commandes[j], clients[cl]->curdir);
				break;

		// Because a file can be of great size, it is better to create a child Which will deal with the sending to the client
		case RETR:	param1 = strtok(param,"-");
				filename = strtok(NULL,"-");
				port = atoi(param1);
				clients[cl]->dataport = port;
				if( (clients[cl]->pid = fork()) == 0 ) { 
					send(clients[cl]->sock, ok, strlen(ok)+1, 0);
					retr(cl, filename);
				}
				printf("%s %s\n", commandes[j], param);
				break;

		// Because a file can be of great size, it is better to create a child Which will deal with the recovery from the client

		case STOR:	param1 = strtok(param,"-");
				filename = strtok(NULL,"-");
				port = atoi(param1);
				clients[cl]->dataport = port;
				if( (clients[cl]->pid = fork()) == 0 ){
					if(send(clients[cl]->sock, ok, strlen(ok)+1, 0)<0)
						perror("send");
					stor(cl, filename);
				}
				printf("%s %s\n", commandes[j], param);	
				break;

		// Because a file can be of great size, it is better to create a child Which will deal with the removal

		
		
		//By default, we consider that if a client sends commands incomprehensible, it must be disconnected
		default:	if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM);
				if (clients[cl]->pid) kill(clients[cl]->pid,SIGTERM);
  				clients[cl]->pid=0;
				close(clients[cl]->sock);
				clients[cl]->sock = 0;
				clients[cl]->dataport = 0;
				nb_users--;
				printf("Client %d Disocnnected\n",cl);
				break;
				prompt();
	}	
}
Exemple #18
0
int
canna_request(int id,int* major,int* minor,int* cxt,
	      int* aux0,int* aux1,int* aux2,char* buf,int bufsize)
{
  canna_server* svr = &server[id];
  uint8_t maj,min;

  if (retr(svr,&maj,1)) return -1;
  if (retr(svr,&min,1)) return -1;
  *major = maj; *minor = min;

  if (maj == 0x02 && min == 0) {
    /* Finalization */
    return request_type1(id,maj,min);
  } else if (maj == 0x03 && min == 0) {
    /* CreateContext */
    return request_type1(id,maj,min);
  } else if (maj == 0x03 && min == 1) {
    /* CreateDictionary */
    return request_type15(id,maj,min,cxt,aux0,aux1,buf,bufsize);
  } else if (maj == 0x04 && min == 0) {
    /* DuplicateContext */
    return request_type2(id,maj,min,aux0);
  } else if (maj == 0x05 && min == 0) {
    /* CloseContext */
    return request_type2(id,maj,min,aux0);
  } else if (maj == 0x06 && min == 0) {
    /* GetDictionaryList */
    return request_type3(id,maj,min,cxt,aux0);
  } else if (maj == 0x07 && min == 0) {
    /* GetDirectoryList */
    return request_type3(id,maj,min,cxt,aux0);
  } else if (maj == 0x08 && min == 0) {
    /* MountDictionary */
    return request_type15(id,maj,min,cxt,aux0,aux1,buf,bufsize);
  } else if (maj == 0x08 && min == 1) {
    /* Sync */
    return request_type15(id,maj,min,cxt,aux0,aux1,buf,bufsize);
  } else if (maj == 0x09 && min == 0) {
    /* UnmountDictionary */
    return request_type15(id,maj,min,cxt,aux0,aux1,buf,bufsize);
  } else if (maj == 0x0b && min == 0) {
    /* GetMountDictionaryList */
    return request_type3(id,maj,min,cxt,aux0);
  } else if (maj == 0x0d && min == 0) {
    /* DefineWord */
    return request_type12(id,maj,min,cxt,buf,bufsize);
  } else if (maj == 0x0e && min == 0) {
    /* DeleteWord */
    return request_type12(id,maj,min,cxt,buf,bufsize);
  } else if (maj == 0x0f && min == 0) {
    /* BeginConvert */
    return request_type14(id,maj,min,cxt,aux0,buf,bufsize);
  } else if (maj == 0x10 && min == 0) {
    /* EndConvert */
    return request_type10(id,maj,min,cxt,aux0,aux1,buf,bufsize);
  } else if (maj == 0x11 && min == 0) {
    /* GetCandidacyList */
    return request_type6(id,maj,min,cxt,aux0,aux1);
  } else if (maj == 0x12 && min == 0) {
    /* GetYomi */
    return request_type6(id,maj,min,cxt,aux0,aux1);
  } else if (maj == 0x1a && min == 0) {
    /* ResizePause */
    return request_type7(id,maj,min,cxt,aux0,aux1);
  } else if (maj == 0x1b && min == 0) {
    /* GetHinsi */
    return request_type8(id,maj,min,cxt,aux0,aux1,aux2);
  } else if (maj == 0x1c && min == 0) {
    /* GetLex */
    return request_type9(id,maj,min,cxt,aux0,aux1,aux2);
  } else if (maj == 0x1d && min == 0) {
    /* GetStatus */
    return request_type7(id,maj,min,cxt,aux0,aux1);
  } else if (maj == 0x21 && min == 0) {
    /* SetApplicationName */
    return request_type15(id,maj,min,cxt,aux0,aux1,buf,bufsize);
  } else if (maj == 0x22 && min == 0) {
    /* NoticeGroupName */
    return request_type15(id,maj,min,cxt,aux0,aux1,buf,bufsize);
  } else {
    return -1;
  }
}
Exemple #19
0
int	smunge (userT *user)
{
	// Interactively deals with users pop commands,
	// servicing them from the users pop servers,
	// smunging the results as needed.

	int	argc;
	char	argv0[MAX_ARG_LEN];
	char	argv1[MAX_ARG_LEN];
	char	argv2[MAX_ARG_LEN];
	char	argv3[MAX_ARG_LEN];
	int	i;
	char	response[MAX_LINE];

	if (!user || (user->fd < 1))
	{
		return -1;
	}

	while (user->fd > 0)
	{
		watchdog (user);
		if (user->fd < 0)
		{
			return (-1);
		}
		
		argc=get_command (&user->fd, argv0, argv1, argv2, argv3);
 
		if (argc < 0)
		{
			// there was a problem.
			return (0);
		} else
		if (argc)
		{
			if (!strcmp (argv0, "QUIT"))
			{ 
				quit (user);
				ok (user->fd, "Have a nice day");	
				return (0);
			} else
			if (!strcmp (argv0, "DBUG") && (LOG_LEVEL==666))
			{
				debug (user);
			} else
			if (!strcmp (argv0, "STAT"))
			{
				long messages = 0;
				long size = 0;

				user->time = time(NULL);
				for (i=0; i < user->mailboxes; i++)
				{
					if (user->mailbox[i].fd > 0)
					{
						if (status (user, i, &messages, &size) == -1)
						{
							return (0);
						}
					}
				}
				snprintf (response, MAX_LINE-1, "%ld %ld", messages, size);

				ok (user->fd, response);
			} else
			if (!strcmp (argv0, "LIST"))
			{
				user->time = time(NULL);
				// if given with no arguments
				if (argc == 1)
				{
					if (list (user) == -1)
					{
						return (0);
					}
				} else
				{
					if (list_s (user, atol(argv1)) == -1)
					{
						return (0);
					}
				}
			} else
			if (!strcmp (argv0, "UIDL"))
			{
				user->time = time(NULL);
				// if given with no arguments
				if (argc == 1)
				{
					if (uidl (user) == -1)
					{
						return (0);
					}
				} else
				{
					if (uidl_s (user, atol(argv1)) == -1)
					{
						return (0);
					}
				}
			} else
			if ((argc == 2) && (!strcmp (argv0, "RETR")))
			{
				user->time = time(NULL);
				if (retr (user, atol(argv1), -1) == -1)
				{
					return (0);
				}
			} else
			if ((argc == 2) && (!strcmp (argv0, "DELE")))
			{
				user->time = time(NULL);
				if (dele (user, atol(argv1)) == -1)
				{
					return (0);
				}	
			} else
			if ((argc == 3) && (!strcmp (argv0, "TOP")))
			{
				user->time = time(NULL);

				if (atol(argv2) < 0)
				{
					err (user, "Need to supply a non-negative number of lines");
				} else
				if (retr (user, atol(argv1), atol(argv2)) == -1)
				{
					return (0);
				}
			} else
			if (!strcmp (argv0, "RSET"))
			{
				user->time = time(NULL);
				if (rset (user) == -1)
				{
					return (0);
				}
			} else
			if (!strcmp (argv0, "NOOP"))
			{
				user->time = time(NULL);
				ok (user->fd, "Keeping out of trouble");
			} else
			{
				user->time = time(NULL);
				snprintf (response, MAX_LINE-1, "Invalid commmand - %s", argv0);
				err (user, response); 
			}
		
		} else
		{
			user->time = time(NULL);
			err (user, "Talk to me");
		}
	}

	return (0);
}
Exemple #20
0
static int doline(struct PCP *pcp, char *p, int acl_flags)
{
	char *q=strtok(p, " ");

	if (!q)
	{
		printf("500 Syntax error\n");
		return (0);
	}

	if (strcasecmp(q, "QUIT") == 0)
	{
		printf("200 Bye.\n");
		return (-1);
	}

	if (strcasecmp(q, "NOOP") == 0)
	{
		printf("200 Ok.\n");
		return (0);
	}

	if (strcasecmp(q, "CAPABILITY") == 0)
	{
		printf("100-ACL\n");
		printf("100 PCP1\n");
		return (0);
	}

	if (strcasecmp(q, "LIST") == 0)
	{
		if (check_acl(acl_flags, PCP_ACL_LIST))
			return (0);

		if (list(pcp))
			printf("500 Syntax error\n");
		return (0);
	}

	if (strcasecmp(q, "RETR") == 0)
	{
		if (check_acl(acl_flags, PCP_ACL_RETR))
			return (0);

		if (retr(pcp))
			printf("500 Syntax error\n");
		return (0);
	}


	if (strcasecmp(q, "ACL") == 0 && pcp_has_acl(pcp) && !proxy_userid)
	{
		q=strtok(NULL, " ");
		if (q && strcasecmp(q, "SET") == 0)
		{
			const char *who=strtok(NULL, " ");

			if (who)
			{
				int flags=0;

				while ((q=strtok(NULL, " ")) != 0)
					flags |= pcp_acl_num(q);

				if (pcp_acl(pcp, who, flags))
				{
					error(0);
					return (0);
				}
				printf("200 Ok\n");
				return (0);
			}
		}
		else if (q && strcasecmp(q, "LIST") == 0)
		{
			listacls(pcp);
			return (0);
		}
	}

	if (strcasecmp(q, "RSET") == 0)
	{
		conflict_flag=0;
		force_flag=0;
		need_rset=0;
		rset(pcp);
		printf("200 Ok.\n");	
		return (0);
	}

	if (need_rset)
	{
		printf("500 RSET required - calendar in an unknown state.\n");
		return (0);
	}

	if (strcasecmp(q, "DELETE") == 0)
	{
		struct PCP_retr r;
		const char *event_id_list[2];

		char *e=strtok(NULL, " ");

		if (check_acl(acl_flags, PCP_ACL_MODIFY))
			return (0);

		if (e && deleted_eventid == NULL && new_eventid == NULL)
		{
			if ((deleted_eventid=strdup(e)) == NULL)
			{
				perror("strdup");
				exit(1);
			}
			proxy_list_rset();
			memset(&r, 0, sizeof(r));
			r.callback_retr_participants=open_event_participant;
			event_id_list[0]=deleted_eventid;
			event_id_list[1]=NULL;
			r.event_id_list=event_id_list;
			if (pcp_retr(pcp, &r))
			{
				error(r.errcode);
				proxy_list_rset();
			}
			else
				printf("200 Ok.\n");
			return (0);
		}
	}

	if (strcasecmp(q, "NEW") == 0 && new_eventid == NULL)
	{
		if (check_acl(acl_flags, PCP_ACL_MODIFY))
			return (0);

		new_eventid=readnewevent(pcp);

		if (new_eventid == NULL)
		{
			printf("500 %s\n", strerror(errno));
		}
		else
			printf("109 %s ready to be commited.\n",
			       new_eventid->eventid);
		return (0);
	}

	if (strcasecmp(q, "BOOK") == 0 && new_eventid)
	{
		dobook(pcp);
		return (0);
	}

	if (strcasecmp(q, "CONFLICT") == 0)
	{
		q=strtok(NULL, " ");
		if (q && strcasecmp(q, "ON") == 0)
		{
			if (check_acl(acl_flags, PCP_ACL_CONFLICT))
				return (0);

			conflict_flag=1;
		}
		else
			conflict_flag=0;
		printf("200 Ok.\n");
		return (0);
	}

	if (strcasecmp(q, "FORCE") == 0)
	{
		q=strtok(NULL, " ");
		if (q && strcasecmp(q, "ON") == 0)
		{
			force_flag=1;
		}
		else
			force_flag=0;
		printf("200 Ok.\n");
		return (0);
	}

	if (strcasecmp(q, "COMMIT") == 0)
	{
		if (notbooked)
		{
			printf("500 BOOK required.\n");
		}
		else if (new_eventid && new_commit_times)
		{
			struct proxy_list *pl;

			new_commit.add_conflict_callback=NULL;
			new_commit.add_conflict_callback_ptr=NULL;

			new_commit.flags=
				(conflict_flag ? PCP_OK_CONFLICT:0) |
				(force_flag ? PCP_OK_PROXY_ERRORS:0);

			for (pl=proxy_list; pl; pl=pl->next)
			{
				if (pl->flags & PROXY_IGNORE)
					continue;

				if (pl->flags & PROXY_NEW)
				{
					if (pcp_commit(pl->proxy,
						       pl->newevent,
						       &new_commit))
					{
						syslog(LOG_CRIT,
						       "COMMIT failed for PROXY %s",
						       pl->userid);

						if (!force_flag)
						{
							pl->flags &=
								~PROXY_NEW;
							error(new_commit
							      .errcode);
							return (0);
						}
					}
				}
				else if (pl->old_event_id)
				{
					struct PCP_delete del;

					memset(&del, 0, sizeof(del));

					del.id=pl->old_event_id;

					if (pcp_delete(pl->proxy, &del))
					{
						syslog(LOG_CRIT,
						       "DELETE failed for PROXY %s",
						       pl->userid);
						if (!force_flag)
						{
							error(del.errcode);
							return (0);
						}
						pl->flags |= PROXY_IGNORE;
					}
				}
			}

			if (proxy_userid)
				new_commit.flags |= PCP_BYPROXY;

			if (pcp_commit(pcp, new_eventid, &new_commit))
				error(new_commit.errcode);
			else
			{
				const char *proxy_name=NULL;
				const char *proxy_action=NULL;

				for (pl=proxy_list; pl; pl=pl->next)
				{
					if (proxy_name)
						printf("111-%s %s\n",
						       proxy_action,
						       proxy_name);

					proxy_action=
						!(pl->flags & PROXY_IGNORE)
						&& (pl->flags & PROXY_NEW)
						? "NEW":"DELETE";
					proxy_name=pl->userid;
				}

				if (proxy_name)
					printf("111 %s %s\n",
					       proxy_action,
					       proxy_name);
				else
					printf("200 Ok.\n");
			}	
			rset(pcp);
			return (0);
		}
		else if (!new_eventid && deleted_eventid)
		{
			struct proxy_list *pl;
			struct PCP_delete del;
			const char *proxy_userid;

			for (pl=proxy_list; pl; pl=pl->next)
			{
				if (pl->flags & PROXY_IGNORE)
					continue;

				if (pl->old_event_id)
				{
					memset(&del, 0, sizeof(del));
					del.id=pl->old_event_id;

					if (pcp_delete(pl->proxy, &del))
					{
						syslog(LOG_CRIT,
						       "DELETE failed for PROXY %s",
						       pl->userid);
					}
				}
			}

			memset(&del, 0, sizeof(del));
			del.id=deleted_eventid;

			if (pcp_delete(pcp, &del))
			{
				if (del.errcode != PCP_ERR_EVENTNOTFOUND)
				{
					error(del.errcode);
					return (0);
				}
			}

			proxy_userid=NULL;
			for (pl=proxy_list; pl; pl=pl->next)
			{
				if (proxy_userid)
					printf("111-DELETE %s\n",
					       proxy_userid);

				proxy_userid=pl->userid;
			}

			if (proxy_userid)
				printf("111 DELETE %s\n", proxy_userid);
			else
				printf("200 Ok\n");

			rset(pcp);
			return (0);
		}

		printf("500 There's nothing to commit.\n");
		return (0);
	}

	if (strcasecmp(q, "CANCEL") == 0)
	{
		int errcode;

		if (check_acl(acl_flags, PCP_ACL_MODIFY))
			return (0);

		q=strtok(NULL, " ");
		if (!q)
			printf("500 Syntax error\n");
		else if (pcp_cancel(pcp, q, &errcode))
			error(errcode);
		else
			printf("200 Cancelled\n");
		return (0);
	}

	if (strcasecmp(q, "UNCANCEL") == 0)
	{
		struct PCP_uncancel unc;
		struct uncancel_list *list=NULL, **tail= &list;
		struct uncancel_list *p;

		if (check_acl(acl_flags, PCP_ACL_MODIFY))
			return (0);

		memset(&unc, 0, sizeof(unc));
		unc.uncancel_conflict_callback=uncancel_callback;
		unc.uncancel_conflict_callback_ptr=&tail;

		q=strtok(NULL, " ");
		if (!q)
			printf("500 Syntax error\n");
		else if (pcp_uncancel(pcp, q,
				      (conflict_flag ? PCP_OK_CONFLICT:0)|
				      (force_flag ? PCP_OK_PROXY_ERRORS:0),
				      &unc))
		{
			if (unc.errcode == PCP_ERR_CONFLICT && list)
			{
				for (p=list; p; p=p->next)
				{
					char from_buf[15];
					char to_buf[15];

					pcp_gmtimestr(p->from, from_buf);
					pcp_gmtimestr(p->to, to_buf);

					printf("403%c%s %s %s %s conflicts.\n",
					       p->next ? '-':' ',
					       p->addr,
					       from_buf,
					       to_buf,
					       p->id);
				}
			}
			else
				error(unc.errcode);
		}
		else
			printf("200 Uncancelled\n");

		while((p=list) != NULL)
		{
			list=p->next;
			free(p->addr);
			free(p->id);
			free(p);
		}
		return (0);
	}

	printf("500 Syntax error\n");
	return (0);
}