예제 #1
0
static void register_record(struct obex_server *server)
{
	const GSList *l;

	if (connection == NULL)
		return;

	for (l = server->drivers; l; l = l->next) {
		struct obex_service_driver *driver = l->data;
		struct bluetooth_service *service;
		char *xml;

		service = find_service(driver);
		if (service == NULL) {
			service = g_new0(struct bluetooth_service, 1);
			service->driver = driver;
			service->server = server;
			any->services = g_slist_append(any->services, service);
		}

		/* Service already has a record registered */
		if (service->handle != 0)
			continue;

		/* Adapter ANY is not available yet: Add record later */
		if (any->path == NULL)
			continue;

		xml = g_markup_printf_escaped(driver->record, driver->channel,
						driver->name);
		add_record(any->path, xml, service);
		g_free(xml);
	}
예제 #2
0
int main()
{
	int choice;
	initscr();
	do {
		choice = getchoice("Options:",
							current_cd[0] ? extended_menu : main_menu);
		switch(choice) {
		case 'q':
			break;
		case 'a':
			add_record();
			break;
		case 'c':
			count_cds();
			break;
		case 'f':
			find_cd();
			break;
		case 'l':
			list_tracks();
			break;
		case 'r':
			remove_cd();
			break;
		case 'u':
			update_cd();
			break;
		}
	} while(choice != 'q');
	endwin();
	exit(EXIT_SUCCESS);
}
예제 #3
0
파일: app.c 프로젝트: hemiao3000/code
int main()
{
	int choice;
	initscr();

	do {
		choice = getchoice("Options:", current_cd[0] ? extended_menu : main_menu);
		switch (choice) {
			case 'q':
				break;
			case 'a':
				add_record();
				break;
			case 'c':
				count_cds();
				break;
			case 'f':
				find_cd();
				break;
			case 'l':
				break;
			case 'u':
				break;
		}		

	} while (choice != 'q');

	endwin();
	exit(0);
}
예제 #4
0
int records::loadFile(string path)
{
  char * name;
  char * points;
  char str [128];
  int cont = -1;
  records_vector.clear();
 
  if (path.length()==0) path = string(DEFAULT_RECORDS_FILE);
  this->path=path;
  FILE * fd = fopen (path.c_str(),"r");
  if (fd != NULL)
  {
    cont = 0; 
    while (fgets(str,sizeof(str)-1,fd)!=NULL)
    {
      name=strtok(str,SEPARATOR);
      points=strtok(NULL,SEPARATOR);
      add_record(string(name),atoi(points));
      cont ++;
    }
    fclose (fd);
  }
  return cont;
}
예제 #5
0
u16 iotrace_readw(const void *ptr)
{
	u32 v;

	v = readw(ptr);
	add_record(IOT_16 | IOT_READ, ptr, v);

	return v;
}
예제 #6
0
u32 iotrace_readl(const void *ptr)
{
	u32 v;

	v = readl(ptr);
	add_record(IOT_32 | IOT_READ, ptr, v);

	return v;
}
예제 #7
0
u8 iotrace_readb(const void *ptr)
{
	u32 v;

	v = readb(ptr);
	add_record(IOT_8 | IOT_READ, ptr, v);

	return v;
}
예제 #8
0
// [SLOT] - slot when add button is pressed
void creatordialog::on_pushButton_add_clicked()
{
    if(count==true)
    {
        QMessageBox::information(this,"Informacja","Nie można dodać dwóch pustych wierszy.");
        return;
    }
    add_record(creator_model);
    count=true;
}
예제 #9
0
/*
	kpreport_workerから定期的に呼び出される関数
*/
static void read_periodic(void)
{
	int i;
	char buf[STR_ENTRY_MAX];

	for(i = 0; i < kp_entry_ctl.nr_entries; i++){
		fgets(buf, STR_ENTRY_MAX, kp_entry_ctl.entries[i].fp);
		add_record(buf, i);
		fseek(kp_entry_ctl.entries[i].fp, 0, SEEK_SET);	/* 次回のために頭出ししておく */
	}
}
예제 #10
0
/*
 * database access
 */
void *data_access(void *record) {
    struct Phone_Entries *phone_entries = (struct Phone_Entries *)record; // Link our structures
    struct phone_record *person = phone_entries->record; // Link our record to our entries
    
    pthread_mutex_t *lock = phone_entries->mtx; // Link the mutex with a lock
    add_record(person); // Add the person
    pthread_mutex_unlock(lock); // Unlock the locked mutex
    pthread_mutex_lock(lock); // Lock the mutex
    remove_record(person->name); // Remove the record
    pthread_mutex_unlock(lock); // And lastly unlock again
    pthread_exit(NULL); // Exit when NULL
}
예제 #11
0
/* CREAMOS UN INICIO DE REGISTRO, O LO ADHERIMOS AL TEXTO DEL ARCHIVO ANTERIOR */
void Record::start(bool is_recording) {
    // Current date/time based on current system
    time_t now = time(0);

    // Convert now to tm struct for local timezone
    tm* localtm = localtime(&now);

    std::stringstream ss;

    ss << separador;
    ss << "Inicio de Nuevo Registro | Fecha/Hora: " << asctime(localtm) << std::endl;

    add_record(ss, is_recording);
}
예제 #12
0
void  directory :: menu()
{
    system("clear");
    int ch;
    cout << "DATA MANAGEMENT SOFTWARE\n";
    cout << "*******MENU*********\n\n";
    cout << "1: Addition\n";
    cout << "2: Deletion\n";
    cout << "3: Modification\n";
    cout << "4: View\n";
    cout << "5: Search\n";
    cout << "6: No Of Records\n";
    cout << "7: Exit\n\n";
    cout << "Choice- ";
    cin >> ch;
    switch(ch)
    {
    case 1:
        add_record();
        break;
    // case 2 :
    //     obj.delette();
    //     break;
    // case 3:
    //     obj.modification();
    //     break;
    // case 4:
    //     obj.view();
    //     break;
    // case 5:
    //     obj.search();
    //     break;
    // case 6:
    //     obj.no_of_records();
    //     int c;
    //     cout << "\n\n\n\nDo you want to return to the menu(1) or exit(2) ??????? ";
    //     cin >> c;
    //     switch(ch)
    //     {
    //         case 1:
    //             menu();
    //             break;
    //         case 2:
    //             exit(0);
    //     }
    //     break;
    case 7:
        exit(0);
    }
}
예제 #13
0
int main(int argc, const char *argv[])
{
  
  int choice;

  initscr();

  do {
    choice = getchoice("Options:", current_cd[0] ? extended_menu : main_menu);

    switch (choice) {
      case 'q':
        break;

      case 'a':
        add_record();
        break;

      case 'c':
        count_cds();
        break;

      case 'f':
        find_cd();
        break;

      case 'l':
        list_tracks();
        break;

      case 'r':
        remove_cd();
        break;

      case 'u':
        update_cd();
        break;
    }
  } while (choice != 'q');

  endwin();
  return 0;
}
예제 #14
0
파일: main.c 프로젝트: jonathanhamm/C-hash
int main (void)
{
	int i, j;
	int t = clock();
	int array[20000];
	hash_s *hash = DEFAULT_HASH();
	for (i = 0, j = 0; i < 20000; i++, j++)
	{
		array[j] = i;
		add_record (hash, (key_u)array[j]);
	}	
	for (i = 0; i < 1993; i++)
		if (delete_record (hash, (key_u)array[i]) < 0)
			printf("hello son\n");	
	print_hash (hash);
	printf("Last:%d\n",array[19999]);
	printf("%d,%d\n",hash->size, hash->collisions);
	dealloc_hash (hash);
	printf("total time: %d\n",(int)clock()-t);
}
예제 #15
0
파일: buddy.cpp 프로젝트: LubosD/twinkle
t_buddy *t_buddy_list::add_buddy(const t_buddy &buddy) {
	t_buddy *b = NULL;
	
	mtx_records.lock();
	add_record(buddy);
	
	// KLUDGE: this code assumes that the buddy is added at the end.
	b = &records.back();
	mtx_records.unlock();
	
	log_file->write_header("t_buddy_list::add_buddy");
	log_file->write_raw("Added buddy: ");
	log_file->write_raw(b->get_name());
	log_file->write_raw(", ");
	log_file->write_raw(b->get_sip_address());
	log_file->write_endl();
	log_file->write_footer();
	
	return b;
}
예제 #16
0
/*
void add_mime_media_record(stru_message *message, char *mimeType, unsigned char *payload)
{
	unsigned char payloadBytes[strlen(payload) + 1];

	memcpy(payloadBytes, payload,strlen(payload));

	stru_record *record = create_record();
	set_tnf(record, TNF_MIME_MEDIA);

	unsigned char type[strlen(mimeType) + 1];
	memcpy(type, mimeType, strlen(mimeType));
	set_type(record, type, strlen(mimeType));

	set_payload(record, payloadBytes, strlen(payload));

	add_record(message, record);
}
*/
void add_text_record(stru_message *message, char *text)
{
	stru_record *record = create_record();
	set_tnf(record, TNF_WELL_KNOWN);

	unsigned char RTD_TEXT[1] = { 0x54 }; // this should be a constant or preprocessor
	set_type(record, RTD_TEXT, sizeof(RTD_TEXT));

	// X is a placeholder for encoding length
	// is it more efficient to build w/o string concatenation?
	unsigned char payload[strlen(text) + 4];

	payload[strlen(text) + 3] = '\0';
	memcpy(payload, "Xen", 3);
	memcpy(payload + 3, text, strlen(text));
	// replace X with the real encoding length
	payload[0] = 2;
	set_payload(record, payload, strlen(text) + 3);

	add_record(message, record);
}
예제 #17
0
static void load_url_list(char * f_path)
{
	FILE * fp = NULL;
	int count_url = 0;
	char buf[1000];

	memset(buf, 0, 1000);

	if(f_path == NULL || *f_path =='\0') {
		printf("[ERROR] url list path is empty\n");
		return;
	}
	fp = fopen(f_path, "r");
	if (fp == NULL)
	{
		printf(" [ERROR] can't open file:%s\n", f_path);
		return;
	}

	printf(" Start to prepare url cache.\n");
	while( fgets(buf, 1000, fp) != NULL)
	{
		count_url ++ ;
	}

	set_url_records(count_url);
	fseek(fp, 0, SEEK_SET);
	
	
	while( fgets(buf, 1000, fp) != NULL)
	{
		add_record(buf);
		memset(buf, 0, sizeof(buf));
	}

	fclose(fp);
	

	printf(" Finish preparing url cache.\n");
}
예제 #18
0
/*
 * main()
 */
int main(int argc, char** argv) {
    pthread_t threads[NUM_THREADS]; // Create a new array of threads
    int i = 0; // Loop counter
    void *status; // Set a pointer to status
    int rc; // Used for error checking
    int j; // Loop counter
    pthread_mutex_t *lock = malloc(sizeof(pthread_mutex_t)); // Allocate the memory needed
    
    struct phone_record person = { // Create a person from phone record
        9286008799, // Phone number
        "Moody" // Name of person
    };
    
    struct Phone_Entries phone_entry = { // Create a phone entry
        &person, // Put our person in it
        lock // LOCK IT!
    };
    
    if (pthread_mutex_init(lock, NULL) != 0) { // Check if mutex initalized correctly
        printf("\nMutex failed to initialize\n"); // Oh no! We failed to initialize correctly
        return 1; // Return 1
    }
    
    while (i < NUM_THREADS) { // Iterate over the number of threads
        printf("\nCreating threads in main %d\n", i); // Let the user know what we are doing
        rc = pthread_create(&threads[i], NULL, data_access, (void *)&phone_entry); // Creat the threads!
        if (rc) { // Check if it really worked
            printf("Error, return code is %d\n", rc); // Oh no! We failed to create threads...
        }
        i++; // Increment the loop counter
    }
    
    for (j = 0; j < NUM_THREADS; j++) { // Loop to join the threads together
        pthread_join(threads[j], &status); // YES! Status has worked and we have created a thread
    }
    
    add_record(&person); // Add the person one last time
    printDB(); // Print the results
    return 0; // Return 0! Success!
}
예제 #19
0
void main()
{
    int i, op;
    clrscr();
    fp = fopen("work.dat","wb");
    if ( fp == NULL)
    {
        printf("\n Can not open a file ");
        exit(0);
    }
    fclose(fp);
    while( op != 4)
    {
        printf("\n \t\t Menu");
        printf("\n \t\t 1. Add record");
        printf("\n \t\t 2. Delete");
        printf("\n \t\t 3. Display");
        printf("\n \t\t 4. Exit");
        printf("\n Enter your choice :");
        scanf("%d",&op);

        switch(op)
        {
        case 1 :
            add_record();
            break;
        case 2 :
            del_record();
            break;
        case 3 :
            view();
            break;
        case 4 :
            break;
        }
        printf("\n");
    }
    getch();
}
예제 #20
0
파일: dnsparser.c 프로젝트: GNUnet/gnunet
/**
 * Given a DNS packet @a p, generate the corresponding UDP payload.
 * Note that we do not attempt to pack the strings with pointers
 * as this would complicate the code and this is about being
 * simple and secure, not fast, fancy and broken like bind.
 *
 * @param p packet to pack
 * @param max maximum allowed size for the resulting UDP payload
 * @param buf set to a buffer with the packed message
 * @param buf_length set to the length of @a buf
 * @return #GNUNET_SYSERR if @a p is invalid
 *         #GNUNET_NO if @a p was truncated (but there is still a result in @a buf)
 *         #GNUNET_OK if @a p was packed completely into @a buf
 */
int
GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
		       uint16_t max,
		       char **buf,
		       size_t *buf_length)
{
  struct GNUNET_TUN_DnsHeader dns;
  size_t off;
  char tmp[max];
  unsigned int i;
  int ret;
  int trc;

  if ( (p->num_queries > UINT16_MAX) ||
       (p->num_answers > UINT16_MAX) ||
       (p->num_authority_records > UINT16_MAX) ||
       (p->num_additional_records > UINT16_MAX) )
    return GNUNET_SYSERR;
  dns.id = p->id;
  dns.flags = p->flags;
  dns.query_count = htons (p->num_queries);
  dns.answer_rcount = htons (p->num_answers);
  dns.authority_rcount = htons (p->num_authority_records);
  dns.additional_rcount = htons (p->num_additional_records);

  off = sizeof (struct GNUNET_TUN_DnsHeader);
  trc = GNUNET_NO;
  for (i=0;i<p->num_queries;i++)
  {
    ret = GNUNET_DNSPARSER_builder_add_query (tmp, sizeof (tmp), &off, &p->queries[i]);
    if (GNUNET_SYSERR == ret)
      return GNUNET_SYSERR;
    if (GNUNET_NO == ret)
    {
      dns.query_count = htons ((uint16_t) (i-1));
      trc = GNUNET_YES;
      break;
    }
  }
  for (i=0;i<p->num_answers;i++)
  {
    ret = add_record (tmp, sizeof (tmp), &off, &p->answers[i]);
    if (GNUNET_SYSERR == ret)
      return GNUNET_SYSERR;
    if (GNUNET_NO == ret)
    {
      dns.answer_rcount = htons ((uint16_t) (i-1));
      trc = GNUNET_YES;
      break;
    }
  }
  for (i=0;i<p->num_authority_records;i++)
  {
    ret = add_record (tmp, sizeof (tmp), &off, &p->authority_records[i]);
    if (GNUNET_SYSERR == ret)
      return GNUNET_SYSERR;
    if (GNUNET_NO == ret)
    {
      dns.authority_rcount = htons ((uint16_t) (i-1));
      trc = GNUNET_YES;
      break;
    }
  }
  for (i=0;i<p->num_additional_records;i++)
  {
    ret = add_record (tmp, sizeof (tmp), &off, &p->additional_records[i]);
    if (GNUNET_SYSERR == ret)
      return GNUNET_SYSERR;
    if (GNUNET_NO == ret)
    {
      dns.additional_rcount = htons (i-1);
      trc = GNUNET_YES;
      break;
    }
  }

  if (GNUNET_YES == trc)
    dns.flags.message_truncated = 1;
  GNUNET_memcpy (tmp, &dns, sizeof (struct GNUNET_TUN_DnsHeader));

  *buf = GNUNET_malloc (off);
  *buf_length = off;
  GNUNET_memcpy (*buf, tmp, off);
  if (GNUNET_YES == trc)
    return GNUNET_NO;
  return GNUNET_OK;
}
예제 #21
0
static void
setup_tables(void)
{
  users = create_table("Users", GRN_OBJ_TABLE_HASH_KEY, "ShortText");
  daijiro = add_record("Users", "daijiro");
}
예제 #22
0
void
mono_locks_lock_released (RuntimeLocks kind, gpointer lock)
{
	add_record (RECORD_LOCK_RELEASED, kind, lock);
}
예제 #23
0
void iotrace_writel(ulong value, const void *ptr)
{
	add_record(IOT_32 | IOT_WRITE, ptr, value);
	writel(value, ptr);
}
예제 #24
0
/*
void add_uri_record(stru_message *message, char *uri)
{
	stru_record *record = create_record();
	set_tnf(record, TNF_WELL_KNOWN);

	unsigned char RTD_URI[1] = { 0x55 }; // this should be a constant or preprocessor
	set_type(record, RTD_URI, sizeof(RTD_URI));

	// X is a placeholder for identifier code
	unsigned char payload[strlen(uri) + 2];
	memcpy(payload, "X", 1);
	memcpy(payload + 1, uri, strlen(uri));

	// add identifier code 0x0, meaning no prefix substitution
	payload[0] = 0x0;

	set_payload(record, payload, strlen(uri) + 1);

	add_record(message, record);
}
*/
void add_empty_record(stru_message *message)
{
	stru_record *record = create_record();
    set_tnf(record, TNF_EMPTY);
    add_record(message, record);
}
예제 #25
0
stru_message *create_message_b(const unsigned char* data, const int numBytes)
{
	stru_message *message = &message_buffer;

	//message = (stru_message *)malloc(sizeof(stru_message));

	int index = 0;
	message->recordCount = 0;

    while(index <= numBytes)
    {
        // decode tnf - first byte is tnf with bit flags
        // see the NFDEF spec for more info
        unsigned char tnf_byte = data[index];
        bool mb = (tnf_byte & 0x80) != 0;
        bool me = (tnf_byte & 0x40) != 0;
        bool cf = (tnf_byte & 0x20) != 0;
        bool sr = (tnf_byte & 0x10) != 0;
        bool il = (tnf_byte & 0x8) != 0;
        unsigned char tnf = (tnf_byte & 0x7);

        stru_record *record = create_record();
        set_tnf(record, tnf);

        index++;
        int typeLength = data[index];

        int payloadLength = 0;
        if(sr)
        {
            index++;
            payloadLength = data[index];
        }
        else
        {
            payloadLength =((0xFF & data[++index]) << 24) | ((0xFF & data[++index]) << 16) | ((0xFF & data[++index]) << 8) | (0xFF & data[++index]);
        }

        int idLength = 0;
        if(il)
        {
            index++;
            idLength = data[index];
        }

        index++;
        set_type(record, &data[index], typeLength);
        index += typeLength;

        if(il)
        {
            set_id(record, &data[index], idLength);
            index += idLength;
        }

        set_payload(record, &data[index], payloadLength);
        index += payloadLength;

        add_record(message, record);

        if(me)break; // last message
    }
    return message;
}
예제 #26
0
int load_reg_info_from_db(unsigned int plist)
{
	db_res_t * res = NULL;
	db_val_t * values;
	db_row_t * rows;
	int i, nr_rows, ret;
	unsigned int n_result_cols = 0;
	unsigned int registrar_col;
	unsigned int proxy_col;
	unsigned int aor_col;
	unsigned int third_party_registrant_col;
	unsigned int username_col;
	unsigned int password_col;
	unsigned int binding_URI_col;
	unsigned int binding_params_col;
	unsigned int expiry_col;
	unsigned int forced_socket_col;
	db_key_t q_cols[REG_TABLE_TOTAL_COL_NO];

	char *p = NULL;
	int len = 0;
	str now = {NULL, 0};
	struct sip_uri uri;
	str forced_socket, host;
	int port, proto;
	uac_reg_map_t uac_param;

	p = int2str((unsigned long)(time(0)), &len);
	if (p && len>0) {
		now.s = (char *)pkg_malloc(len);
		if(now.s) {
			memcpy(now.s, p, len); now.len = len;
		} else {
			LM_ERR("oom\n"); return -1;
		}
	}

	if(use_reg_table()) return -1;

	q_cols[registrar_col = n_result_cols++] = &registrar_column;
	q_cols[proxy_col = n_result_cols++] = &proxy_column;
	q_cols[aor_col = n_result_cols++] = &aor_column;
	q_cols[third_party_registrant_col = n_result_cols++] =
					&third_party_registrant_column;
	q_cols[username_col = n_result_cols++] = &username_column;
	q_cols[password_col = n_result_cols++] = &password_column;
	q_cols[binding_URI_col = n_result_cols++] = &binding_URI_column;
	q_cols[binding_params_col = n_result_cols++] = &binding_params_column;
	q_cols[expiry_col = n_result_cols++] = &expiry_column;
	q_cols[forced_socket_col = n_result_cols++] = &forced_socket_column;

	/* select the whole tabel and all the columns */
	if (DB_CAPABILITY(reg_dbf, DB_CAP_FETCH)) {
		if(reg_dbf.query(reg_db_handle, 0, 0, 0, q_cols, 0,
				REG_TABLE_TOTAL_COL_NO, 0, 0) < 0) {
			LM_ERR("Error while querying (fetch) database\n");
			return -1;
		}
		if(reg_dbf.fetch_result(reg_db_handle, &res, REG_FETCH_SIZE)<0){
			LM_ERR("fetching rows failed\n");
			return -1;
		}
	} else {
		if(reg_dbf.query(reg_db_handle, 0, 0, 0, q_cols, 0,
				REG_TABLE_TOTAL_COL_NO, 0, &res) < 0) {
			LM_ERR("Error while querying database\n");
			return -1;
		}
	}

	nr_rows = RES_ROW_N(res);

	do {
		LM_INFO("loading [%i] records from db\n", nr_rows);
		rows = RES_ROWS(res);
		/* for every row/record */
		for(i=0; i<nr_rows; i++){
			values = ROW_VALUES(rows + i);
			if (VAL_NULL(values+registrar_col) ||
				VAL_NULL(values+aor_col) ||
				VAL_NULL(values+binding_URI_col)) {
				LM_ERR("columns [%.*s] or/and [%.*s] or/and [%.*s]"
					" cannot be null -> skipping\n",
					registrar_column.len, registrar_column.s,
					aor_column.len, aor_column.s,
					binding_URI_column.len, binding_URI_column.s);
				continue;
			}

			memset(&uac_param, 0, sizeof(uac_reg_map_t));

			/* Get the registrar (mandatory parameter) */
			uac_param.registrar_uri.s =
				(char*)values[registrar_col].val.string_val;
			if (uac_param.registrar_uri.s)
				uac_param.registrar_uri.len =
					strlen(uac_param.registrar_uri.s);
			else {
				LM_ERR("ignoring empty registrar\n");
				continue;
			}
			if (parse_uri(uac_param.registrar_uri.s,
					uac_param.registrar_uri.len, &uri)<0) {
				LM_ERR("cannot parse registrar uri [%.*s]\n",
					uac_param.registrar_uri.len,
					uac_param.registrar_uri.s);
				continue;
			}
			if (uri.user.s && uri.user.len) {
				LM_ERR("registrant uri must not have user [%.*s]\n",
					uri.user.len, uri.user.s);
				continue;
			}

			/* Get the proxy */
			uac_param.proxy_uri.s =
				(char*)values[proxy_col].val.string_val;
			if (uac_param.proxy_uri.s)
				uac_param.proxy_uri.len =
					strlen(uac_param.proxy_uri.s);
			if (uac_param.proxy_uri.len) {
				if (parse_uri(uac_param.proxy_uri.s,
						uac_param.proxy_uri.len, &uri)<0) {
					LM_ERR("cannot parse proxy uri [%.*s]\n",
						uac_param.proxy_uri.len,
						uac_param.proxy_uri.s);
					continue;
				}
				if (uri.user.s && uri.user.len) {
					LM_ERR("proxy uri must not have user [%.*s]\n",
						uri.user.len, uri.user.s);
					continue;
				}
			} else {
				uac_param.proxy_uri.s = NULL;
			}

			/* Get the AOR (mandatory parameter) */
			uac_param.to_uri.s =
				(char*)values[aor_col].val.string_val;
			if (uac_param.to_uri.s)
				uac_param.to_uri.len = strlen(uac_param.to_uri.s);
			else {
				LM_ERR("ignoring empty AOR\n");
				continue;
			}
			if (parse_uri(uac_param.to_uri.s,uac_param.to_uri.len,&uri)<0) {
				LM_ERR("cannot parse aor uri [%.*s]\n",
					uac_param.to_uri.len, uac_param.to_uri.s);
				continue;
			}
			uac_param.hash_code =
				core_hash(&uac_param.to_uri, NULL, reg_hsize);

			/* Get the third party registrant */
			uac_param.from_uri.s =
				(char*)values[third_party_registrant_col].val.string_val;
			if (uac_param.from_uri.s)
				uac_param.from_uri.len = strlen(uac_param.from_uri.s);
			if (uac_param.from_uri.len) {
				if (parse_uri(uac_param.from_uri.s,
						uac_param.from_uri.len, &uri)<0) {
					LM_ERR("cannot parse third party registrant"
						" uri [%.*s]\n",
						uac_param.from_uri.len,
						uac_param.from_uri.s);
					continue;
				}
			} else {
				uac_param.from_uri.s = NULL;
			}

			/* Get the binding (manadatory parameter) */
			uac_param.contact_uri.s =
				(char*)values[binding_URI_col].val.string_val;
			if (uac_param.contact_uri.s)
				uac_param.contact_uri.len =
					strlen(uac_param.contact_uri.s);
			else {
				LM_ERR("ignoring empty binding\n");
				continue;
			}
			if (parse_uri(uac_param.contact_uri.s,
					uac_param.contact_uri.len, &uri)<0) {
				LM_ERR("cannot parse contact uri [%.*s]\n",
					uac_param.contact_uri.len,
					uac_param.contact_uri.s);
				continue;
			}

			/* Get the authentication user */
			uac_param.auth_user.s =
				(char*)values[username_col].val.string_val;
			if (uac_param.auth_user.s)
				uac_param.auth_user.len = strlen(uac_param.auth_user.s);
			if (uac_param.auth_user.len == 0) uac_param.auth_user.s = NULL;

			/* Get the authentication password */
			uac_param.auth_password.s =
				(char*)values[password_col].val.string_val;
			if (uac_param.auth_password.s)
				uac_param.auth_password.len =
					strlen(uac_param.auth_password.s);
			if (uac_param.auth_password.len == 0)
				uac_param.auth_password.s = NULL;

			/* Get the binding params */
			uac_param.contact_params.s =
				(char*)values[binding_params_col].val.string_val;
			if (uac_param.contact_params.s)
				uac_param.contact_params.len =
					strlen(uac_param.contact_params.s);
			if (uac_param.contact_params.len == 0)
				uac_param.contact_params.s = NULL;

			/* Get the expiration param */
			uac_param.expires = values[expiry_col].val.int_val;
			if (uac_param.expires <= timer_interval) {
				LM_ERR("Please decrease timer_interval=[%u]"
					" - requested expires=[%u] to small for AOR=[%.*s]\n",
					timer_interval, uac_param.expires,
					uac_param.to_uri.len, uac_param.to_uri.s);
				continue;
			}

			/* Get the socket */
			if (values[forced_socket_col].val.string_val &&
				(forced_socket.s = (char*)values[forced_socket_col].val.string_val)) {
				if((forced_socket.len = strlen(forced_socket.s))){
					if (parse_phostport(forced_socket.s,
							forced_socket.len,
							&host.s, &host.len,
							&port, &proto)<0) {
						LM_ERR("cannot parse forced socket [%.*s]\n",
							forced_socket.len, forced_socket.s);
						continue;
					}
					uac_param.send_sock = grep_sock_info(&host,
								(unsigned short) port,
								(unsigned short) proto);
					if (uac_param.send_sock==NULL) {
						LM_ERR("invalid forced socket [%.*s]\n",
							forced_socket.len, forced_socket.s);
						continue;
					}
				}
			}
			LM_DBG("registrar=[%.*s] AOR=[%.*s] auth_user=[%.*s] "
				"password=[%.*s] expire=[%d] proxy=[%.*s] "
				"contact=[%.*s] third_party=[%.*s]\n",
				uac_param.registrar_uri.len, uac_param.registrar_uri.s,
				uac_param.to_uri.len, uac_param.to_uri.s,
				uac_param.auth_user.len, uac_param.auth_user.s,
				uac_param.auth_password.len, uac_param.auth_password.s,
				uac_param.expires,
				uac_param.proxy_uri.len, uac_param.proxy_uri.s,
				uac_param.contact_uri.len, uac_param.contact_uri.s,
				uac_param.from_uri.len, uac_param.from_uri.s);
			lock_get(&reg_htable[uac_param.hash_code].lock);
			ret = add_record(&uac_param, &now, plist);
			lock_release(&reg_htable[uac_param.hash_code].lock);
			if(ret<0) {
				LM_ERR("can't load registrant\n");
				continue;
			}
		}

		/* any more data to be fetched ?*/
		if (DB_CAPABILITY(reg_dbf, DB_CAP_FETCH)) {
			if (reg_dbf.fetch_result(reg_db_handle, &res, REG_FETCH_SIZE)<0) {
				LM_ERR("fetching more rows failed\n");
				goto error;
			}
			nr_rows = RES_ROW_N(res);
		} else {
			nr_rows = 0;
		}
	}while (nr_rows>0);

	reg_dbf.free_result(reg_db_handle, res);
	if (now.s) pkg_free(now.s);
	return 0;
error:
	reg_dbf.free_result(reg_db_handle, res);
	if (now.s) pkg_free(now.s);
	return -1;
}
예제 #27
0
파일: register.c 프로젝트: edenden/lix
void *start_map_register(void *arg){
	int ipv4_no_eid = 0;
	int ipv6_no_eid = 0;
	int ipv4_no_rloc = 0;
	int ipv6_no_rloc = 0;

        struct record request_dest;
        struct record request_source;
        memset(&request_dest, 0, sizeof(struct record));
        memset(&request_source, 0, sizeof(struct record));

	/* read rloc config */
        struct config *rloc_config = (struct config *)config_root.under_layers[RLOC_LAYER];
	if(rloc_config == NULL){
		warn("no rloc configured");
		return;
	}
        struct rloc_layer_data *rloc_data = (struct rloc_layer_data *)(rloc_config->data);

	struct address_list *addr_list = &(rloc_data->v6address);
        if(addr_list->next != NULL){
                do{
                        addr_list = addr_list->next;

		        char address[16];
		        inet_pton(AF_INET6, addr_list->address, address);

		        struct register_locator_attr *attr = malloc(sizeof(struct register_locator_attr));
		        attr->priority = 0;
		        attr->weight = 100;
		        add_record(&request_source, AF_INET6, 128, address, attr);
                }while(addr_list->next != NULL);
        }else{
                ipv6_no_rloc = 1;
        }

        addr_list = &(rloc_data->v4address);
        if(addr_list->next != NULL){
                do{
                        addr_list = addr_list->next;

                        char address[4];
                        inet_pton(AF_INET, addr_list->address, address);

                        struct register_locator_attr *attr = malloc(sizeof(struct register_locator_attr));
                        attr->priority = 0;
                        attr->weight = 100;
                        add_record(&request_source, AF_INET, 32, address, attr);
                }while(addr_list->next != NULL);
        }else{
                ipv4_no_rloc = 1;
        }

        if(ipv4_no_rloc == 1 && ipv6_no_rloc == 1){
                warn("no rloc configured");
		return;
        }

	/* read eid config */
	struct config *eid_config = (struct config *)config_root.under_layers[EID_LAYER];
	if(eid_config == NULL){
		warn("no eid configured");
		return;
	}
	struct eid_layer_data *eid_data = (struct eid_layer_data *)(eid_config->data);

	addr_list = &(eid_data->v6prefix);
	if(addr_list->next != NULL){
		do{
			addr_list = addr_list->next;

                        char address[16];
                        inet_pton(AF_INET6, addr_list->address, address);

		        struct register_record_attr *attr = malloc(sizeof(struct register_record_attr));
		        attr->record_ttl = default_ttl;
		        attr->act = 0;
			add_record(&request_dest, AF_INET6, addr_list->prefix, address, attr);
		}while(addr_list->next != NULL);
	}else{
		ipv6_no_eid = 1;
	}

        addr_list = &(eid_data->v4prefix);
	if(addr_list->next != NULL){
        	do{
        	        addr_list = addr_list->next;

                        char address[4];
                        inet_pton(AF_INET, addr_list->address, address);

                        struct register_record_attr *attr = malloc(sizeof(struct register_record_attr));
                        attr->record_ttl = default_ttl;
                        attr->act = 0;
                        add_record(&request_dest, AF_INET, addr_list->prefix, address, attr);
        	}while(addr_list->next != NULL);
	}else{
		ipv4_no_eid = 1;
	}

	if(ipv4_no_eid == 1 && ipv6_no_eid == 1){
		err(EXIT_FAILURE, "no eid configured");
	}

	send_map_register(&request_dest, &request_source);

	free_record(&request_dest);
	free_record(&request_source);
}
예제 #28
0
void
mono_locks_lock_acquired (RuntimeLocks kind, gpointer lock)
{
	add_record (RECORD_LOCK_ACQUIRED, kind, lock);
}
static void
show_week (UmHistoryDialog *um)
{
        GArray *login_history;
        GDateTime *datetime, *temp;
        gint64 from, to;
        gint i, line;
        GtkWidget *grid;
        UmLoginHistory history;

        show_week_label (um);
        clear_history (um);
        set_sensitivity (um);

        login_history = get_login_history (um->user);
        if (login_history == NULL) {
                return;
        }

        /* Find first record for week */
        from = g_date_time_to_unix (um->week);
        temp = g_date_time_add_weeks (um->week, 1);
        to = g_date_time_to_unix (temp);
        g_date_time_unref (temp);
        for (i = login_history->len - 1; i >= 0; i--) {
                history = g_array_index (login_history, UmLoginHistory, i);
                if (history.login_time < to) {
                        break;
                }
        }

        /* Add new session records */
        grid = get_widget (um, "history-grid");
        line = 0;
        for (;i >= 0; i--) {
                history = g_array_index (login_history, UmLoginHistory, i);
                if (history.logout_time > 0 && history.logout_time < from) {
                        break;
                }

                /* Display only x-sessions */
                if (g_strrstr (history.type, ":") == NULL) {
                        continue;
                }

                if (history.logout_time > 0 && history.logout_time < to) {
                        datetime = g_date_time_new_from_unix_local (history.logout_time);
                        add_record (grid, datetime, "Session Ended", line);
                        line++;
                }

                if (history.login_time >= from) {
                        datetime = g_date_time_new_from_unix_local (history.login_time);
                        add_record (grid, datetime, "Session Started", line);
                        line++;
                }
        }

        gtk_widget_show_all (grid);

        g_array_free (login_history, TRUE);
}
예제 #30
0
파일: registrant.c 프로젝트: mtulio/mtulio
/** Module init function */
static int mod_init(void)
{
	uac_reg_map_t *_uac_param, *uac_param = uac_params;
	char *p = NULL;
	int len = 0;
	str now = {NULL, 0};

	LM_DBG("start\n");

	regfree(&uac_params_regex);

	if(load_uac_auth_api(&uac_auth_api)<0){
		LM_ERR("Failed to load uac_auth api\n");
		return -1;
	}

	if(default_expires<15){
		LM_ERR("default_expires to short: [%d]<15\n", default_expires);
		return -1;
	}
	if(timer_interval<10){
		LM_ERR("timer_interval to short: [%d]<10\n", timer_interval);
		return -1;
	}
	if(reg_hsize<1 || reg_hsize>20) {
		LM_ERR("Wrong hash size: 20<[%d]<1\n", reg_hsize);
	}
	reg_hsize = 1<<reg_hsize;

	if(init_reg_htable()<0) {
		LM_ERR("Failed to initialize registrant hash table\n");
		return -1;
	}

	/* load all TM stuff */
	if(load_tm_api(&tmb)==-1) {
		LM_ERR("can't load tm functions\n");
		return -1;
	}

	p = int2str((unsigned long)(time(0)), &len);
	if (p && len>0) {
		now.s = (char *)pkg_malloc(len);
		if(now.s) {
			memcpy(now.s, p, len);
			now.len = len;
		} else {
			LM_ERR("oom\n");
			return -1;
		}
	}
	
	while(uac_param) {
		LM_DBG("let's register [%.*s] on [%.*s] from hash table [%d]\n",
			uac_param->to_uri.len, uac_param->to_uri.s,
			uac_param->registrar_uri.len, uac_param->registrar_uri.s,
			uac_param->hash_code);
		if(add_record(uac_param, &now)<0) {
			LM_ERR("can't load registrant\n");
			if (now.s) {pkg_free(now.s);}
			return -1;
		}
		_uac_param = uac_param;
		uac_param = uac_param->next;
		pkg_free(_uac_param);
	}
	uac_params = NULL;
	if (now.s) {pkg_free(now.s);}

	register_timer(timer_check, 0, timer_interval/reg_hsize);

	return 0;
}