Exemple #1
0
/*---------------------------------------------------------------------------*/
int
rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len)
{
  rpl_prefix_t last_prefix;
  uint8_t last_len = dag->prefix_info.length;

  if(len > 128) {
    return 0;
  }
  if(dag->prefix_info.length != 0) {
    memcpy(&last_prefix, &dag->prefix_info, sizeof(rpl_prefix_t));
  }
  memset(&dag->prefix_info.prefix, 0, sizeof(dag->prefix_info.prefix));
  memcpy(&dag->prefix_info.prefix, prefix, (len + 7) / 8);
  dag->prefix_info.length = len;
  dag->prefix_info.flags = UIP_ND6_RA_FLAG_AUTONOMOUS;
  PRINTF("RPL: Prefix set - will announce this in DIOs\n");
  if(dag->rank != ROOT_RANK(dag->instance)) {
    /* Autoconfigure an address if this node does not already have an address
       with this prefix. Otherwise, update the prefix */
    if(last_len == 0) {
      PRINTF("rpl_set_prefix - prefix NULL\n");
      check_prefix(NULL, &dag->prefix_info);
    } else {
      PRINTF("rpl_set_prefix - prefix NON-NULL\n");
      check_prefix(&last_prefix, &dag->prefix_info);
    }
  }
  return 1;
}
static int
read_map(avro_reader_t reader, const avro_encoding_t * enc,
	 avro_consumer_t *consumer, void *ud)
{
	int rval;
	int64_t i;          /* index within the current block */
	int64_t index = 0;  /* index within the entire array */
	int64_t block_count;
	int64_t block_size;

	check_prefix(rval, enc->read_long(reader, &block_count),
		     "Cannot read map block count: ");
	check(rval, avro_consumer_call(consumer, map_start_block,
				       1, block_count, ud));

	while (block_count != 0) {
		if (block_count < 0) {
			block_count = block_count * -1;
			check_prefix(rval, enc->read_long(reader, &block_size),
				     "Cannot read map block size: ");
		}

		for (i = 0; i < block_count; i++, index++) {
			char *key;
			int64_t key_size;
			avro_consumer_t  *element_consumer = NULL;
			void  *element_ud = NULL;

			check_prefix(rval, enc->read_string(reader, &key, &key_size),
				     "Cannot read map key: ");

			rval = avro_consumer_call(consumer, map_element,
						  index, key,
						  &element_consumer, &element_ud,
						  ud);
			if (rval) {
				avro_free(key, key_size);
				return rval;
			}

			rval = avro_consume_binary(reader, element_consumer, element_ud);
			if (rval) {
				avro_free(key, key_size);
				return rval;
			}

			avro_free(key, key_size);
		}

		check_prefix(rval, enc->read_long(reader, &block_count),
			     "Cannot read map block count: ");
		check(rval, avro_consumer_call(consumer, map_start_block,
					       0, block_count, ud));
	}

	return 0;
}
Exemple #3
0
static int check_filenames(git_patch_parsed *patch)
{
	const char *prefixed_new, *prefixed_old;
	size_t old_prefixlen = 0, new_prefixlen = 0;
	bool added = (patch->base.delta->status == GIT_DELTA_ADDED);
	bool deleted = (patch->base.delta->status == GIT_DELTA_DELETED);

	if (patch->old_path && !patch->new_path)
		return git_parse_err("missing new path");

	if (!patch->old_path && patch->new_path)
		return git_parse_err("missing old path");

	/* Ensure (non-renamed) paths match */
	if (check_header_names(
			patch->header_old_path, patch->old_path, "old", added) < 0 ||
		check_header_names(
			patch->header_new_path, patch->new_path, "new", deleted) < 0)
		return -1;

	prefixed_old = (!added && patch->old_path) ? patch->old_path :
		patch->header_old_path;
	prefixed_new = (!deleted && patch->new_path) ? patch->new_path :
		patch->header_new_path;

	if (check_prefix(
			&patch->old_prefix, &old_prefixlen, patch, prefixed_old) < 0 ||
		check_prefix(
			&patch->new_prefix, &new_prefixlen, patch, prefixed_new) < 0)
		return -1;

	/* Prefer the rename filenames as they are unambiguous and unprefixed */
	if (patch->rename_old_path)
		patch->base.delta->old_file.path = patch->rename_old_path;
	else
		patch->base.delta->old_file.path = prefixed_old + old_prefixlen;

	if (patch->rename_new_path)
		patch->base.delta->new_file.path = patch->rename_new_path;
	else
		patch->base.delta->new_file.path = prefixed_new + new_prefixlen;

	if (!patch->base.delta->old_file.path &&
		!patch->base.delta->new_file.path)
		return git_parse_err("git diff header lacks old / new paths");

	return 0;
}
Exemple #4
0
/**
 * Searches for a value in the ART tree
 * @arg t The tree
 * @arg key The key
 * @arg key_len The length of the key
 * @return NULL if the item was not found, otherwise
 * the value pointer is returned.
 */
void* art_search(const art_tree *t, const unsigned char *key, int key_len) {
    art_node **child;
    art_node *n = t->root;
    int prefix_len, depth = 0;
    while (n) {
        // Might be a leaf
        if (IS_LEAF(n)) {
            n = (art_node*)LEAF_RAW(n);
            // Check if the expanded path matches
            if (!leaf_matches((art_leaf*)n, key, key_len, depth)) {
                return ((art_leaf*)n)->value;
            }
            return NULL;
        }

        // Bail if the prefix does not match
        if (n->partial_len) {
            prefix_len = check_prefix(n, key, key_len, depth);
            if (prefix_len != min(MAX_PREFIX_LEN, n->partial_len))
                return NULL;
            depth = depth + n->partial_len;
        }

        // Recursively search
        child = find_child(n, key[depth]);
        n = (child) ? *child : NULL;
        depth++;
    }
    return NULL;
}
static int
read_array(avro_reader_t reader, const avro_encoding_t * enc,
	   avro_consumer_t *consumer, void *ud)
{
	int rval;
	int64_t i;          /* index within the current block */
	int64_t index = 0;  /* index within the entire array */
	int64_t block_count;
	int64_t block_size;

	check_prefix(rval, enc->read_long(reader, &block_count),
		     "Cannot read array block count: ");
	check(rval, avro_consumer_call(consumer, array_start_block,
				       1, block_count, ud));

	while (block_count != 0) {
		if (block_count < 0) {
			block_count = block_count * -1;
			check_prefix(rval, enc->read_long(reader, &block_size),
				     "Cannot read array block size: ");
		}

		for (i = 0; i < block_count; i++, index++) {
			avro_consumer_t  *element_consumer = NULL;
			void  *element_ud = NULL;

			check(rval,
			      avro_consumer_call(consumer, array_element,
					         index, &element_consumer, &element_ud,
						 ud));

			check(rval, avro_consume_binary(reader, element_consumer, element_ud));
		}

		check_prefix(rval, enc->read_long(reader, &block_count),
			     "Cannot read array block count: ");
		check(rval, avro_consumer_call(consumer, array_start_block,
					       0, block_count, ud));
	}

	return 0;
}
Exemple #6
0
/**
 * Convert mime string to media type constants value
 */
static javacall_media_type javautil_media_mime_to_type(const javacall_utf16* mime, long length)
{
    javacall_media_type ret = JAVACALL_END_OF_TYPE;
    char* cMime = MALLOC(length + 1);

    if (cMime) {
        int wres = WideCharToMultiByte(CP_ACP, 0, mime, length, 
            cMime, length + 1, NULL, NULL);

        if (0 != wres) {
            cMime[length] = 0;
            JAVA_DEBUG_PRINT1("javautil_media_mime_to_type %s\n", cMime);

            if (0 == strcmp(JAVACALL_AUDIO_MIDI_MIME, cMime)) {
                ret = JAVACALL_AUDIO_MIDI;
            } else if (0 == strcmp(JAVACALL_AUDIO_MIDI_MIME_2, cMime)) {
                ret = JAVACALL_AUDIO_MIDI;
            } else if (0 == strcmp(JAVACALL_AUDIO_SP_MIDI_MIME, cMime)) {
                ret = JAVACALL_AUDIO_MIDI;
            } else if (0 == strcmp(JAVACALL_AUDIO_WAV_MIME, cMime)) {
                ret = JAVACALL_AUDIO_WAV;
            } else if (0 == strcmp(JAVACALL_AUDIO_MP3_MIME, cMime)) {
                ret = JAVACALL_AUDIO_MP3;
            } else if (0 == strcmp(JAVACALL_AUDIO_TONE_MIME, cMime)) {
                ret = JAVACALL_AUDIO_TONE;
            } else if (0 == strcmp(JAVACALL_DEVICE_TONE_MIME, cMime)) {
                ret = JAVACALL_AUDIO_TONE;
            } else if (0 == strcmp(JAVACALL_DEVICE_MIDI_MIME, cMime)) {
                ret = JAVACALL_INTERACTIVE_MIDI;
            } else if (0 == strcmp(JAVACALL_VIDEO_MPEG4_MIME_2, cMime)) {
                ret = JAVACALL_VIDEO_MPEG4;
            } else if (0 == check_prefix(JAVACALL_CAPTURE_VIDEO_MIME, cMime)) {
                ret = JAVACALL_CAPTURE_VIDEO;
            } else if (0 == check_prefix(JAVACALL_CAPTURE_AUDIO_MIME, cMime)) {
                ret = JAVACALL_CAPTURE_AUDIO;
            }
        }
        FREE(cMime);
    }

    return ret;
}
static int
read_enum(avro_reader_t reader, const avro_encoding_t * enc,
	  avro_consumer_t *consumer, void *ud)
{
	int rval;
	int64_t index;

	check_prefix(rval, enc->read_long(reader, &index),
		     "Cannot read enum value: ");
	return avro_consumer_call(consumer, enum_value, index, ud);
}
Exemple #8
0
/**
 * Handle syscalls that take a path as the first parameter
 */
static void _handle_file_series_syscalls(pid_t pid, char* syscall, int flag, uid_t uid, gid_t gid)
{
	// TODO
	tracee_ptr_t path_ptr = (tracee_ptr_t) ptrace_get_syscall_arg(pid, 0);
	int len = ptrace_strlen(pid, path_ptr);
	char path[len + 1];
	ptrace_read_data(pid, path, path_ptr, len + 1);
#if 0
	int nth_dir;

	if ((flag & SANDBOX_CHROOT_PRIVATE_FOLDER) && (nth_dir = check_prefix_dir(path,SANDBOX_PATH_INTERNAL)) > 0) {
		//internal file storage sandbox
		char* sub_dir = get_nth_dir(path, nth_dir + 2);
		if (!check_prefix(sub_dir, SANDBOX_PATH_INTERNAL_EXCLUDE)) {
			char new_path[len + 1];
			//replace dir in path with LINK_PREFIX
			char* second_dir = get_nth_dir(path, nth_dir + 1);
			strcpy(new_path, SANDBOX_LINK);
			strcat(new_path, second_dir);
			ptrace_write_data(pid, new_path, path_ptr, len + 1);
			// create require folder
			create_nth_dir(new_path, 3, uid, gid, 0751);
			LOGD("pid %d %s: %s ==> new path: %s", pid, syscall, path, new_path);

			// return from open syscall, reset the path
			pid = waitpid(pid, NULL, __WALL);

			ptrace_write_data(pid, path, path_ptr, len + 1);
			long result = ptrace_get_syscall_arg(pid, 0);
			LOGD(" = %ld\n", result);

			return;
		}
	/* } else if ((flag & SANDBOX_FLAG) && FILE_SANDBOX_ENABLED && (nth_dir = check_prefix_dir(path,SANDBOX_PATH_EXTERNAL)) > 0) { */
	/* 	//external file storage sandbox */
	/* 	char new_path[len + 1]; */
	/* 	//replace dir in path with LINK_PREFIX */
	/* 	char* second_dir = get_nth_dir(path, nth_dir + 1); */
	/* 	strcpy(new_path, SANDBOX_LINK); */
	/* 	strcat(new_path, second_dir); */
	/* 	ptrace_write_data(pid, new_path, arg0, len + 1); */
	/* 	LOGD("pid %d %s: %s\n ==> new path: %s\n", pid, syscall, path, new_path); */

	/* 	// return from open syscall, reset the path */
	/* 	pid = waitpid(pid, NULL, __WALL); */

	/* 	ptrace_write_data(pid, path, arg0, len + 1); */

	/* 	return; */
	}
#endif
	LOGD("[%d] %s(%s, ...)\n", pid, syscall, path);
}
int
heim_digest_parse_challenge(heim_digest_t context, const char *challenge)
{
    struct md5_value *val = NULL;
    int ret, type;
    
    challenge = check_prefix(context, challenge);

    ret = parse_values(challenge, &val);
    if (ret)
	goto out;

    ret = 1;

    context->serverNonce = values_find(&val, "nonce");
    if (context->serverNonce == NULL) goto out;

    context->serverRealm = values_find(&val, "realm");
    if (context->serverRealm == NULL) goto out;

    /* check alg */

    context->serverAlgorithm = values_find(&val, "algorithm");
    if (context->serverAlgorithm == NULL || strcasecmp(context->serverAlgorithm, "md5") == 0) {
	type = HEIM_DIGEST_TYPE_RFC2617_MD5;
    } else if (strcasecmp(context->serverAlgorithm, "md5-sess") == 0) {
	type = HEIM_DIGEST_TYPE_RFC2617_OR_RFC2831;
    } else {
	goto out;
    }

    context->serverQOP = values_find(&val, "qop");
    if (context->serverQOP == NULL)
	type = HEIM_DIGEST_TYPE_RFC2069;
    
    context->serverOpaque = values_find(&val, "opaque");

    if (context->type != HEIM_DIGEST_TYPE_AUTO && (context->type & type) == 0)
	goto out;
    else if (context->type == HEIM_DIGEST_TYPE_AUTO)
	context->type = type;

    ret = 0;
 out:
    free_values(val);
    if (ret)
	clear_context(context);
    return ret;
}
Exemple #10
0
static int dump_channels(const char *dev_dir_name)
{
	DIR *dp;
	const struct dirent *ent;

	dp = opendir(dev_dir_name);
	if (!dp)
		return -errno;

	while (ent = readdir(dp), ent)
		if (check_prefix(ent->d_name, "in_") &&
		    check_postfix(ent->d_name, "_raw"))
			printf("   %-10s\n", ent->d_name);

	return (closedir(dp) == -1) ? -errno : 0;
}
static int
read_union(avro_reader_t reader, const avro_encoding_t * enc,
	   avro_consumer_t *consumer, void *ud)
{
	int rval;
	int64_t discriminant;
	avro_consumer_t  *branch_consumer = NULL;
	void  *branch_ud = NULL;

	check_prefix(rval, enc->read_long(reader, &discriminant),
		     "Cannot read union discriminant: ");
	check(rval, avro_consumer_call(consumer, union_branch,
				       discriminant,
				       &branch_consumer, &branch_ud, ud));
	return avro_consume_binary(reader, branch_consumer, branch_ud);
}
Exemple #12
0
/*---------------------------------------------------------------------------*/
int
rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len)
{
  if(len > 128) {
    return 0;
  }

  memset(&dag->prefix_info.prefix, 0, sizeof(dag->prefix_info.prefix));
  memcpy(&dag->prefix_info.prefix, prefix, (len + 7) / 8);
  dag->prefix_info.length = len;
  dag->prefix_info.flags = UIP_ND6_RA_FLAG_AUTONOMOUS;
  PRINTF("RPL: Prefix set - will announce this in DIOs\n");
  /* Autoconfigure an address if this node does not already have an address
     with this prefix. */
  check_prefix(NULL, &dag->prefix_info);
  return 1;
}
Exemple #13
0
bool simulator_symext::is_spurious(
    const predicatest &predicates,
    const abstract_modelt &abstract_model,
    abstract_counterexamplet &abstract_counterexample,
    concrete_counterexamplet &concrete_counterexample,
    fail_infot &fail_info)
{
  status("Simulating abstract counterexample on concrete program");

#if 0
  std::cout << "***********************************" << std::endl;
  std::cout << abstract_counterexample << std::endl;
#endif

  if(path_slicing)
  {
#if 0 // buggy right now
    status("Path slicing");
    path_slicer(
        ns,
        abstract_model.goto_functions,
        abstract_counterexample);
#endif
  }

#if 0
  std::cout << "***********************************" << std::endl;
  std::cout << abstract_counterexample << std::endl;
  std::cout << "***********************************" << std::endl;
#endif

  if(!check_prefix(
        predicates,
        abstract_model,
        abstract_counterexample,
        concrete_counterexample,
        fail_info))
  {
    status("Simulation successful");
    return false;
  }

  return true;
}
Exemple #14
0
static art_leaf* recursive_delete(art_node *n, art_node **ref, const unsigned char *key, int key_len, int depth) {
    // Search terminated
    if (!n) return NULL;

    // Handle hitting a leaf node
    if (IS_LEAF(n)) {
        art_leaf *l = LEAF_RAW(n);
        if (!leaf_matches(l, key, key_len, depth)) {
            *ref = NULL;
            return l;
        }
        return NULL;
    }

    // Bail if the prefix does not match
    if (n->partial_len) {
        int prefix_len = check_prefix(n, key, key_len, depth);
        if (prefix_len != min(MAX_PREFIX_LEN, n->partial_len)) {
            return NULL;
        }
        depth = depth + n->partial_len;
    }

    // Find child node
    art_node **child = find_child(n, key[depth]);
    if (!child) return NULL;

    // If the child is leaf, delete from this node
    if (IS_LEAF(*child)) {
        art_leaf *l = LEAF_RAW(*child);
        if (!leaf_matches(l, key, key_len, depth)) {
            remove_child(n, ref, key[depth], child);
            return l;
        }
        return NULL;

    // Recurse
    } else {
        return recursive_delete(*child, child, key, key_len, depth+1);
    }
}
Exemple #15
0
/*---------------------------------------------------------------------------*/
void
rpl_free_dag(rpl_dag_t *dag)
{
  if(dag->joined) {
    PRINTF("RPL: Leaving the DAG ");
    PRINT6ADDR(&dag->dag_id);
    PRINTF("\n");
    dag->joined = 0;

    /* Remove routes installed by DAOs. */
    rpl_remove_routes(dag);

   /* Remove autoconfigured address */
    if((dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS)) {
      check_prefix(&dag->prefix_info, NULL);
    }

    remove_parents(dag, 0);
  }
  dag->used = 0;
}
gboolean
nms_keyfile_utils_should_ignore_file (const char *filename)
{
	gs_free char *base = NULL;

	g_return_val_if_fail (filename != NULL, TRUE);

	base = g_path_get_basename (filename);
	g_return_val_if_fail (base != NULL, TRUE);

	/* Ignore hidden and backup files */
	/* should_ignore_file() must mirror escape_filename() */
	if (check_prefix (base, ".") || check_suffix (base, "~"))
		return TRUE;
	/* Ignore temporary files */
	if (check_mkstemp_suffix (base))
		return TRUE;
	/* Ignore 802.1x certificates and keys */
	if (check_suffix (base, PEM_TAG) || check_suffix (base, DER_TAG))
		return TRUE;

	return FALSE;
}
Exemple #17
0
/*---------------------------------------------------------------------------*/
void
rpl_free_dag(rpl_dag_t *dag)
{
  if(dag->joined) {
    PRINTF("RPL: Leaving the DAG ");
    PRINT6ADDR(&dag->dag_id);
    PRINTF("\n");
    dag->joined = 0;

    /* Remove routes installed by DAOs. */
    rpl_remove_routes(dag);

/* TODO: Should probably be another option for PREFIX handling in RPL */
#if !CONF_6LOWPAN_ND
   /* Remove autoconfigured address */
    if((dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS)) {
      check_prefix(&dag->prefix_info, NULL);
    }
#endif /* !CONF_6LOWPAN_ND */

    remove_parents(dag, 0);
  }
  dag->used = 0;
}
char *
nms_keyfile_utils_escape_filename (const char *filename)
{
	GString *str;
	const char *f = filename;
	const char ESCAPE_CHAR = '*';

	/* keyfile used to escape with '*', do not change that behavior.
	 * But for newly added escapings, use '_' instead. */
	const char ESCAPE_CHAR2 = '_';

	g_return_val_if_fail (filename && filename[0], NULL);

	str = g_string_sized_new (60);

	/* Convert '/' to ESCAPE_CHAR */
	for (f = filename; f[0]; f++) {
		if (f[0] == '/')
			g_string_append_c (str, ESCAPE_CHAR);
		else
			g_string_append_c (str, f[0]);
	}

	/* escape_filename() must avoid anything that should_ignore_file() would reject.
	 * We can escape here more aggressivly then what we would read back. */
	if (check_prefix (str->str, "."))
		str->str[0] = ESCAPE_CHAR2;
	if (check_suffix (str->str, "~"))
		str->str[str->len - 1] = ESCAPE_CHAR2;
	if (   check_mkstemp_suffix (str->str)
	    || check_suffix (str->str, PEM_TAG)
	    || check_suffix (str->str, DER_TAG))
		g_string_append_c (str, ESCAPE_CHAR2);

	return g_string_free (str, FALSE);;
}
Exemple #19
0
/*---------------------------------------------------------------------------*/
void
rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
{
  rpl_instance_t *instance;
  rpl_dag_t *dag;
  rpl_parent_t *p;
  rpl_of_t *of;

  dag = rpl_alloc_dag(dio->instance_id, &dio->dag_id);
  if(dag == NULL) {
    PRINTF("RPL: Failed to allocate a DAG object!\n");
    return;
  }

  instance = dag->instance;

  p = rpl_add_parent(dag, dio, from);
  PRINTF("RPL: Adding ");
  PRINT6ADDR(from);
  PRINTF(" as a parent: ");
  if(p == NULL) {
    PRINTF("failed\n");
    instance->used = 0;
    return;
  }
  p->dtsn = dio->dtsn;
  PRINTF("succeeded\n");

  /* Determine the objective function by using the
     objective code point of the DIO. */
  of = rpl_find_of(dio->ocp);
  if(of == NULL) {
    PRINTF("RPL: DIO for DAG instance %u does not specify a supported OF\n",
        dio->instance_id);
    rpl_remove_parent(p);
    instance->used = 0;
    return;
  }

  /* Autoconfigure an address if this node does not already have an address
     with this prefix. */
  if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
    check_prefix(NULL, &dio->prefix_info);
  }

  dag->joined = 1;
  dag->preference = dio->preference;
  dag->grounded = dio->grounded;
  dag->version = dio->version;

  instance->of = of;
  instance->mop = dio->mop;
  instance->current_dag = dag;
  instance->dtsn_out = RPL_LOLLIPOP_INIT;

  instance->max_rankinc = dio->dag_max_rankinc;
  instance->min_hoprankinc = dio->dag_min_hoprankinc;
  instance->dio_intdoubl = dio->dag_intdoubl;
  instance->dio_intmin = dio->dag_intmin;
  instance->dio_intcurrent = instance->dio_intmin + instance->dio_intdoubl;
  instance->dio_redundancy = dio->dag_redund;
  instance->default_lifetime = dio->default_lifetime;
  instance->lifetime_unit = dio->lifetime_unit;

  memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id));

  /* Copy prefix information from the DIO into the DAG object. */
  memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));

  rpl_set_preferred_parent(dag, p);
  instance->of->update_metric_container(instance);
  dag->rank = instance->of->calculate_rank(p, 0);
  /* So far this is the lowest rank we are aware of. */
  dag->min_rank = dag->rank;

  if(default_instance == NULL) {
    default_instance = instance;
  }

  PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ",
         dio->instance_id, dag->rank);
  PRINT6ADDR(&dag->dag_id);
  PRINTF("\n");

  ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]);

  rpl_reset_dio_timer(instance);
  rpl_set_default_route(instance, from);

  if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES) {
    rpl_schedule_dao(instance);
  } else {
    PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n");
  }
}
Exemple #20
0
int main(int argc, char *argv[])
{
	int c;
	char *filename = NULL;
	char *outfile = NULL;
	FILE *fh;
	Stream *st;
	int config_checkprefix = 1;
	int config_basename = 0;
	int integrate_saturated = 0;
	IndexingMethod *indm;
	IndexingPrivate **ipriv;
	char *indm_str = NULL;
	char *cellfile = NULL;
	char *prefix = NULL;
	char *speaks = NULL;
	char *toler = NULL;
	int n_proc = 1;
	struct index_args iargs;
	char *intrad = NULL;
	char *pkrad = NULL;
	char *int_str = NULL;
	char *tempdir = NULL;
	char *int_diag = NULL;
	char *geom_filename = NULL;
	struct beam_params beam;
	int have_push_res = 0;

	/* Defaults */
	iargs.cell = NULL;
	iargs.noisefilter = 0;
	iargs.median_filter = 0;
	iargs.satcorr = 1;
	iargs.tols[0] = 5.0;
	iargs.tols[1] = 5.0;
	iargs.tols[2] = 5.0;
	iargs.tols[3] = 1.5;
	iargs.threshold = 800.0;
	iargs.min_gradient = 100000.0;
	iargs.min_snr = 5.0;
	iargs.check_hdf5_snr = 0;
	iargs.det = NULL;
	iargs.peaks = PEAK_ZAEF;
	iargs.beam = &beam;
	iargs.hdf5_peak_path = NULL;
	iargs.copyme = NULL;
	iargs.pk_inn = -1.0;
	iargs.pk_mid = -1.0;
	iargs.pk_out = -1.0;
	iargs.ir_inn = 4.0;
	iargs.ir_mid = 5.0;
	iargs.ir_out = 7.0;
	iargs.use_saturated = 1;
	iargs.no_revalidate = 0;
	iargs.stream_peaks = 1;
	iargs.stream_refls = 1;
	iargs.int_diag = INTDIAG_NONE;
	iargs.copyme = new_copy_hdf5_field_list();
	if ( iargs.copyme == NULL ) {
		ERROR("Couldn't allocate HDF5 field list.\n");
		return 1;
	}
	iargs.indm = NULL;  /* No default */
	iargs.ipriv = NULL;  /* No default */
	iargs.int_meth = integration_method("rings-nocen", NULL);
	iargs.push_res = 0.0;
	iargs.highres = +INFINITY;
	iargs.fix_profile_r = -1.0;
	iargs.fix_bandwidth = -1.0;
	iargs.fix_divergence = -1.0;

	/* Long options */
	const struct option longopts[] = {

		/* Options with long and short versions */
		{"help",               0, NULL,               'h'},
		{"version",            0, NULL,               'v'},
		{"input",              1, NULL,               'i'},
		{"output",             1, NULL,               'o'},
		{"indexing",           1, NULL,               'z'},
		{"geometry",           1, NULL,               'g'},
		{"pdb",                1, NULL,               'p'},
		{"prefix",             1, NULL,               'x'},
		{"threshold",          1, NULL,               't'},
		{"beam",               1, NULL,               'b'},

		/* Long-only options with no arguments */
		{"filter-noise",       0, &iargs.noisefilter,        1},
		{"no-check-prefix",    0, &config_checkprefix,       0},
		{"basename",           0, &config_basename,          1},
		{"no-peaks-in-stream", 0, &iargs.stream_peaks,       0},
		{"no-refls-in-stream", 0, &iargs.stream_refls,       0},
		{"integrate-saturated",0, &integrate_saturated,      1},
		{"no-use-saturated",   0, &iargs.use_saturated,      0},
		{"no-revalidate",      0, &iargs.no_revalidate,      1},
		{"check-hdf5-snr",     0, &iargs.check_hdf5_snr,     1},

		/* Long-only options which don't actually do anything */
		{"no-sat-corr",        0, &iargs.satcorr,            0},
		{"sat-corr",           0, &iargs.satcorr,            1},
		{"no-check-hdf5-snr",  0, &iargs.check_hdf5_snr,     0},
		{"use-saturated",      0, &iargs.use_saturated,      1},

		/* Long-only options with arguments */
		{"peaks",              1, NULL,                2},
		{"cell-reduction",     1, NULL,                3},
		{"min-gradient",       1, NULL,                4},
		{"record",             1, NULL,                5},
		{"cpus",               1, NULL,                6},
		{"cpugroup",           1, NULL,                7},
		{"cpuoffset",          1, NULL,                8},
		{"hdf5-peaks",         1, NULL,                9},
		{"copy-hdf5-field",    1, NULL,               10},
		{"min-snr",            1, NULL,               11},
		{"tolerance",          1, NULL,               13},
		{"int-radius",         1, NULL,               14},
		{"median-filter",      1, NULL,               15},
		{"integration",        1, NULL,               16},
		{"temp-dir",           1, NULL,               17},
		{"int-diag",           1, NULL,               18},
		{"push-res",           1, NULL,               19},
		{"res-push",           1, NULL,               19}, /* compat */
		{"peak-radius",        1, NULL,               20},
		{"highres",            1, NULL,               21},
		{"fix-profile-radius", 1, NULL,               22},
		{"fix-bandwidth",      1, NULL,               23},
		{"fix-divergence",     1, NULL,               24},

		{0, 0, NULL, 0}
	};

	/* Short options */
	while ((c = getopt_long(argc, argv, "hi:o:z:p:x:j:g:t:vb:",
	                        longopts, NULL)) != -1)
	{
		switch (c) {

			case 'h' :
			show_help(argv[0]);
			return 0;

			case 'v' :
			printf("CrystFEL: " CRYSTFEL_VERSIONSTRING "\n");
			printf(CRYSTFEL_BOILERPLATE"\n");
			return 0;

			case 'b' :
			ERROR("WARNING: This version of CrystFEL no longer "
			      "uses beam files.  Please remove the beam file "
			      "from your indexamajig command line.\n");
			return 1;

			case 'i' :
			filename = strdup(optarg);
			break;

			case 'o' :
			outfile = strdup(optarg);
			break;

			case 'z' :
			indm_str = strdup(optarg);
			break;

			case 'p' :
			cellfile = strdup(optarg);
			break;

			case 'x' :
			prefix = strdup(optarg);
			break;

			case 'j' :
			n_proc = atoi(optarg);
			break;

			case 'g' :
			geom_filename = optarg;
			break;

			case 't' :
			iargs.threshold = strtof(optarg, NULL);
			break;

			case 2 :
			speaks = strdup(optarg);
			break;

			case 3 :
			ERROR("The option '--cell-reduction' is no longer "
			      "used.\n"
			      "The complete indexing behaviour is now "
			      "controlled using '--indexing'.\n"
			      "See 'man indexamajig' for details of the "
			      "available methods.\n");
			return 1;

			case 4 :
			iargs.min_gradient = strtof(optarg, NULL);
			break;

			case 5 :
			ERROR("The option '--record' is no longer used.\n"
			      "Use '--no-peaks-in-stream' and"
			      "'--no-refls-in-stream' if you need to control"
			      "the contents of the stream.\n");
			return 1;

			case 6 :
			case 7 :
			case 8 :
			ERROR("The options --cpus, --cpugroup and --cpuoffset"
			      " are no longer used by indexamajig.\n");
			break;

			case 9 :
			free(iargs.hdf5_peak_path);
			iargs.hdf5_peak_path = strdup(optarg);
			break;

			case 10 :
			add_copy_hdf5_field(iargs.copyme, optarg);
			break;

			case 11 :
			iargs.min_snr = strtof(optarg, NULL);
			break;

			case 13 :
			toler = strdup(optarg);
			break;

			case 14 :
			intrad = strdup(optarg);
			break;

			case 15 :
			iargs.median_filter = atoi(optarg);
			break;

			case 16 :
			int_str = strdup(optarg);
			break;

			case 17 :
			tempdir = strdup(optarg);
			break;

			case 18 :
			int_diag = strdup(optarg);
			break;

			case 19 :
			if ( sscanf(optarg, "%f", &iargs.push_res) != 1 ) {
				ERROR("Invalid value for --push-res\n");
				return 1;
			}
			iargs.push_res *= 1e9;  /* nm^-1 -> m^-1 */
			have_push_res = 1;
			break;

			case 20 :
			pkrad = strdup(optarg);
			break;

			case 21 :
			if ( sscanf(optarg, "%f", &iargs.highres) != 1 ) {
				ERROR("Invalid value for --highres\n");
				return 1;
			}
			/* A -> m^-1 */
			iargs.highres = 1.0 / (iargs.highres/1e10);
			break;

			case 22 :
			if ( sscanf(optarg, "%f", &iargs.fix_profile_r) != 1 ) {
				ERROR("Invalid value for "
				      "--fix-profile-radius\n");
				return 1;
			}
			break;

			case 23 :
			if ( sscanf(optarg, "%f", &iargs.fix_bandwidth) != 1 ) {
				ERROR("Invalid value for --fix-bandwidth\n");
				return 1;
			}
			break;

			case 24 :
			if ( sscanf(optarg, "%f", &iargs.fix_divergence) != 1 ) {
				ERROR("Invalid value for --fix-divergence\n");
				return 1;
			}
			break;

			case 0 :
			break;

			case '?' :
			break;

			default :
			ERROR("Unhandled option '%c'\n", c);
			break;

		}

	}

	if ( tempdir == NULL ) {
		tempdir = strdup(".");
	}

	if ( filename == NULL ) {
		filename = strdup("-");
	}
	if ( strcmp(filename, "-") == 0 ) {
		fh = stdin;
	} else {
		fh = fopen(filename, "r");
	}
	if ( fh == NULL ) {
		ERROR("Failed to open input file '%s'\n", filename);
		return 1;
	}
	free(filename);

	if ( speaks == NULL ) {
		speaks = strdup("zaef");
		STATUS("You didn't specify a peak detection method.\n");
		STATUS("I'm using 'zaef' for you.\n");
	}
	if ( strcmp(speaks, "zaef") == 0 ) {
		iargs.peaks = PEAK_ZAEF;
	} else if ( strcmp(speaks, "hdf5") == 0 ) {
		iargs.peaks = PEAK_HDF5;
	} else if ( strcmp(speaks, "cxi") == 0 ) {
		iargs.peaks = PEAK_CXI;
	} else {
		ERROR("Unrecognised peak detection method '%s'\n", speaks);
		return 1;
	}
	free(speaks);

	/* Set default path for peaks, if appropriate */
	if ( iargs.hdf5_peak_path == NULL ) {
		if ( iargs.peaks == PEAK_HDF5 ) {
			iargs.hdf5_peak_path = strdup("/processing/hitfinder/peakinfo");
		} else if ( iargs.peaks == PEAK_CXI ) {
			iargs.hdf5_peak_path = strdup("/entry_1/result_1");
		}
	}

	if ( prefix == NULL ) {
		prefix = strdup("");
	} else {
		if ( config_checkprefix ) {
			prefix = check_prefix(prefix);
		}
	}

	if ( n_proc == 0 ) {
		ERROR("Invalid number of processes.\n");
		return 1;
	}

	iargs.det = get_detector_geometry(geom_filename, iargs.beam);
	if ( iargs.det == NULL ) {
		ERROR("Failed to read detector geometry from  '%s'\n",
		      geom_filename);
		return 1;
	}

	if ( indm_str == NULL ) {

		STATUS("You didn't specify an indexing method, so I  won't try "
		       " to index anything.\n"
		       "If that isn't what you wanted, re-run with"
		       " --indexing=<methods>.\n");
		indm = NULL;

	} else {

		indm = build_indexer_list(indm_str);
		if ( indm == NULL ) {
			ERROR("Invalid indexer list '%s'\n", indm_str);
			return 1;
		}
		free(indm_str);
	}

	if ( int_str != NULL ) {

		int err;

		iargs.int_meth = integration_method(int_str, &err);
		if ( err ) {
			ERROR("Invalid integration method '%s'\n", int_str);
			return 1;
		}
		free(int_str);
	}
	if ( integrate_saturated ) {
		/* Option provided for backwards compatibility */
		iargs.int_meth |= INTEGRATION_SATURATED;
	}

	if ( have_push_res && !(iargs.int_meth & INTEGRATION_RESCUT) ) {
		ERROR("WARNING: You used --push-res, but not -rescut, "
		      "therefore --push-res will have no effect.\n");
	}

	if ( toler != NULL ) {
		int ttt;
		ttt = sscanf(toler, "%f,%f,%f,%f",
		             &iargs.tols[0], &iargs.tols[1],
		             &iargs.tols[2], &iargs.tols[3]);
		if ( ttt != 4 ) {
			ERROR("Invalid parameters for '--tolerance'\n");
			return 1;
		}
		free(toler);
	}

	if ( intrad != NULL ) {
		int r;
		r = sscanf(intrad, "%f,%f,%f",
		           &iargs.ir_inn, &iargs.ir_mid, &iargs.ir_out);
		if ( r != 3 ) {
			ERROR("Invalid parameters for '--int-radius'\n");
			return 1;
		}
		free(intrad);
	} else {
		STATUS("WARNING: You did not specify --int-radius.\n");
		STATUS("WARNING: I will use the default values, which are"
		       " probably not appropriate for your patterns.\n");
	}

	if ( pkrad != NULL ) {
		int r;
		r = sscanf(pkrad, "%f,%f,%f",
		           &iargs.pk_inn, &iargs.pk_mid, &iargs.pk_out);
		if ( r != 3 ) {
			ERROR("Invalid parameters for '--peak-radius'\n");
			return 1;
		}
		free(pkrad);
	}

	if ( iargs.pk_inn < 0.0 ) {
		iargs.pk_inn = iargs.ir_inn;
		iargs.pk_mid = iargs.ir_mid;
		iargs.pk_out = iargs.ir_out;
	}

	if ( iargs.det == NULL ) {
		ERROR("You need to provide a geometry file (please read the"
		      " manual for more details).\n");
		return 1;
	}

	add_geom_beam_stuff_to_copy_hdf5(iargs.copyme, iargs.det, iargs.beam);

	if ( cellfile != NULL ) {
		iargs.cell = load_cell_from_file(cellfile);
		if ( iargs.cell == NULL ) {
			ERROR("Couldn't read unit cell (from %s)\n", cellfile);
			return 1;
		}
		free(cellfile);
		STATUS("This is what I understood your unit cell to be:\n");
		cell_print(iargs.cell);
	} else {
		STATUS("No unit cell given.\n");
		iargs.cell = NULL;
	}

	if ( int_diag != NULL ) {

		int r;
		signed int h, k, l;

		if ( strcmp(int_diag, "random") == 0 ) {
			iargs.int_diag = INTDIAG_RANDOM;
		}

		if ( strcmp(int_diag, "all") == 0 ) {
			iargs.int_diag = INTDIAG_ALL;
		}

		if ( strcmp(int_diag, "negative") == 0 ) {
			iargs.int_diag = INTDIAG_NEGATIVE;
		}

		if ( strcmp(int_diag, "implausible") == 0 ) {
			iargs.int_diag = INTDIAG_IMPLAUSIBLE;
		}

		if ( strcmp(int_diag, "strong") == 0 ) {
			iargs.int_diag = INTDIAG_STRONG;
		}

		r = sscanf(int_diag, "%i,%i,%i", &h, &k, &l);
		if ( r == 3 ) {
			iargs.int_diag = INTDIAG_INDICES;
			iargs.int_diag_h = h;
			iargs.int_diag_k = k;
			iargs.int_diag_l = l;
		}

		if ( (iargs.int_diag == INTDIAG_NONE)
		  && (strcmp(int_diag, "none") != 0) ) {
			ERROR("Invalid value for --int-diag.\n");
			return 1;
		}

		free(int_diag);

		if ( (n_proc > 1) && (iargs.int_diag != INTDIAG_NONE) ) {
			n_proc = 1;
			STATUS("Ignored \"-j\" because you used --int-diag.\n");
		}

	}

	st = open_stream_for_write_2(outfile, geom_filename, argc, argv);
	if ( st == NULL ) {
		ERROR("Failed to open stream '%s'\n", outfile);
		return 1;
	}
	free(outfile);

	/* Prepare the indexer */
	if ( indm != NULL ) {
		ipriv = prepare_indexing(indm, iargs.cell, iargs.det,
		                         iargs.tols);
		if ( ipriv == NULL ) {
			ERROR("Failed to prepare indexing.\n");
			return 1;
		}
	} else {
		ipriv = NULL;
	}

	gsl_set_error_handler_off();

	iargs.indm = indm;
	iargs.ipriv = ipriv;

	create_sandbox(&iargs, n_proc, prefix, config_basename, fh,
	               st, tempdir);

	free(prefix);
	free(tempdir);
	free_detector_geometry(iargs.det);
	close_stream(st);
	cleanup_indexing(indm, ipriv);

	return 0;
}
static struct gpiochip_info *list_gpiochip(const char *gpiochip_name, int *ret)
{
	struct gpiochip_info *cinfo;
	struct gpiochip_info *current;
	const struct dirent *ent;
	DIR *dp;
	char *chrdev_name;
	int fd;
	int i = 0;

	cinfo = calloc(sizeof(struct gpiochip_info) * 4, GC_NUM + 1);
	if (!cinfo)
		err(EXIT_FAILURE, "gpiochip_info allocation failed");

	current = cinfo;
	dp = opendir("/dev");
	if (!dp) {
		*ret = -errno;
		goto error_out;
	} else {
		*ret = 0;
	}

	while (ent = readdir(dp), ent) {
		if (check_prefix(ent->d_name, "gpiochip")) {
			*ret = asprintf(&chrdev_name, "/dev/%s", ent->d_name);
			if (*ret < 0)
				goto error_out;

			fd = open(chrdev_name, 0);
			if (fd == -1) {
				*ret = -errno;
				fprintf(stderr, "Failed to open %s\n",
					chrdev_name);
				goto error_close_dir;
			}
			*ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, current);
			if (*ret == -1) {
				perror("Failed to issue CHIPINFO IOCTL\n");
				goto error_close_dir;
			}
			close(fd);
			if (strcmp(current->label, gpiochip_name) == 0
			    || check_prefix(current->label, gpiochip_name)) {
				*ret = 0;
				current++;
				i++;
			}
		}
	}

	if ((!*ret && i == 0) || *ret < 0) {
		free(cinfo);
		cinfo = NULL;
	}
	if (!*ret && i > 0) {
		cinfo = realloc(cinfo, sizeof(struct gpiochip_info) * 4 * i);
		*ret = i;
	}

error_close_dir:
	closedir(dp);
error_out:
	if (*ret < 0)
		err(EXIT_FAILURE, "list gpiochip failed: %s", strerror(*ret));

	return cinfo;
}
Exemple #22
0
/*---------------------------------------------------------------------------*/
rpl_dag_t *
rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p)
{
  rpl_parent_t *last_parent;
  rpl_dag_t *dag, *end, *best_dag;
  rpl_rank_t old_rank;

  old_rank = instance->current_dag->rank;
  last_parent = instance->current_dag->preferred_parent;

  if(instance->current_dag->rank != ROOT_RANK(instance)) {
    rpl_select_parent(p->dag);
  }

  best_dag = NULL;
  for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) {
    if(dag->used && dag->preferred_parent != NULL && dag->preferred_parent->rank != INFINITE_RANK) {
      if(best_dag == NULL) {
        best_dag = dag;
      } else {
        best_dag = instance->of->best_dag(best_dag, dag);
      }
    }
  }

  if(best_dag == NULL) {
    /* No parent found: the calling function handle this problem. */
    return NULL;
  }

  if(instance->current_dag != best_dag) {
    /* Remove routes installed by DAOs. */
    rpl_remove_routes(instance->current_dag);

    PRINTF("RPL: New preferred DAG: ");
    PRINT6ADDR(&best_dag->dag_id);
    PRINTF("\n");

    if(best_dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
      check_prefix(&instance->current_dag->prefix_info, &best_dag->prefix_info);
    } else if(instance->current_dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
      check_prefix(&instance->current_dag->prefix_info, NULL);
    }

    best_dag->joined = 1;
    instance->current_dag->joined = 0;
    instance->current_dag = best_dag;
  }

  instance->of->update_metric_container(instance);
  /* Update the DAG rank. */
  best_dag->rank = instance->of->calculate_rank(best_dag->preferred_parent, 0);
  if(last_parent == NULL || best_dag->rank < best_dag->min_rank) {
    best_dag->min_rank = best_dag->rank;
  } else if(!acceptable_rank(best_dag, best_dag->rank)) {
    PRINTF("RPL: New rank unacceptable!\n");
    rpl_set_preferred_parent(instance->current_dag, NULL);
    if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES && last_parent != NULL) {
      /* Send a No-Path DAO to the removed preferred parent. */
      dao_output(last_parent, RPL_ZERO_LIFETIME);
    }
    return NULL;
  }

  if(best_dag->preferred_parent != last_parent) {
    rpl_set_default_route(instance, rpl_get_parent_ipaddr(best_dag->preferred_parent));
    PRINTF("RPL: Changed preferred parent, rank changed from %u to %u\n",
  	(unsigned)old_rank, best_dag->rank);
    RPL_STAT(rpl_stats.parent_switch++);
    if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES) {
      if(last_parent != NULL) {
        /* Send a No-Path DAO to the removed preferred parent. */
        dao_output(last_parent, RPL_ZERO_LIFETIME);
      }
      /* The DAO parent set changed - schedule a DAO transmission. */
      RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
      rpl_schedule_dao(instance);
    }
    rpl_reset_dio_timer(instance);
#if DEBUG
    rpl_print_neighbor_list();
#endif
  } else if(best_dag->rank != old_rank) {
    PRINTF("RPL: Preferred parent update, rank changed from %u to %u\n",
  	(unsigned)old_rank, best_dag->rank);
  }
  return best_dag;
}
int
avro_consume_binary(avro_reader_t reader, avro_consumer_t *consumer, void *ud)
{
	int rval;
	const avro_encoding_t *enc = &avro_binary_encoding;

	check_param(EINVAL, reader, "reader");
	check_param(EINVAL, consumer, "consumer");

	switch (avro_typeof(consumer->schema)) {
	case AVRO_NULL:
		check_prefix(rval, enc->read_null(reader),
			     "Cannot read null value: ");
		check(rval, avro_consumer_call(consumer, null_value, ud));
		break;

	case AVRO_BOOLEAN:
		{
			int8_t b;
			check_prefix(rval, enc->read_boolean(reader, &b),
				     "Cannot read boolean value: ");
			check(rval, avro_consumer_call(consumer, boolean_value, b, ud));
		}
		break;

	case AVRO_STRING:
		{
			int64_t len;
			char *s;
			check_prefix(rval, enc->read_string(reader, &s, &len),
				     "Cannot read string value: ");
			check(rval, avro_consumer_call(consumer, string_value, s, len, ud));
		}
		break;

	case AVRO_INT32:
		{
			int32_t i;
			check_prefix(rval, enc->read_int(reader, &i),
				    "Cannot read int value: ");
			check(rval, avro_consumer_call(consumer, int_value, i, ud));
		}
		break;

	case AVRO_INT64:
		{
			int64_t l;
			check_prefix(rval, enc->read_long(reader, &l),
				     "Cannot read long value: ");
			check(rval, avro_consumer_call(consumer, long_value, l, ud));
		}
		break;

	case AVRO_FLOAT:
		{
			float f;
			check_prefix(rval, enc->read_float(reader, &f),
				     "Cannot read float value: ");
			check(rval, avro_consumer_call(consumer, float_value, f, ud));
		}
		break;

	case AVRO_DOUBLE:
		{
			double d;
			check_prefix(rval, enc->read_double(reader, &d),
				     "Cannot read double value: ");
			check(rval, avro_consumer_call(consumer, double_value, d, ud));
		}
		break;

	case AVRO_BYTES:
		{
			char *bytes;
			int64_t len;
			check_prefix(rval, enc->read_bytes(reader, &bytes, &len),
				     "Cannot read bytes value: ");
			check(rval, avro_consumer_call(consumer, bytes_value, bytes, len, ud));
		}
		break;

	case AVRO_FIXED:
		{
			char *bytes;
			int64_t size =
			    avro_schema_to_fixed(consumer->schema)->size;

			bytes = avro_malloc(size);
			if (!bytes) {
				avro_prefix_error("Cannot allocate new fixed value");
				return ENOMEM;
			}
			rval = avro_read(reader, bytes, size);
			if (rval) {
				avro_prefix_error("Cannot read fixed value: ");
				avro_free(bytes, size);
				return rval;
			}

			rval = avro_consumer_call(consumer, fixed_value, bytes, size, ud);
			if (rval) {
				avro_free(bytes, size);
				return rval;
			}
		}
		break;

	case AVRO_ENUM:
		check(rval, read_enum(reader, enc, consumer, ud));
		break;

	case AVRO_ARRAY:
		check(rval, read_array(reader, enc, consumer, ud));
		break;

	case AVRO_MAP:
		check(rval, read_map(reader, enc, consumer, ud));
		break;

	case AVRO_UNION:
		check(rval, read_union(reader, enc, consumer, ud));
		break;

	case AVRO_RECORD:
		check(rval, read_record(reader, enc, consumer, ud));
		break;

	case AVRO_LINK:
		avro_set_error("Consumer can't consume a link schema directly");
		return EINVAL;
	}

	return 0;
}
int
heim_digest_parse_response(heim_digest_t context, const char *response)
{
    struct md5_value *val = NULL;
    char *nonce;
    int ret;

    response = check_prefix(context, response);

    ret = parse_values(response, &val);
    if (ret)
	goto out;

    ret = 1;

    if (context->type == HEIM_DIGEST_TYPE_AUTO) {
	goto out;
    } else if (context->type == HEIM_DIGEST_TYPE_RFC2617_OR_RFC2831) {
	context->clientURI = values_find(&val, "uri");
	if (context->clientURI) {
	    context->type = HEIM_DIGEST_TYPE_RFC2617_MD5_SESS;
	} else {
	    context->clientURI = values_find(&val, "digest-uri");
	    context->type = HEIM_DIGEST_TYPE_RFC2831;
	}
    } else if (context->type == HEIM_DIGEST_TYPE_RFC2831) {
	context->clientURI = values_find(&val, "digest-uri");
    } else {
	context->clientURI = values_find(&val, "uri");
    }

    if (context->clientURI == NULL)
        goto out;

    context->clientUsername = values_find(&val, "username");
    if (context->clientUsername == NULL) goto out;

    /* if client sent realm, make sure its the same of serverRealm if its set */
    context->clientRealm = values_find(&val, "realm");
    if (context->clientRealm && context->serverRealm && strcmp(context->clientRealm, context->serverRealm) != 0)
	goto out;
    
    context->clientResponse = values_find(&val, "response");
    if (context->clientResponse == NULL) goto out;

    nonce = values_find(&val, "nonce");
    if (nonce == NULL) goto out;

    if (strcmp(nonce, context->serverNonce) != 0) {
	free(nonce);
	goto out;
    }
    free(nonce);

    if (context->type != HEIM_DIGEST_TYPE_RFC2069) {

	context->clientQOP = values_find(&val, "qop");
	if (context->clientQOP == NULL) goto out;
	
	/*
	 * If we have serverQOP, lets check that clientQOP exists
	 * in the list of server entries.
	 */
	
	if (context->serverQOP) {
	    Boolean found = false;
	    char *b, *e;
	    size_t len, clen = strlen(context->clientQOP);
	    
	    b = context->serverQOP;
	    while (b && !found) {
		e = strchr(b, ',');
		if (e == NULL)
		    len = strlen(b);
		else {
		    len = e - b;
		    e += 1;
		}
		if (clen == len && strncmp(b, context->clientQOP, len) == 0)
		    found = true;
		b = e;
	    }
	    if (!found)
		goto out;
	}

	context->clientNC = values_find(&val, "nc");
	if (context->clientNC == NULL) goto out;

	context->clientNonce = values_find(&val, "cnonce");
	if (context->clientNonce == NULL) goto out;
    }

    set_auth_method(context);

    ret = 0;
 out:
    free_values(val);
    return ret;
}
Exemple #25
0
/*---------------------------------------------------------------------------*/
void
rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio)
{
  rpl_instance_t *instance;
  rpl_dag_t *dag;
  rpl_parent_t *p;
  rpl_of_t *of;
int tx;//elnaz

  dag = rpl_alloc_dag(dio->instance_id, &dio->dag_id);
  if(dag == NULL) {
//    PRINTF("RPL: Failed to allocate a DAG object!\n");
    return;
  }

  instance = dag->instance;

  p = rpl_add_parent(dag, dio, from);
//  PRINTF("RPL: Adding ");
//  PRINT6ADDR(from);
//  PRINTF(" as a parent: ");
  if(p == NULL) {
//    PRINTF("failed\n");
    instance->used = 0;
    return;
  }
  p->dtsn = dio->dtsn;
//  PRINTF("succeeded\n");

  /* Determine the objective function by using the
     objective code point of the DIO. */
  of = rpl_find_of(dio->ocp);
  if(of == NULL) {
//    PRINTF("RPL: DIO for DAG instance %u does not specify a supported OF\n",dio->instance_id);
    rpl_remove_parent(p);
    instance->used = 0;
    return;
  }

  /* Autoconfigure an address if this node does not already have an address
     with this prefix. */
  if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) {
    check_prefix(NULL, &dio->prefix_info);
  }


//-----------------elnaz
  tx =cc2420_get_txpower();
  printf("Power=%d \n",tx);
  switch(tx) {

  case 3:
  	dag->Tx = 0.003;
  	break;
  case 7:
  	dag->Tx = 0.03;
  	break;
  case 11:
  	dag->Tx = 0.1;
  	break;

  case 15:
  	dag->Tx = 0.2;
  	break;

  case 19:
  	dag->Tx = 0.3;
  	break;

  case 23:
  	dag->Tx = 0.5;
  	break;

  case 27:
  	dag->Tx = 0.8;
  	break;

  case 31:
  	dag->Tx = 1;

  }

  /*
      float mv = (bateria * 2.500 * 2) / 4096;
      printf("Battery: (%ld.%03d mV)\n", (long) mv, (unsigned) ((mv - floor(mv)) * 1000));
  */
  //printf("Test tx=%ld  ",(long) (dag->Tx*1000));

//----------------------elnaz


  dag->joined = 1;
  dag->preference = dio->preference;
  dag->grounded = dio->grounded;
  dag->version = dio->version;

  instance->of = of;
  instance->mop = dio->mop;
  instance->current_dag = dag;
  instance->dtsn_out = RPL_LOLLIPOP_INIT;

  instance->max_rankinc = dio->dag_max_rankinc;
  instance->min_hoprankinc = dio->dag_min_hoprankinc;
  instance->dio_intdoubl = dio->dag_intdoubl;
  instance->dio_intmin = dio->dag_intmin;
  instance->dio_intcurrent = instance->dio_intmin + instance->dio_intdoubl;
  instance->dio_redundancy = dio->dag_redund;
  instance->default_lifetime = dio->default_lifetime;
  instance->lifetime_unit = dio->lifetime_unit;

  memcpy(&dag->dag_id, &dio->dag_id, sizeof(dio->dag_id));

  /* Copy prefix information from the DIO into the DAG object. */
  memcpy(&dag->prefix_info, &dio->prefix_info, sizeof(rpl_prefix_t));

  rpl_set_preferred_parent(dag, p);
  instance->of->update_metric_container(instance);
  dag->rank = instance->of->calculate_rank(p, 0);
  /* So far this is the lowest rank we are aware of. */
  dag->min_rank = dag->rank;

  if(default_instance == NULL) {
    default_instance = instance;
  }

//  PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ", dio->instance_id, dag->rank);
//  PRINT6ADDR(&dag->dag_id);
//  PRINTF("\n");

  ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]);

  rpl_reset_dio_timer(instance);
  rpl_set_default_route(instance, from);

  if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES) {
    rpl_schedule_dao(instance);
  } else {
//    PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n");
  }
}
static void
  process_input_file(FILE *in, kd_message * &messages, const char *fname,
                     bool quiet)
{
  int num_errors = 0;
  int num_warnings = 0;
  int num_dev_errors = 0;
  int num_dev_warnings = 0;

  kd_string error_context;
  kd_string warning_context;
  kd_string error_lead_in;
  kd_string warning_lead_in;

  kd_message msg; // Temporary resource for building messages
  kd_string txt; // Temporary resource for assembling contents of KDU_TXT()
  kd_line line;
  int unmatched_braces = 0;
  bool in_txt = false; // If inside the `KDU_TXT' macro
  bool in_comment = false;
  while (line.read(in))
    {
      const char *cp;
      if (error_context.is_empty() &&
          ((cp=strstr(line.get(),"kdu_error _name(\"")) != NULL))
        error_context.add(strchr(cp,'\"'));
      else if (error_lead_in.is_empty() &&
               ((cp=strstr(line.get(),"kdu_error _name(\"")) != NULL))
        error_lead_in.add(strchr(cp,'\"'));
      else if (warning_context.is_empty() &&
               ((cp=strstr(line.get(),"kdu_warning _name(\"")) != NULL))
        warning_context.add(strchr(cp,'\"'));
      else if (warning_lead_in.is_empty() &&
               ((cp=strstr(line.get(),"kdu_warning _name(\"")) != NULL))
        warning_lead_in.add(strchr(cp,'\"'));

     cp = line.get();
     if (*cp == '#')
       continue;

     for (; *cp != '\0'; cp++)
       {
         if ((cp[0] == '/') && (cp[1] == '/'))
           break; // Rest of line is a comment
         if (in_comment)
           {
             if ((cp[0] == '*') && (cp[1] == '/'))
               { in_comment = false; cp++; }
             continue;
           }
         if ((cp[0] == '/') && (cp[1] == '*'))
           { in_comment = true; cp++; continue; }
         if (!msg.started())
           {
             kdu_uint32 id;
             if (check_prefix(cp,"KDU_ERROR("))
               {
                 cp += strlen("KDU_ERROR(");
                 if (read_id(cp,id) &&
                     !(error_context.is_empty() ||
                       error_lead_in.is_empty()))
                   {
                     msg.start(error_context,id,error_lead_in,false);
                     num_errors++;
                   }
               }
             else if (check_prefix(cp,"KDU_ERROR_DEV("))
               {
                 cp += strlen("KDU_ERROR_DEV(");
                 if (read_id(cp,id) &&
                     !(error_context.is_empty() ||
                       error_lead_in.is_empty()))
                   {
                     msg.start(error_context,id,error_lead_in,true);
                     num_errors++;  num_dev_errors++;
                   }
               }
             else if (check_prefix(cp,"KDU_WARNING("))
               {
                 cp += strlen("KDU_WARNING(");
                 if (read_id(cp,id) &&
                     !(warning_context.is_empty() ||
                       warning_lead_in.is_empty()))
                   {
                     msg.start(warning_context,id,warning_lead_in,false);
                     num_warnings++;
                   }
               }
             else if (check_prefix(cp,"KDU_WARNING_DEV("))
               {
                 cp += strlen("KDU_WARNING_DEV(");
                 if (read_id(cp,id) &&
                     !(warning_context.is_empty() ||
                       warning_lead_in.is_empty()))
                   {
                     msg.start(warning_context,id,warning_lead_in,true);
                     num_warnings++;  num_dev_warnings++;
                   }
               }
             assert((unmatched_braces == 0) && !in_txt);
             continue;
           }

         // If we get here, a message has been started
         if (!in_txt)
           {
             if (check_prefix(cp,"KDU_TXT("))
               {
                 cp += strlen("KDU_TXT");
                 in_txt = true;
               }
             else if (*cp == '{')
               unmatched_braces++;
             else if (*cp == '}')
               {
                 if (unmatched_braces > 0)
                   unmatched_braces--;
                 else
                   {
                     kd_message *new_msg = new kd_message;
                     msg.donate(new_msg);
                     assert(!msg.started());
                     insert_message(messages,new_msg,fname);
                   }
               }
             continue;
           }

         // If we get here, we are inside a `KDU_TXT' macro
         if (*cp == '\"')
           cp = txt.add(cp);
         else if (*cp == ')')
           {
             msg.add_text(txt);
             txt.clear();
             in_txt = false;
           }
       }
    }

  if (msg.started())
    { kdu_error e; e << "Encountered incomplete \"KDU_ERROR\", "
      "\"KDU_ERROR_DEV\", \"KDU_WARNING\" or \"KDU_WARNING_DEV\" environment "
      "while parsing source file \"" << fname << "\"."; }

  if (!quiet)
    {
      pretty_cout << ">> Parsed " << num_errors << " KDU_ERROR messages ("
                  << num_dev_errors << " for developers only)\n\tand "
                  << num_warnings << " KDU_WARNING messages ("
                  << num_dev_warnings << " for developers only)\n\tfrom \""
                  << fname << "\".\n";
      pretty_cout.flush();
    }
}
Exemple #27
0
static int dump_devices(void)
{
	const struct dirent *ent;
	int ret;
	DIR *dp;

	dp = opendir(iio_dir);
	if (!dp) {
		fprintf(stderr, "No industrial I/O devices available\n");
		return -ENODEV;
	}

	while (ent = readdir(dp), ent) {
		if (check_prefix(ent->d_name, type_device)) {
			char *dev_dir_name;

			if (asprintf(&dev_dir_name, "%s%s", iio_dir,
				     ent->d_name) < 0) {
				ret = -ENOMEM;
				goto error_close_dir;
			}

			ret = dump_one_device(dev_dir_name);
			if (ret) {
				free(dev_dir_name);
				goto error_close_dir;
			}

			free(dev_dir_name);
			if (verblevel >= VERBLEVEL_SENSORS)
				printf("\n");
		}
	}
	rewinddir(dp);
	while (ent = readdir(dp), ent) {
		if (check_prefix(ent->d_name, type_trigger)) {
			char *dev_dir_name;

			if (asprintf(&dev_dir_name, "%s%s", iio_dir,
				     ent->d_name) < 0) {
				ret = -ENOMEM;
				goto error_close_dir;
			}

			ret = dump_one_trigger(dev_dir_name);
			if (ret) {
				free(dev_dir_name);
				goto error_close_dir;
			}

			free(dev_dir_name);
		}
	}

	return (closedir(dp) == -1) ? -errno : 0;

error_close_dir:
	if (closedir(dp) == -1)
		perror("dump_devices(): Failed to close directory");

	return ret;
}
Exemple #28
0
int main(int argc, char** argv)
{
        std::cout << "\nsend_rpc_ra\n";
        std::cout << "\n(C) 2015 Alexander Holler\n\n";

	if (argc != 4) {
		std::cout << "Usage: " <<
			"send_rpc_ra interface destination_ipv6 prefix_ipv6\n" <<
			"Example: " <<
			"send_ra eth0 ff02::1 fecd::\n\n";
		return 1;
	}

	std::string interface(argv[1]);
	std::string destination(argv[2]);
	std::string prefix(argv[3]);

	struct {
		nd_router_advert nra;
		nd_opt_prefix_info opt_prefix_info;
	} my_ra;

	std::memset(&my_ra, 0, sizeof(my_ra));

	my_ra.nra.nd_ra_type = ND_ROUTER_ADVERT;

	msghdr msghdr;
	std::memset(&msghdr, 0, sizeof(msghdr));

	// destination address
	sockaddr_in6 dst;
	std::memset(&dst, 0, sizeof(dst));
	dst.sin6_family = AF_INET6;
	dst.sin6_port = htons(IPPROTO_ICMPV6);

	if (inet_pton(AF_INET6, destination.c_str(), &dst.sin6_addr) != 1) {
		std::cerr << "Error setting destination '" << destination << "'\n";
		return 2;
	}

	msghdr.msg_name = &dst;
	msghdr.msg_namelen = sizeof(dst);

	iovec iov[2];
	std::memset(&iov, 0, sizeof(iov));
	iov[0].iov_base = &my_ra;
	iov[0].iov_len = sizeof(my_ra);
	msghdr.msg_iov = (struct iovec *) &iov;
	msghdr.msg_iovlen = sizeof(iov) / sizeof(struct iovec);

	in6_pktinfo* ipi;
	cmsghdr* cmsg_hdr;
	uint8_t cmsgbuf[CMSG_SPACE(sizeof(int)) + CMSG_SPACE(sizeof(*ipi))];
	std::memset(&cmsgbuf, 0, sizeof(cmsgbuf));

	msghdr.msg_control = &cmsgbuf;
	msghdr.msg_controllen = sizeof(cmsgbuf);

	// hop limit
	cmsg_hdr = CMSG_FIRSTHDR(&msghdr);
	cmsg_hdr->cmsg_level = IPPROTO_IPV6;
	cmsg_hdr->cmsg_type = IPV6_HOPLIMIT;
	cmsg_hdr->cmsg_len = CMSG_LEN(sizeof(int));
	cmsgbuf[sizeof(*cmsg_hdr)] = 255; // using CMSG_DATA throws a warning

	// packet info
	cmsg_hdr = CMSG_NXTHDR(&msghdr, cmsg_hdr);
	cmsg_hdr->cmsg_level = IPPROTO_IPV6;
	cmsg_hdr->cmsg_type = IPV6_PKTINFO;
	cmsg_hdr->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
	ipi = (struct in6_pktinfo *) CMSG_DATA(cmsg_hdr);

	ipi->ipi6_ifindex = if_nametoindex(interface.c_str());
	if (!ipi->ipi6_ifindex) {
		std::cerr << "Interface '" << interface << "' not found!\n";
		return 3;
	}

	in6_addr s_addr;
	std::memset(&s_addr, 0, sizeof(s_addr));

	if (set_src_addr(interface, s_addr)) {
		std::cerr << "Error finding link-local address of interface '" << interface << "'!\n";
		return 4;
	}

	std::memcpy(&ipi->ipi6_addr, &s_addr, sizeof(ipi->ipi6_addr));
	msghdr.msg_iovlen = 1;

	my_ra.opt_prefix_info.nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
	my_ra.opt_prefix_info.nd_opt_pi_len = 4;
	if (inet_pton(AF_INET6, prefix.c_str(), &my_ra.opt_prefix_info.nd_opt_pi_prefix) != 1) {
		std::cerr << "Error converting prefix '" << prefix << "'!\n";
		return 5;
	}
	my_ra.opt_prefix_info.nd_opt_pi_prefix_len = 64;


	if (check_prefix(interface, my_ra.opt_prefix_info.nd_opt_pi_prefix)) {
		std::cerr << "Prefix " << prefix << " seems to be in use!\n";
		return 6;
	}
	my_ra.opt_prefix_info.nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_AUTO;
	my_ra.opt_prefix_info.nd_opt_pi_flags_reserved |= ND_OPT_PI_FLAG_RADDR;

	// Setting both lifetimes to 1 means the kernel will only delete the
	// link-local address without creating it before.
	my_ra.opt_prefix_info.nd_opt_pi_valid_time = htonl(1);
	my_ra.opt_prefix_info.nd_opt_pi_preferred_time = htonl(1);

	int sock = ::socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
	if (sock < 0) {
		std::cerr << "Error opening raw socket, are you root?\n";
		return 7;
	}
	if (::sendmsg(sock, &msghdr, 0) < 0) {
		::close(sock);
		std::cerr << "Error sending RA ( " << strerror(errno) << ")!\n";
		return 8;
	}
	::close(sock);

	std::cout << "Sent a Router Advertisment with prefix " <<
		prefix << " to " << destination << "\n";

	return 0;
}
Exemple #29
0
void
smtp (int fd)
{
  int state, c;
  char *buf = NULL;
  size_t size = 0;
  mu_mailbox_t mbox;
  mu_message_t msg;
  char *tempfile;
  char *rcpt_addr;
  
  in = fdopen (fd, "r");
  out = fdopen (fd, "w");
  SETVBUF (in, NULL, _IOLBF, 0);
  SETVBUF (out, NULL, _IOLBF, 0);

  smtp_reply (220, "Ready");
  for (state = STATE_INIT; state != STATE_QUIT; )
    {
      int argc;
      char **argv;
      int kw, len;
      
      if (getline (&buf, &size, in) == -1)
	exit (1);
      len = strlen (buf);
      while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r'))
	len --;
      buf[len] = 0;
      
      if (mu_argcv_get (buf, "", NULL, &argc, &argv))
	exit (1);

      kw = smtp_kw (argv[0]);
      if (kw == KW_QUIT)
	{
	  smtp_reply (221, "Done");
	  state = STATE_QUIT;
	  mu_argcv_free (argc, argv);
	  continue;
	}
      
      switch (state)
	{
	case STATE_INIT:
	  switch (kw)
	    {
	    case KW_EHLO:
	    case KW_HELO:
	      if (argc == 2)
		{
		  smtp_reply (250, "pleased to meet you");
		  state = STATE_EHLO;
		}
	      else
		smtp_reply (501, "%s requires domain address", argv[0]);
	      break;

	    default:
	      smtp_reply (503, "Polite people say HELO first");
	      break;
	    }
	  break;
	  
	case STATE_EHLO:
	  switch (kw)
	    {
	    case KW_MAIL:
	      if (argc == 2)
		from_person = check_prefix (argv[1], "from:");
	      else if (argc == 3 && mu_c_strcasecmp (argv[1], "from:") == 0)
		from_person = argv[2];
	      else
		from_person = NULL;

	      if (from_person)
		{
		  from_person = strdup (from_person);
		  smtp_reply (250, "Sender OK");
		  state = STATE_MAIL;
		}
	      else
		smtp_reply (501, "Syntax error");
	      break;

	    default:
	      smtp_reply (503, "Need MAIL command");
	    }
	  break;
	  
	case STATE_MAIL:
	  switch (kw)
	    {
	    case KW_RCPT:
	      if (argc == 2)
		rcpt_addr = check_prefix (argv[1], "to:");
	      else if (argc == 3 && mu_c_strcasecmp (argv[1], "to:") == 0)
		rcpt_addr = argv[2];
	      else
		rcpt_addr = NULL;
	      
	      if (rcpt_addr)
		{
		  if (add_recipient (rcpt_addr))
		    smtp_reply (451, "Recipient not accepted");
		  else
		    {
		      smtp_reply (250, "Recipient OK");
		      state = STATE_RCPT;
		    }
		}
	      else
		smtp_reply (501, "Syntax error");
	      break;
	      
	    default:
	      smtp_reply (503, "Need RCPT command");
	    }
	  break;
	  
	case STATE_RCPT:
	  switch (kw)
	    {
	    case KW_RCPT:
	      if (argc == 2)
		rcpt_addr = check_prefix (argv[1], "to:");
	      else if (argc == 3 && mu_c_strcasecmp (argv[1], "to:") == 0)
		rcpt_addr = argv[2];
	      else
		rcpt_addr = NULL;
	      
	      if (rcpt_addr)
		{
		  if (add_recipient (rcpt_addr))
		    smtp_reply (451, "Recipient not accepted");
		  else
		    {
		      smtp_reply (250, "Recipient OK");
		      state = STATE_RCPT;
		    }
		}
	      else
		smtp_reply (501, "Syntax error");
	      break;

	    case KW_DATA:
	      smtp_reply (354,
			  "Enter mail, end with \".\" on a line by itself");
	      make_tmp (in, from_person, &tempfile);
	      if ((c = mu_mailbox_create_default (&mbox, tempfile)) != 0)
		{
		  mu_error ("%s: can't create mailbox %s: %s",
			    progname,
			    tempfile, mu_strerror (c));
		  unlink (tempfile);
		  exit (1);
		}

	      if ((c = mu_mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
		{
		  mu_error ("%s: can't open mailbox %s: %s",
			    progname, 
			    tempfile, mu_strerror (c));
		  unlink (tempfile);
		  exit (1);
		}

	      mu_mailbox_get_message (mbox, 1, &msg);
	      if (message_finalize (msg, 0) == 0)
		mta_send (msg);
	      else
		smtp_reply (501, "can't send message"); /*FIXME: code?*/
	      unlink (tempfile);

	      mu_address_destroy (&recipients);
	      from_person = NULL;
	      
	      smtp_reply (250, "Message accepted for delivery");
	      state = STATE_EHLO;
	      break;

	    default:
	      smtp_reply (503, "Invalid command");
	      break;
	    }
	  break;

	}
      mu_argcv_free (argc, argv);
    }
    
  close (fd);
}