Exemple #1
0
struct xlist_node *xusb_find_byproduct(const struct xusb_spec *specs,
		int numspecs, xusb_filter_t filterfunc, void *data)
{
	struct xlist_node	*xlist;
	struct usb_bus		*bus;
	struct usb_device	*dev;

	DBG("specs(%d)\n", numspecs);
	xlist = xlist_new(NULL);
	if (!xlist) {
		ERR("Failed allocation new xlist");
		goto fail_xlist;
	}
	xusb_init();
	for (bus = usb_get_busses(); bus; bus = bus->next) {
		for (dev = bus->devices; dev; dev = dev->next) {
			struct usb_device_descriptor	*dev_desc;
			struct xlist_node		*item;
			int				i;

			dev_desc = &dev->descriptor;
			assert(dev_desc);
			DBG("usb:%s/%s: ID=%04X:%04X\n",
				dev->bus->dirname,
				dev->filename,
				dev_desc->idVendor,
				dev_desc->idProduct);
			for (i = 0; i < numspecs; i++) {
				struct xusb		*xusb;
				const struct xusb_spec	*sp = &specs[i];

				if (!match_interface(dev, sp))
					continue;
				xusb = xusb_new(dev, sp);
				if (!xusb) {
					ERR("xusb allocation failed\n");
					goto fail_malloc;
				}
				if (filterfunc && !filterfunc(xusb, data)) {
					xusb_destroy(xusb);
					continue;
				}
				item = xlist_new(xusb);
				xlist_append_item(xlist, item);
				break;
			}
		}
	}
	xusb_list_dump(xlist);
	return xlist;
fail_malloc:
	xlist_destroy(xlist, NULL);
fail_xlist:
	return NULL;
}
Exemple #2
0
ogmp_ui_t* client_new_ui(module_catalog_t* mod_cata, char* type)
{
    ogmp_ui_t* ui = NULL;
    
    xlist_user_t lu;
    xlist_t* uis  = xlist_new();
    int found = 0;
    
    int nmod = catalog_create_modules (mod_cata, "ui", uis);
    if(nmod)
    {
        ui = (ogmp_ui_t*)xlist_first(uis, &lu);
        while(ui)
        {
            if(ui->match_type(ui, type))
            {
                xlist_remove_item(uis, ui);
                found = 1;
                break;
            }

            ui = xlist_next(uis, &lu);
        }
    }

    xlist_done(uis, ogmp_done_ui);

    if(!found)
        return NULL;

    global_ui = ui;
    
    return ui;
}
sipua_phonebook_t* sipua_load_book(char* bookloc)
{
	FILE* f;
	sipua_phonebook_t* book;

	f = fopen(bookloc, "r");
	if(!f)
	{
		pbk_log(("sipua_new_book: can not open '%s'\n", bookloc));
		return NULL;
	}

	book = xmalloc(sizeof(sipua_phonebook_t));
	if(!book)
	{
		pbk_log(("sipua_new_book: no memory\n"));
		return NULL;
	}
	memset(book, 0, sizeof(sipua_phonebook_t));

	book->contacts = xlist_new();

	sipua_load_file(book, f);
		
	fclose(f);

	return book;
}
sipua_uas_t* client_new_uas(module_catalog_t* mod_cata, char* type)
{
    sipua_uas_t* uas = NULL;

    xlist_user_t lu;
    xlist_t* uases  = xlist_new();
    int found = 0;

    int nmod = catalog_create_modules (mod_cata, "uas", uases);
    if(nmod)
    {
        uas = (sipua_uas_t*)xlist_first(uases, &lu);
        while(uas)
        {
            if(uas->match_type(uas, type))
            {
                xlist_remove_item(uases, uas);
                found = 1;
                break;
            }

            uas = xlist_next(uases, &lu);
        }
    }

    xlist_done(uases, client_done_uas);

    if(!found)
        return NULL;

    return uas;
}
Exemple #5
0
module_interface_t* sipua_new_server()
{
	eXosipua_t *jua;
	sipua_uas_t *uas;

	jua = xmalloc(sizeof(eXosipua_t));
	if(!jua)
	{
		jua_log(("sipua_new: No memory\n"));
		return NULL;
	}
	memset(jua, 0, sizeof(eXosipua_t));

	uas = (sipua_uas_t*)jua;
   uas->auth_list = xlist_new();
   if(!uas->auth_list)
   {
      xfree(jua);
      jua_debug(("sipua_new_server: No memory for Authorization list\n"));
      
      return NULL;
   }

   uas->match_type = uas_match_type;

   uas->init = uas_init;
	uas->done = uas_done;
    
	uas->start = uas_start;

   uas->shutdown = uas_shutdown;

	uas->address = uas_address;

	uas->add_coding = uas_add_coding;
	uas->clear_coding = uas_clear_coding;

	uas->set_listener = uas_set_lisener;

	uas->set_authentication_info = uas_set_authentication_info;
	uas->clear_authentication_info = uas_clear_authentication_info;
	uas->has_authentication_info = uas_has_authentication_info;
   
	uas->regist = uas_regist;
	uas->unregist = uas_unregist;

	uas->accept = uas_accept;
	uas->release = uas_release;

	uas->invite = uas_invite;
	uas->answer = uas_answer;
	uas->bye = uas_bye;

   uas->retry = uas_retry_call;

	return uas;
}
sipua_phonebook_t* sipua_new_book()
{
	sipua_phonebook_t* book = xmalloc(sizeof(sipua_phonebook_t));
	if(!book)
	{
		pbk_log(("sipua_new_book: no memory\n"));
		return NULL;
	}
	memset(book, 0, sizeof(sipua_phonebook_t));

	book->contacts = xlist_new();

	return book;
}
user_t* sipua_load_user_file(FILE* f, char* uid, char* tok, int tsz)
{
	char buf[256];

	int bsize = 256;
	int bi;
	
	char line[128];
	char *start, *end;

	char *pc;
	int len;

	int nitem = 0;

	user_t* user = NULL;

	bi = sipua_verify_user_file(f, uid, tok, tsz, buf, &bsize);

	if(bi == -1)
		return NULL;
	
	user = xmalloc(sizeof(user_t));
	if(!user)
	{
		return NULL;
	}
	memset(user, 0, sizeof(user_t));

	user->profiles = xlist_new();
	if(!user->profiles)
	{
		xfree(user);
		return NULL;
	}

	user->uid = xstr_clone(uid);

	while(1)
	{
		user_profile_t* u;

		len = sipua_get_line(line, 128, buf, &bsize, &bi, f);
		if(len < 0)
			break;

		pc = line;
	
		if(len > 9 && 0==strncmp(pc, "fullname[", 9))
		{
			int n;

			u = xmalloc(sizeof(user_profile_t));
			if(!u)
				return 0;
			memset(u, 0, sizeof(user_profile_t));

			u->user = user;
			
			while(*pc != '[')
				pc++;

			start = pc+1;
			u->fbyte = strtol(start, &end, 10);
			u->fullname = xmalloc(u->fbyte+1);

			while(*end != '=')
				end++;

			start = end+1;

			n = len-(start-line);
			if(n >= u->fbyte)
			{
				u->fullname = xstr_nclone(start, u->fbyte);
			}
			else
			{
				strncpy(u->fullname, start, n);

				len = sipua_load_nchar(u->fullname+n, u->fbyte-n, buf, &bsize, &bi, f);
			}

			u->fullname[u->fbyte] = '\0';
		
			u->username = user->uid;

			nitem++;
		}
		else if(len > 9 && 0==strncmp(pc, "reg.home=", 9))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->registrar = xstr_clone(start);

			nitem++;
		}
		else if(len > 9 && 0==strncmp(pc, "reg.name=", 9))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->regname = xstr_clone(start);

			nitem++;
		}

		if(len > 11 && 0==strncmp(pc, "reg.seconds=", 11))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->seconds = strtol(start, &end, 10);

			nitem++;
		}
		else if(len >= 19 && 0==strncmp(pc, "phonebook.location=", 19))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->book_location = xstr_clone(start);

			nitem++;
		}

		if(nitem < 5)
			continue;

		xlist_addto_first(user->profiles, u);
		nitem = 0;
	}

	return user;
}
user_t* sipua_load_user_file_v2(FILE* f, const char* uid, char* buf, int *bsize, int *bi)
{
	char line[128];
	char *start, *end;

	char *pc;
	int len;
   
   int nprof = 0;
   int nitem = 0;
   int nbook = 0;

	user_t* user = NULL;

	user = xmalloc(sizeof(user_t));
	if(!user)
	{
		return NULL;
	}
	memset(user, 0, sizeof(user_t));

	user->profiles = xlist_new();
	if(!user->profiles)
	{
		xfree(user);
		return NULL;
	}

	user->uid = xstr_clone(uid);

   /* load profile */
   if(sipua_get_section("[profiles]", line, 128, buf, bsize, bi, f))
   {
	   len = sipua_get_line(line, 128, buf, bsize, bi, f);
      if(len > 7 && 0==strncmp(line, "number=", 7))
      {
         pc = line;
         while(*pc != '=')
				pc++;

			start = pc+1;

         nprof = strtol(start, &end, 10);
      }
   }

   pbk_log(("sipua_load_user_file_v2: %d profiles\n", nprof));
   
   while(nprof)
	{
		user_profile_t* u;

		len = sipua_get_line(line, 128, buf, bsize, bi, f);
		if(len < 0)
			break;

		pc = line;

		if(len > 9 && 0==strncmp(pc, "fullname[", 9))
		{
			int n;

			u = xmalloc(sizeof(user_profile_t));
			if(!u)
				return 0;
			memset(u, 0, sizeof(user_profile_t));

			u->user = user;

			while(*pc != '[')
				pc++;

			start = pc+1;
			u->fbyte = strtol(start, &end, 10);
			u->fullname = xmalloc(u->fbyte+1);

			while(*end != '=')
				end++;

			start = end+1;

			n = len-(start-line);
			if(n >= u->fbyte)
			{
				u->fullname = xstr_nclone(start, u->fbyte);
			}
			else
			{
				strncpy(u->fullname, start, n);

				len = sipua_load_nchar(u->fullname+n, u->fbyte-n, buf, bsize, bi, f);
			}

			u->fullname[u->fbyte] = '\0';

			u->username = user->uid;

			nitem++;
		}
		else if(len > 9 && 0==strncmp(pc, "reg.home=", 9))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->registrar = xstr_clone(start);

			nitem++;
		}
		else if(len > 9 && 0==strncmp(pc, "reg.name=", 9))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->regname = xstr_clone(start);

         u->regid = u->regname;
         while(*u->regid != ':')
            u->regid++;
         u->regid++;

         u->realm = u->regname;
         while(*u->realm != '@')
            u->realm++;
         u->realm++;

			nitem++;
		}

		if(len > 11 && 0==strncmp(pc, "reg.seconds=", 11))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->seconds = strtol(start, &end, 10);

			nitem++;
		}
		else if(len >= 19 && 0==strncmp(pc, "phonebook.location=", 19))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->book_location = xstr_clone(start);

			nitem++;
		}

		if(nitem < 5)
			continue;

      u->thread_register_lock = xthr_new_lock();

		xlist_addto_last(user->profiles, u);
		nitem = 0;
      nprof--;
	}

   /* load phonebook */
   if(sipua_get_section("[phonebooks]", line, 128, buf, bsize, bi, f))
   {
	   len = sipua_get_line(line, 128, buf, bsize, bi, f);
      if(len > 7 && 0==strncmp(line, "number=", 7))
      {
         pc = line;
         while(*pc != '=')
				pc++;

			start = pc+1;

         nbook = strtol(start, &end, 10);
      }
   }

   pbk_log(("sipua_load_user_file_v2: %d books\n", nbook));

   while(nbook)
   {
      int ref;
		user_profile_t* prof;

      /* load phonebook */
      if(sipua_get_section("[contacts]", line, 128, buf, bsize, bi, f))
      {
         int ncontact = 0;
         
         len = sipua_get_line(line, 128, buf, bsize, bi, f);
         if(len < 12 || 0!=strncmp(line, "profile.ref=", 7))

         {
            nbook--;
            continue;
         }

         pc = line;
         while(*pc != '=')
		      pc++;

		   start = pc+1;

         ref = strtol(start, &end, 10);
            
         prof = (user_profile_t*)xlist_at(user->profiles, ref);
         if(!prof)
         {
            nbook--;
            continue;
         }

         pbk_log(("sipua_load_user_file_v2: phonebook[%s]\n", prof->regname));

         prof->phonebook = sipua_new_book(user);
         if(!prof->phonebook)
            return user;
         
         len = sipua_get_line(line, 128, buf, bsize, bi, f);
         if(len > 7 && 0==strncmp(line, "number=", 7))
         {
            pc = line;
            while(*pc != '=')
				   pc++;

			   start = pc+1;


            ncontact = strtol(start, &end, 10);
         }
         
         while(ncontact)
         {
		      sipua_contact_t* contact;

		      len = sipua_get_line(line, 128, buf, bsize, bi, f);
		      if(len < 0)
			      break;

		      pc = line;

		      if(len > 4 && 0==strncmp(pc, "name[", 4))
		      {
			      int n;

			      contact = xmalloc(sizeof(sipua_contact_t));
			      if(!contact)
				      return user;
                  
			      memset(contact, 0, sizeof(sipua_contact_t));

			      while(*pc != '[')
				      pc++;

			      start = pc+1;
			      contact->nbytes = strtol(start, &end, 10);
			      contact->name = xmalloc(contact->nbytes+1);

			      while(*end != '=')
				      end++;

			      start = end+1;

			      n = len-(start-line);
			      if(n >= contact->nbytes)
			      {
				      contact->name = xstr_nclone(start, contact->nbytes);
			      }
			      else
			      {
				      strncpy(contact->name, start, n);
				      len = sipua_load_nchar(contact->name+n, contact->nbytes-n, buf, bsize, bi, f);
			      }

			      contact->name[contact->nbytes] = '\0';
               pbk_log(("sipua_load_user_file_v2: contact.name[%s]\n", contact->name));


			      nitem++;
		      }
            else if(len > 4 && 0==strncmp(pc, "memo[", 4))
		      {
			      int n;

			      while(*pc != '[')
				      pc++;

			      start = pc+1;
			      contact->mbytes = strtol(start, &end, 10);
			      contact->memo = xmalloc(contact->mbytes+1);

			      while(*end != '=')
				      end++;

			      start = end+1;

			      n = len-(start-line);
			      if(n >= contact->mbytes)
			      {
				      contact->memo = xstr_nclone(start, contact->mbytes);
			      }
			      else
			      {
				      strncpy(contact->memo, start, n);

				      len = sipua_load_nchar(contact->memo+n, contact->mbytes-n, buf, bsize, bi, f);
			      }

			      contact->memo[contact->mbytes] = '\0';
               pbk_log(("sipua_load_user_file_v2: contact.memo[%s]\n", contact->memo));

			      nitem++;
		      }
		      else if(len > 9 && 0==strncmp(pc, "reg.name=", 9))
		      {
			      while(*pc != '=')
				      pc++;

			      start = pc+1;

			      contact->sip = xstr_clone(start);
               pbk_log(("sipua_load_user_file_v2: contact.sip[%s]\n", contact->sip));

			      nitem++;
		      }

		      if(nitem < 3)
			      continue;

		      xlist_addto_last(prof->phonebook->contacts, contact);
		      nitem = 0;
            ncontact--;
         }
      }

      nbook--;
   }

	return user;
}
user_t* sipua_load_user_file_v1(FILE* f, const char* uid, char* buf, int *bsize, int *bi)
{
	char line[128];
	char *start, *end;

	char *pc;
	int len;

	int nitem = 0;

	user_t* user = NULL;


	user = xmalloc(sizeof(user_t));
	if(!user)
	{
		return NULL;
	}
	memset(user, 0, sizeof(user_t));

	user->profiles = xlist_new();
	if(!user->profiles)
	{
		xfree(user);
		return NULL;
	}

	user->uid = xstr_clone(uid);

	while(1)
	{
		user_profile_t* u;

		len = sipua_get_line(line, 128, buf, bsize, bi, f);
		if(len < 0)
			break;

		pc = line;

		if(len > 9 && 0==strncmp(pc, "fullname[", 9))
		{
			int n;

			u = xmalloc(sizeof(user_profile_t));
			if(!u)
				return 0;
			memset(u, 0, sizeof(user_profile_t));

			u->user = user;

			while(*pc != '[')
				pc++;

			start = pc+1;
			u->fbyte = strtol(start, &end, 10);
			u->fullname = xmalloc(u->fbyte+1);

			while(*end != '=')
				end++;


			start = end+1;

			n = len-(start-line);
			if(n >= u->fbyte)
			{
				u->fullname = xstr_nclone(start, u->fbyte);
			}
			else
			{
				strncpy(u->fullname, start, n);

				len = sipua_load_nchar(u->fullname+n, u->fbyte-n, buf, bsize, bi, f);
			}

			u->fullname[u->fbyte] = '\0';

			u->username = user->uid;

			nitem++;
		}
		else if(len > 9 && 0==strncmp(pc, "reg.home=", 9))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->registrar = xstr_clone(start);

			nitem++;
		}
		else if(len > 9 && 0==strncmp(pc, "reg.name=", 9))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->regname = xstr_clone(start);

         u->regid = u->regname;
         while(*u->regid != ':')
            u->regid++;
         u->regid++;

         u->realm = u->regname;
         while(*u->realm != '@')
            u->realm++;
         u->realm++;

			nitem++;
		}

		if(len > 11 && 0==strncmp(pc, "reg.seconds=", 11))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->seconds = strtol(start, &end, 10);

			nitem++;
		}
		else if(len >= 19 && 0==strncmp(pc, "phonebook.location=", 19))
		{
			while(*pc != '=')
				pc++;

			start = pc+1;

			u->book_location = xstr_clone(start);

			nitem++;
		}

		if(nitem < 5)
			continue;

      u->thread_register_lock = xthr_new_lock();
      
		xlist_addto_last(user->profiles, u);
		nitem = 0;
	}

	return user;
}
sipua_t* client_new(char *uitype, sipua_uas_t* uas, module_catalog_t* mod_cata, int bandwidth)
{
	int nmod;
	int nformat;

	ogmp_client_t *client=NULL;

	sipua_t* sipua;

	client = xmalloc(sizeof(ogmp_client_t));
	memset(client, 0, sizeof(ogmp_client_t));

	client->ui = client_new_ui(mod_cata, uitype);
    if(client->ui == NULL)
    {
        clie_log (("client_new: No cursesui module found!\n"));
        xfree(client);

        return NULL;
    }
    
	sipua = (sipua_t*)client;

    client->ui->set_sipua(client->ui, sipua);

	client->control = new_media_control();

	client->course_lock = xthr_new_lock();
	client->wait_course_finish = xthr_new_cond(XTHREAD_NONEFLAGS);

	/* Initialise */
	client->conf = conf_new ( "ogmprc" );
   
	client->format_handlers = xlist_new();

	nmod = catalog_create_modules (mod_cata, "format", client->format_handlers);
	clie_log (("client_new: %d format module found\n", nmod));

	/* set sip client */
	client->valid = 0;

	/* player controler */
	client->control->config(client->control, client->conf, mod_cata);
	client->control->add_device(client->control, "rtp", client_config_rtp, client->conf);
	
	client->format_handlers = xlist_new();

	nformat = catalog_create_modules (mod_cata, "format", client->format_handlers);
	clie_log (("client_new_sipua: %d format module found\n", nformat));

	client->lines_lock = xthr_new_lock();

	/* set media ports, need to seperate to configure module */
	client->mediatypes[0] = xstr_clone("audio");
	client->default_rtp_ports[0] = 3500;
	client->default_rtcp_ports[0] = 3501;
	client->nmedia = 1;

	client->control->set_bandwidth_budget(client->control, bandwidth);

	uas->set_listener(uas, client, client_sipua_event);

	sipua->uas = uas;

	sipua->done = sipua_done;

	sipua->userloc = sipua_userloc;
	sipua->locate_user = sipua_locate_user;

	sipua->set_profile = client_set_profile;
	sipua->profile = client_profile;

	sipua->regist = client_regist;
	sipua->unregist = client_unregist;

	sipua->new_call = client_new_call;
	sipua->done_call = client_done_call;

 	/* lines management */
 	sipua->lock_lines = client_lock_lines;
 	sipua->unlock_lines = client_unlock_lines;

	sipua->lines = client_lines;
 	sipua->busylines = client_busylines;
 	/* current call session */
	sipua->session = client_session;
 	sipua->line = client_line;

	sipua->set_background_source = client_set_background_source;

	sipua->open_source = client_open_source;
	sipua->close_source = client_close_source;
	sipua->attach_source = client_attach_source;
	sipua->detach_source = client_detach_source;

	/* switch current call session */
 	sipua->pick = client_pick;
 	sipua->hold = client_hold;
	/*
	sipua->add = sipua_add;
	sipua->remove = sipua_remove;
	*/
	sipua->call = sipua_call;
	sipua->answer = client_answer;

	sipua->options_call = sipua_options_call;
	sipua->info_call = sipua_info_call;

	sipua->bye = sipua_bye;
	sipua->recall = sipua_recall;
   
	clie_log(("client_new: client ready\n\n"));

	return sipua;
}