Esempio n. 1
0
dce_result_t SECTION_ATTR dce_process_command_line(dce_t* ctx)
{
    ctx->command_pending = 1;
    
    // 5.2.1 command line format
    size_t size = ctx->command_line_length;
    char *buf = ctx->command_line_buf;
    
    if (size < 2)
    {
        DCE_DEBUG("line does not start with AT");
        dce_emit_basic_result_code(ctx, DCE_RC_ERROR);
        return DCE_OK;
    }
    
    // command line should start with 'AT' prefix
    // TODO: implement support for command line repetition (5.2.4)
    if (!BEGINS(buf, 'A', 'T') &&
        !BEGINS(buf, 'a', 't'))
    {
        DCE_DEBUG("line does not start with AT");
        dce_emit_basic_result_code(ctx, DCE_RC_ERROR);
        return DCE_OK;
    }
    
    if (size == 2)   // 'AT' was sent
    {
        dce_emit_basic_result_code(ctx, DCE_RC_OK);
        return DCE_OK;
    }
    
    buf += 2;
    size -= 2;
    // process single command
    // TODO: implement support for multiple commands per line
    
    char c = buf[0];
    if (c == '+')
        return dce_process_extended_format_command(ctx, buf + 1, size - 1);

    if (c == 'S')  // S-parameter (5.3.2)
        return dce_process_sparameter_command(ctx, buf + 1, size - 1);
    
    return dce_process_basic_command(ctx, buf, size);
}
Esempio n. 2
0
/* We assume gn_phonebook_entry is ready for writing in, ie. no rubbish inside */
GNOKII_API int gn_ldif2phonebook(FILE *f, gn_phonebook_entry *entry)
{
	char buf[10240];
	int i;

	while (1) {
		if (!fgets(buf, 1024, f))
			return -1;
		if (BEGINS("dn:"))
			break;
	}

	while (1) {
		if (!fgets(buf, 1024, f)) {
			ERROR("LDIF began but not ended?");
			return -1;
		}
		STORE("cn: ", entry->name);
		STORE_BASE64("cn:: ", entry->name);

		STORESUB("homeurl: ", GN_PHONEBOOK_ENTRY_URL);
		STORESUB_BASE64("homeurl:: ", GN_PHONEBOOK_ENTRY_URL);
		STORESUB("mail: ", GN_PHONEBOOK_ENTRY_Email);
		STORESUB_BASE64("mail:: ", GN_PHONEBOOK_ENTRY_Email);
		STORESUB("homePostalAddress: ", GN_PHONEBOOK_ENTRY_Postal);
		STORESUB_BASE64("homePostalAddress:: ", GN_PHONEBOOK_ENTRY_Postal);
		STORESUB("Description: ", GN_PHONEBOOK_ENTRY_Note);
		STORESUB_BASE64("Description:: ", GN_PHONEBOOK_ENTRY_Note);

		STORENUM("homePhone: ", GN_PHONEBOOK_NUMBER_Home);
		STORENUM_BASE64("homePhone:: ", GN_PHONEBOOK_NUMBER_Home);
		STORENUM("mobile: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM_BASE64("mobile:: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM("cellphone: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM_BASE64("cellphone:: ", GN_PHONEBOOK_NUMBER_Mobile);
		STORENUM("fax: ", GN_PHONEBOOK_NUMBER_Fax);
		STORENUM_BASE64("fax:: ", GN_PHONEBOOK_NUMBER_Fax);
		STORENUM("workPhone: ", GN_PHONEBOOK_NUMBER_Work);
		STORENUM_BASE64("workPhone:: ", GN_PHONEBOOK_NUMBER_Work);
		STORENUM("telephoneNumber: ", GN_PHONEBOOK_NUMBER_General);
		STORENUM_BASE64("telephoneNumber:: ", GN_PHONEBOOK_NUMBER_General);
		
		STOREINT("businessCategory: ", entry->caller_group);

		if (BEGINS("\n"))
			break;
	}
	/* set entry->number from the first sub-entry that is a number */
	for (i = 0; i < entry->subentries_count && entry->number[0] == 0; i++) {
		if (entry->subentries[i].entry_type == GN_PHONEBOOK_ENTRY_Number) {
			switch (entry->subentries[i].number_type) {
			case GN_PHONEBOOK_NUMBER_None:
			case GN_PHONEBOOK_NUMBER_Common:
			case GN_PHONEBOOK_NUMBER_General:
			case GN_PHONEBOOK_NUMBER_Work: 
			case GN_PHONEBOOK_NUMBER_Home:
			case GN_PHONEBOOK_NUMBER_Mobile:
				dprintf("setting default number to %s\n", entry->subentries[i].data.number);
				snprintf(entry->number, sizeof(entry->number), "%s", entry->subentries[i].data.number);
				break;
			default:
				dprintf("unknown type\n");
				break;
			}
		}
	}
	return 0;
}