Esempio n. 1
0
static int imap_get_flags(mailmessage * msg_info,
			  struct mail_flags ** result)
{
  int r;
  struct mail_flags * flags;

  if (msg_info->msg_flags != NULL) {
    * result = msg_info->msg_flags;
    return MAIL_NO_ERROR;
  }

  flags = mail_flags_store_get(get_session_data(msg_info)->imap_flags_store,
			       msg_info->msg_index);

  if (flags == NULL) {
    r = imap_fetch_flags(get_imap_session(msg_info),
			 msg_info->msg_index, &flags);
    if (r != MAIL_NO_ERROR)
      return r;
  }

  msg_info->msg_flags = flags;

  * result = flags;

  return MAIL_NO_ERROR;
}
Esempio n. 2
0
static int prefetch(mailmessage * msg_info)
{
  struct generic_message_t * msg;
  int res;
  struct db_msg_data * data;
  struct db_session_state_data * sess_data;
  MMAPString * msg_content;
  struct mail_cache_db * maildb;
  int r;
  char key[PATH_MAX];
  void * msg_data;
  size_t msg_data_len;
  
  sess_data = get_session_data(msg_info);
  
  r = mail_cache_db_open_lock(sess_data->db_filename, &maildb);
  if (r < 0) {
    res = MAIL_ERROR_FILE;
    goto err;
  }
  
  snprintf(key, sizeof(key), "%lu", (unsigned long) msg_info->msg_index);
  r = mail_cache_db_get(maildb, key, strlen(key), &msg_data, &msg_data_len);
  if (r < 0) {
    res = MAIL_ERROR_MSG_NOT_FOUND;
    goto close_db;
  }
  
  msg_content = mmap_string_new_len(msg_data, msg_data_len);
  if (msg_content == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto close_db;
  }
  
  data = malloc(sizeof(* data));
  if (data == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto free_mmapstr;
  }
  
  data->msg_content = msg_content;
  
  msg = msg_info->msg_data;
  
  msg->msg_data = data;
  msg->msg_message = msg_content->str;
  msg->msg_length = msg_content->len;
  
  mail_cache_db_close_unlock(sess_data->db_filename, maildb);
  
  return MAIL_NO_ERROR;
  
 free_mmapstr:
  mmap_string_free(msg_content);
 close_db:
  mail_cache_db_close_unlock(sess_data->db_filename, maildb);
 err:
  return res;
}
Esempio n. 3
0
int v4l2_resume(void** session_data){
  fm_v4l2_data* session;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  return set_mute(session->fd, MUTE_OFF);
}
Esempio n. 4
0
int v4l2_mute(void** session_data, int mute){
  fm_v4l2_data* session;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  return set_mute(session->fd, mute);
}
Esempio n. 5
0
static void imap_check(mailmessage * msg_info)
{
  if (msg_info->msg_flags != NULL) {
    mail_flags_store_set(get_session_data(msg_info)->imap_flags_store,
        msg_info);
    /* ignore errors */
  }
}
Esempio n. 6
0
int v4l2_get_threshold (void ** session_data){
  fm_v4l2_data* session;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  return session->threshold;
 }
Esempio n. 7
0
int v4l2_pause(void** session_data){
  fm_v4l2_data* session;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  kill_rds_thread(session);
  return set_mute(session->fd, MUTE_ON);
}
Esempio n. 8
0
int v4l2_set_force_mono (void ** session_data, int force_mono){
  fm_v4l2_data* session;
  int ret;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  ret = set_force_mono(session->fd, &session->vt, force_mono);
  return ret;
}
Esempio n. 9
0
int v4l2_is_playing_in_stereo (void ** session_data){
    fm_v4l2_data* session;
    int ret;

    ALOGI("%s:\n", __FUNCTION__);
    session = get_session_data(session_data);

    ret = get_stereo(session->fd, &session->vt);
    return ret;
}
Esempio n. 10
0
int v4l2_stop_scan(void ** session_data){
  fm_v4l2_data* session;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);
  session->scan_band_run=SCAN_STOP;
  ALOGI("Stop scan value is %d\n", session->scan_band_run);

  return 1;
}
static void check(mailmessage * msg_info)
{
  int r;

  if (msg_info->msg_flags != NULL) {
    r = mail_flags_store_set(get_session_data(msg_info)->md_flags_store,
        msg_info);
    /* ignore errors */
  }
}
Esempio n. 12
0
int v4l2_get_signal_strength (void ** session_data){
    fm_v4l2_data* session;
    int ret;

    ALOGI("%s:\n", __FUNCTION__);
    session = get_session_data(session_data);

    ret = get_signal_strength(session->fd, &session->vt);
    return ret;
}
Esempio n. 13
0
int v4l2_is_rds_data_supported (void ** session_data){
  fm_v4l2_data* session;
  int ret;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  ret = get_RDS_cap(session->fd);
  return ret;
}
Esempio n. 14
0
int v4l2_is_tuned_to_valid_channel (void ** session_data){
  fm_v4l2_data* session;
  int signal;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  signal = get_signal_strength(session->fd, &session->vt);
  if ( signal > session->threshold )
    return 1;
  else
    return 0;
}
static int get_flags(mailmessage * msg_info,
    struct mail_flags ** result)
{
  chashdatum key;
  chashdatum value;
  struct maildir * md;
  struct mail_flags * flags;
  struct maildir_session_state_data * data;
  struct maildir_msg * md_msg;
  int r;
  uint32_t driver_flags;
  clist * ext;
  
  if (msg_info->msg_flags != NULL) {
    * result = msg_info->msg_flags;
    return MAIL_NO_ERROR;
  }
  
  data = get_session_data(msg_info);
  flags = mail_flags_store_get(data->md_flags_store,
      msg_info->msg_index);
  if (flags != NULL) {
    msg_info->msg_flags = flags;
    * result = msg_info->msg_flags;
    return MAIL_NO_ERROR;
  }
  
  md = get_maildir_session(msg_info);
  if (md == NULL)
    return MAIL_ERROR_BAD_STATE;
  
  key.data = msg_info->msg_uid;
  key.len = strlen(msg_info->msg_uid);
  r = chash_get(md->mdir_msg_hash, &key, &value);
  if (r < 0)
    return MAIL_ERROR_MSG_NOT_FOUND;
  
  md_msg = value.data;
  
  driver_flags = maildirdriver_maildir_flags_to_flags(md_msg->msg_flags);
  
  ext = clist_new();
  if (ext == NULL)
    return MAIL_ERROR_MEMORY;
  
  msg_info->msg_flags = mail_flags_new(driver_flags, ext);
  
  * result = msg_info->msg_flags;
  
  return MAIL_NO_ERROR;
}
Esempio n. 16
0
static int get_flags(mailmessage * msg_info,
    struct mail_flags ** result)
{
  char key[PATH_MAX];
  int r;
  struct db_session_state_data * sess_data;
  struct mail_cache_db * maildb;
  int res;
  MMAPString * mmapstr;
  
  sess_data = get_session_data(msg_info);
  
  r = mail_cache_db_open_lock(sess_data->db_filename, &maildb);
  if (r < 0) {
    res = MAIL_ERROR_FILE;
    goto err;
  }
  
  snprintf(key, sizeof(key), "%lu-flags", (unsigned long) msg_info->msg_index);
  
  mmapstr = mmap_string_new("");
  if (mmapstr == NULL) {
    res = MAIL_ERROR_MEMORY;
    goto close_db;
  }
  
  r = generic_cache_flags_read(maildb, mmapstr,
    key, &msg_info->msg_flags);
  
  mmap_string_free(mmapstr);
  
  if (r != MAIL_NO_ERROR) {
    msg_info->msg_flags = mail_flags_new_empty();
    if (msg_info->msg_flags == NULL) {
      res = MAIL_ERROR_MEMORY;
      goto close_db;
    }
  }
  
  mail_cache_db_close_unlock(sess_data->db_filename, maildb);
  
  * result = msg_info->msg_flags;
  
  return MAIL_NO_ERROR;
  
 close_db:
  mail_cache_db_close_unlock(sess_data->db_filename, maildb);
 err:
  return res;
}
Esempio n. 17
0
int v4l2_set_frequency(void** session_data, int frequency){
  fm_v4l2_data* session;
  int ret;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  session->freq = get_proprietary_freq( frequency, session->fact);
  ret= set_freq(session->fd,  session->freq);
  if (ret < 0)
      return -1;

  return frequency;
}
Esempio n. 18
0
int v4l2_get_frequency (void ** session_data){
  fm_v4l2_data* session;
  int ret;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  ret = get_freq(session->fd);
  if (ret < 0)
      return -1;

  session->freq = get_standard_freq(ret, session->fact);

  return session->freq;
}
Esempio n. 19
0
int v4l2_scan (void ** session_data, enum fmradio_seek_direction_t direction){
   fm_v4l2_data* session;
   int increment, rate, freqi, ret;

   ALOGI("%s:\n", __FUNCTION__);
   session = get_session_data(session_data);

   session->scan_band_run=SCAN_RUN;
   if (direction==FMRADIO_SEEK_DOWN)
     increment = -  session->grid;
   else                                      //FMRADIO_SEEK_UP
     increment =  session->grid;

  freqi = session->freq + increment;         //drop the current frequency
  ALOGI("Starting scanning...\n");
  while (session->scan_band_run==SCAN_RUN){

      ret= set_freq(session->fd, freqi);
      if (ret<0)
          return -1;

      usleep(LOCKTIME);                       // let it lock on
      rate= get_signal_strength( session->fd,  &session->vt);
      if (rate < 0)
         return -1;

      ALOGI("final rate %d > %d \n", rate , session->threshold);

      if (rate >  session->threshold){
      ALOGI("Found freq, %d\n", freqi);
      session->scan_band_run=SCAN_STOP;
      session->freq = freqi;
      return get_standard_freq(freqi, session->fact);
      }

      freqi +=  increment;
      if ( freqi >  session->high_freq)
         freqi =  session->low_freq;
      if ( freqi <  session->low_freq)
          freqi =  session->high_freq;
  }
  ALOGI("End scan\n");
  return 0;
}
Esempio n. 20
0
int v4l2_reset(void** session_data)
{
  fm_v4l2_data* session;
  int ret;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  ret = set_mute(session->fd, MUTE_ON);
  if (ret < 0)
    return -1;

  ret = close(session->fd);
  if (ret < 0)
    return -1;

  free(session);
  return 0;
}
Esempio n. 21
0
int v4l2_get_rds(void * * session_data, struct fmradio_rds_bundle_t * fmradio_rds_bundle) {
  int ret = 1;
  int bytesNum, i, j, blocknum, last_block_num, next_expected_block, group_status, group_type;
  char * buf, * group;
  char b0, b1, b2, b1_l5;

  int index;
  fm_v4l2_data * session = get_session_data(session_data);

  buf = malloc(sizeof(char) * BUFFER_RDS_SIZE);
  group = malloc(sizeof(char) * GROUP_SIZE);
  CLEAN_RDS

  bytesNum = read(session -> fd, buf, BUFFER_RDS_SIZE);
  if (bytesNum == -1 && errno == EINTR) {
    ALOGE("Error on RDS read\n");
    ret = 2;
  }


  if (bytesNum > 0) {
    ALOGI("read num bytes %d\n", bytesNum); //assuming to have always multiple of 3

    for (i = 0; i < bytesNum; i += 3) {
      b0 = buf[i];
      b1 = buf[i + 1];
      b2 = buf[i + 2];

      if ((b2 & 0x80) != 0) {
        CLEAN_RDS
        continue;
      }

      blocknum = b2 & 0x07; // What's the differnce between "Received Offset"

      if (blocknum == 4) blocknum = 2; // Treat C' as C
      if ((blocknum == 5) || (blocknum == 6)) continue; // ignore E Blocks

      if (blocknum == 7) { //invalid block
        CLEAN_RDS
        continue;
      }
Esempio n. 22
0
static inline mailimap * get_imap_session(mailmessage * msg)
{
  return get_session_data(msg)->imap_session;
}
static struct maildir * get_maildir_session(mailmessage * msg)
{
  return get_session_data(msg)->md_session;
}
Esempio n. 24
0
int v4l2_full_scan (void ** session_data, int ** found_freqs, int ** signal_strenghts){
  fm_v4l2_data* session;
  int founded, i, ret;
  int freqi, rate;
  int *temp_freq, *temp_strenght;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  session->scan_band_run=SCAN_RUN;

  temp_freq = (int *) malloc(sizeof(int) *MAX_FREQS);
  temp_strenght = (int *) malloc(sizeof(int) *MAX_FREQS);
  if (temp_freq == NULL || temp_strenght==NULL){
    ALOGE("error on allocate");
    return -1;
  }

  ALOGI("Starting full scanning...low freq:%d, high freq:%d\n", session->low_freq, session->high_freq);

  for (freqi =  session->low_freq, founded=0 ; ((freqi < session->high_freq)  && (founded < MAX_FREQS) && (session->scan_band_run==SCAN_RUN)) ; freqi += session->grid){

      ret = set_freq(session->fd, freqi);
      if (ret<0)
         return -1;

      usleep(LOCKTIME);		/* let it lock on */
      rate= get_signal_strength(session->fd, &session->vt);
      if (rate < 0)
          return -1;

      ALOGI("final rate %d > %d \n", rate ,session->threshold);

      if (rate > session->threshold){
          ALOGI("Founded index %d, freq %d\n", founded, freqi);
          temp_freq[founded]= freqi;
          temp_strenght[founded]= rate;
          founded++;
      }
  }

  *found_freqs = (int *) malloc(sizeof(int) * founded);
  *signal_strenghts = (int *) malloc(sizeof(int) * founded);
  if (*found_freqs == NULL || *signal_strenghts==NULL){
    ALOGE("error on allocate");
    return -1;
  }

  //copy founded frequencies
  for (i=0; i<founded; i++){
      (*found_freqs)[i] = get_standard_freq(temp_freq[i], session->fact);
      (*signal_strenghts)[i] = temp_strenght[i];
      ALOGI("Copied index %d, freq %d, signal %d\n",i, (*found_freqs)[i], (*signal_strenghts)[i] );
  }

  ALOGI("End full scan\n");
  free(temp_freq);
  free(temp_strenght);
  session->scan_band_run=SCAN_STOP;

  return i;
}