Exemplo n.º 1
0
static void test_10(void) {
	sSLList *l1,*l2;
	size_t oldFree;
	test_caseStart("Testing sll_clone");
	oldFree = heapspace();

	l1 = sll_create();
	sll_append(l1,(void*)4);
	sll_append(l1,(void*)3);
	sll_append(l1,(void*)2);
	l2 = sll_clone(l1);
	test_assertSize(sll_length(l2),3);
	test_assertPtr(sll_get(l2,0),(void*)4);
	test_assertPtr(sll_get(l2,1),(void*)3);
	test_assertPtr(sll_get(l2,2),(void*)2);
	sll_destroy(l1,false);
	sll_destroy(l2,false);

	l1 = sll_create();
	l2 = sll_clone(l1);
	test_assertSize(sll_length(l2),0);
	sll_destroy(l2,false);
	sll_destroy(l1,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 2
0
static void test_8(void) {
	sSLList *list;
	size_t oldFree;
	sSLNode *n;

	test_caseStart("Walking through the list");
	oldFree = heapspace();

	list = sll_create();
	sll_append(list,(void*)0x123);
	sll_append(list,(void*)0x456);
	sll_append(list,(void*)0x789);

	n = sll_begin(list);
	test_assertPtr(n->data,(void*)0x123);
	n = n->next;
	test_assertPtr(n->data,(void*)0x456);
	n = n->next;
	test_assertPtr(n->data,(void*)0x789);
	n = n->next;
	test_assertPtr(n,NULL);

	n = sll_nodeAt(list,2);
	test_assertPtr(n->data,(void*)0x789);
	n = n->next;
	test_assertPtr(n,NULL);

	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 3
0
static void test_9(void) {
	sSLList *list;
	size_t oldFree;

	test_caseStart("Testing sll_indexOf and sll_nodeWith");
	oldFree = heapspace();

	list = sll_create();
	sll_append(list,(void*)0x123);
	sll_append(list,(void*)0x456);
	sll_append(list,(void*)0x789);

	test_assertSSize(sll_indexOf(list,(void*)0x123),0);
	test_assertSSize(sll_indexOf(list,(void*)0x456),1);
	test_assertSSize(sll_indexOf(list,(void*)0x789),2);
	test_assertSSize(sll_indexOf(list,(void*)0x123123),-1);
	test_assertPtr(sll_nodeWith(list,(void*)0x123),sll_nodeAt(list,0));
	test_assertPtr(sll_nodeWith(list,(void*)0x456),sll_nodeAt(list,1));
	test_assertPtr(sll_nodeWith(list,(void*)0x789),sll_nodeAt(list,2));
	test_assertPtr(sll_nodeWith(list,(void*)0x123123),NULL);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 4
0
extern char *getTagId(char *tagname) {

  struct simpleLinkedList *vars, *rSet;
  char *sql2, *ret = NULL;
  char *sql = o_printf("SELECT tagid FROM tags WHERE tagname = '%s'", tagname);

  rSet = runquery_db(sql);
  if( rSet != NULL ) {
    ret = o_strdup(readData_db(rSet, "tagid"));
  }
  else {
    o_log(DEBUGM, "no tag was found. Adding a new one.");
    sql2 = o_strdup("INSERT INTO tags (tagname) VALUES (?)");

    vars = sll_init();
    sll_append(vars, DB_TEXT );
    sll_append(vars, tagname );

    runUpdate_db(sql2, vars);
    free(sql2);

    ret = itoa(last_insert(), 10);
  }
  free_recordset( rSet );
  free(sql);

  o_log(DEBUGM, "Using tagid of %s", ret);
  return ret;
}
Exemplo n.º 5
0
extern int updateDocValue (char *docid, char *kkey, char *vvalue) {

  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_TEXT );
  sll_append(vars, vvalue );
  sll_append(vars, DB_TEXT );
  sll_append(vars, docid );

  return doUpdateDocValue(kkey, vars);
}
Exemplo n.º 6
0
extern void removeDoc (char *docid) {
  char *sql = o_strdup("DELETE FROM docs WHERE docid = ?");
  int docid_i = atoi(docid);

  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_INT );
  sll_append(vars, &docid_i );

  runUpdate_db(sql, vars);
  free(sql);
}
Exemplo n.º 7
0
extern void deleteTag( char *tagid ) {
  char *sql = o_strdup("DELETE FROM tags WHERE tagid = ?");
  int tagid_i = atoi(tagid);

  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_INT );
  sll_append(vars, &tagid_i );

  runUpdate_db(sql, vars);
  free(sql);
}
Exemplo n.º 8
0
extern void addLocation(char *location, int role) {

  char *sql = o_strdup("INSERT INTO location_access (location, role) VALUES (?, ?);");
  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_TEXT );
  sll_append(vars, location );
  sll_append(vars, DB_INT );
  sll_append(vars, &role );

  runUpdate_db(sql, vars);
  free(sql);
}
Exemplo n.º 9
0
static int addRemoveTagOnDocument (char *sql, char *docid, char *tagid) {

  int rc;
  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_TEXT );
  sll_append(vars, docid );
  sll_append(vars, DB_TEXT );
  sll_append(vars, tagid );

  rc = runUpdate_db(sql, vars);
  free(sql);
  return rc;
}
Exemplo n.º 10
0
static void test_1(void) {
	ulong x = 0x100;
	size_t i,len,oldFree;
	bool res = true;
	sSLList *list;
	test_caseStart("Append & check & remove index 0");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 20; i++) {
		sll_append(list,(void*)x++);
	}
	x = 0x100;
	for(i = 0; i < 20; i++) {
		if(sll_get(list,i) != (void*)x++) {
			res = false;
			break;
		}
	}
	if(res) {
		for(i = 0; i < 20; i++) {
			sll_removeIndex(list,0);
		}
	}
	test_assertTrue(res);

	len = sll_length(list);
	test_assertSSize(len,0);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 11
0
static void test_6(void) {
	ulong x = 0x100;
	size_t i,oldFree;
	sSLList *list;
	bool res = true;
	test_caseStart("Create & append & set somewhere & destroy");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 5; i++) {
		sll_append(list,(void*)x++);
	}
	sll_set(list,(void*)0x200,3);
	if(sll_get(list,3) != (void*)0x200)
		res = false;
	sll_set(list,(void*)0x201,2);
	if(sll_get(list,2) != (void*)0x201)
		res = false;
	sll_set(list,(void*)0x202,1);
	if(sll_get(list,1) != (void*)0x202)
		res = false;
	sll_set(list,(void*)0x203,0);
	if(sll_get(list,0) != (void*)0x203)
		res = false;
	sll_set(list,(void*)0x204,4);
	if(sll_get(list,4) != (void*)0x204)
		res = false;
	if(sll_length(list) != 5)
		res = false;
	sll_destroy(list,false);
	test_assertTrue(res);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 12
0
void strBuf_joinAllStr(NStrBuf* strBuf)
{
    char* all;
    int len = 0, c = 0;
    NStrBufSeg* seg;
    
    if (strBuf->lst == N_NULL)
        return;
    
    seg = sll_first(strBuf->lst);
    while (seg) {
        len += seg->len;
        c++;
        seg = sll_next(strBuf->lst);
    }
    
    if (len == 0 || c == 1)
        return;
    
    all = (char*)NBK_malloc(len);
    len = 0;
    seg = sll_first(strBuf->lst);
    while (seg) {
        NBK_memcpy(all + len, seg->data, seg->len);
        len += seg->len;
        seg = sll_next(strBuf->lst);
    }
    strBuf_reset(strBuf);
    
    strBuf->lst = sll_create();
    seg = (NStrBufSeg*)NBK_malloc0(sizeof(NStrBufSeg));
    seg->data = all;
    seg->len = len;
    sll_append(strBuf->lst, seg);
}
Exemplo n.º 13
0
extern void addScanProgress (char *uuid) {

  char *sql = o_strdup("INSERT INTO scan_progress (client_id, status, value) VALUES (?, ?, 0);");

  int t1 = SCAN_IDLE;
  int *t = &t1;

  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_TEXT );
  sll_append(vars, uuid );
  sll_append(vars, DB_INT );
  sll_append(vars, t );

  runUpdate_db(sql, vars);
  free(sql);
}
Exemplo n.º 14
0
/**
 *
 * Check if there are pending CAC requests
 *
 * @param call_id request a cac for this call_id
 *       sessions  number of sessions in the request
 *        msg    ccapi msg, that is held to process
 *              till cac response is received.
 *
 * @return  CC_CAUSE_BW_OK if the bandwidth is received.
 *          CC_CAUSE_Ok Call returned successfully, not sure about BW yet
 *          CC_CAUSE_ERROR: Call returned with failure.
 *
 * @pre     (NULL)
 */
cc_causes_t
fsm_cac_call_bandwidth_req (callid_t call_id, uint32_t sessions,
                            void *msg)
{
    const char fname[] = "fsm_cac_call_bandwidth_req";
    cac_data_t *cac_data, *cac_pend_data;

    /* If wlan not connected return OK */
    cac_data = fsm_get_new_cac_data();

    if (cac_data == NULL) {

        return(CC_CAUSE_CONGESTION);
    }

    cac_data->msg_ptr = msg;
    cac_data->call_id = call_id;
    cac_data->cac_state = FSM_CAC_IDLE;
    cac_data->sessions = sessions;

    fsm_init_cac_failure_timer(cac_data, CAC_FAILURE_TIMEOUT);

    /* Make sure there is no pending requests before submitting
     * another one
     */
    if ((cac_pend_data = fsm_cac_check_if_pending_req()) == NULL) {

        /*
        * Make sure sufficient bandwidth available to make a outgoing call. This
        * should be done before allocating other resources.
        */
        DEF_DEBUG(DEB_F_PREFIX"CAC request for %d sessions %d.",
                DEB_F_PREFIX_ARGS("CAC", fname), call_id, sessions);

        if (fsm_cac_process_bw_allocation(cac_data) == CC_CAUSE_CONGESTION) {

            return(CC_CAUSE_CONGESTION);
        }

        cac_data->cac_state = FSM_CAC_REQ_PENDING;

    } else if (cac_pend_data->cac_state == FSM_CAC_IDLE) {

        if (fsm_cac_process_bw_allocation(cac_pend_data) ==
                    CC_CAUSE_CONGESTION) {

            /* Clear all remaining data */
            fsm_cac_clear_list();

            return(CC_CAUSE_CONGESTION);
        }

    }

    (void) sll_append(s_cac_list, cac_data);

    return(CC_CAUSE_OK);

}
Exemplo n.º 15
0
/**
 * This function will append presence notification to the pending queue.
 *
 * @param[in] event_data_p - pointer to event data.
 *
 * @return none.
 *
 * @pre (event_data_p != NULL)
 */
static void append_notification_to_pending_queue (ccsip_event_data_t *event_data_p)
{
    static const char fname[] = "append_notification_to_pending_queue";
    pres_pending_notify_t *pending_notify_p;
    Presence_ext_t *event_body_p = &(event_data_p->u.presence_rpid);

    /*
     * create pending list if it is not created yet.
     */
    if (s_pending_notify_list == NULL) {
        s_pending_notify_list = sll_create(NULL);
        if (s_pending_notify_list == NULL) {
            CSFLogError("src-common", "MSC: 0/0: %s: out of memory", fname);
            free_event_data(event_data_p);
            return;
        }
    }

    pending_notify_p = (pres_pending_notify_t *)sll_next(s_pending_notify_list, NULL);
    while (pending_notify_p != NULL) {
        if (strncmp(pending_notify_p->presentity, event_body_p->presence_body.entity,
                    CC_MAX_DIALSTRING_LEN - 1) == 0) {
            /* replace the current state with new state */
            free_event_data(pending_notify_p->event_data_p);
            pending_notify_p->event_data_p = event_data_p;
            return;
        }
        pending_notify_p = (pres_pending_notify_t *)sll_next(s_pending_notify_list,
                                                             pending_notify_p);
    }

    /*
     * To protect from DoS attacks, do not allow more than
     * MAX_REG_LINES entries in the list.
     */
    if (sll_count(s_pending_notify_list) == MAX_REG_LINES) {
        CSFLogError("src-common", "MSC: 0/0: %s: ignoring the NOTIFY "
            "to protect from DoS attack", fname);
        free_event_data(event_data_p);
        return;
    }
    pending_notify_p = (pres_pending_notify_t *)
                       cpr_malloc(sizeof(pres_pending_notify_t));
    if (pending_notify_p == NULL) {
        CSFLogError("src-common", "MSC: 0/0: %s: out of memory", fname);
        free_event_data(event_data_p);
        return;
    }
    sstrncpy(pending_notify_p->presentity, event_body_p->presence_body.entity,
             CC_MAX_DIALSTRING_LEN);
    pending_notify_p->event_data_p = event_data_p;
    (void) sll_append(s_pending_notify_list, pending_notify_p);
    return;
}
Exemplo n.º 16
0
void strBuf_appendStr(NStrBuf* strBuf, const char* str, int length)
{
    int len = (length == -1) ? nbk_strlen(str) : length;
    NStrBufSeg* seg = (NStrBufSeg*)NBK_malloc0(sizeof(NStrBufSeg));
    seg->len = len;
    seg->data = (char*)NBK_malloc(len);
    NBK_memcpy(seg->data, (void*)str, len);
    
    if (strBuf->lst == N_NULL)
        strBuf->lst = sll_create();
    sll_append(strBuf->lst, seg);
}
Exemplo n.º 17
0
/**
 * This function will append the application request in a pending list.
 *
 * @param[in] pcb_p -  pointer to a PCB.
 * @param[in] msg_p -  pointer to an application request.
 *
 * @return  TRUE if it is successful.
 *          Otherwise, FALSE is returned.
 *
 *  @pre    (pcb_p != NULL) and (msg_p != NULL)
 *  @post   ((slink_list_t *)s_pres_req_list->count++)
 */
static boolean append_pending_reqs (ccsip_publish_cb_t *pcb_p, pub_req_t *msg_p)
{
    pub_req_t *temp_msg_p;

    temp_msg_p = (pub_req_t *)cpr_malloc(sizeof(pub_req_t));
    if (temp_msg_p == NULL) {
        return FALSE;
    }
    (*temp_msg_p) = (*msg_p);
    (void) sll_append(pcb_p->pending_reqs, temp_msg_p);
    return TRUE;
}
Exemplo n.º 18
0
void update_config_option( char *option, char *value ) {
  char *sql = o_strdup("update config SET config_value = ? WHERE config_option = ?"); 
  struct simpleLinkedList *vars = sll_init();

	o_log(DEBUGM,"entering update_config_option\n");

  sll_append(vars, DB_TEXT );
  sll_append(vars, value );
  sll_append(vars, DB_TEXT );
  sll_append(vars, option );

  o_log(INFORMATION, "|Attempting to set config option '%s' to '%s'", option, value);
  if( runUpdate_db(sql, vars) ) {
    o_log(INFORMATION, "|    Failed!");
  }
  else {
    o_log(INFORMATION, "|    Successful.");
  }
  free(sql);
	o_log(DEBUGM,"leaving update_config_option\n");
}
Exemplo n.º 19
0
sSLList *sll_clone(const sSLList *list) {
	sSLNode *n;
	sSLList *l = sll_create();
	if(!l)
		return NULL;
	for(n = sll_begin(list); n != NULL; n = n->next) {
		if(!sll_append(l,n->data)) {
			sll_destroy(l,false);
			return NULL;
		}
	}
	return l;
}
Exemplo n.º 20
0
void
stress_test_sll(int amt)
{
	sll l1;
	sll l2;
	gendata x, y;
	int i;

	l1 = sll_create();
	l2 = sll_create();
	assert(sll_empty(l1));
	assert(sll_empty(l2));
	printf("Filling two slls with 2 * %d items...\n", amt);
	for (i = 0; i < amt; ++i) {
		x.num = i;
		l1 = sll_prepend_head(l1, x);
		l2 = sll_prepend_head(l2, x);
		assert(!sll_empty(l1));
		assert(!sll_empty(l2));
		l1 = sll_append_head(l1, x);
		l2 = sll_append_head(l2, x);
		assert(!sll_empty(l1));
		assert(!sll_empty(l2));
	}
	assert(sll_count(l1) == (unsigned int)(2 * amt));
	assert(sll_count(l2) == (unsigned int)(2 * amt));

	l1 = sll_append(l1, l2);
	assert(sll_count(l1) == (unsigned int)(4 * amt));

	/* From now on, l2 is `invalid' */

	printf("Removing 2 * 2 * %d items from the appended sll...\n", amt);
	for (i = 0; i < (2 * amt); ++i) {
		x = sll_get_data(sll_next(l1));
		assert(!sll_empty(l1));
		l1 = sll_remove_next(l1, NULL);
		y = sll_get_data(l1);
		assert(!sll_empty(l1));
		l1 = sll_remove_head(l1, NULL);

		/*
		 * We have to count backwards in this check, since we're
		 * using the list like a stack, prepending all the time.
		 */
		assert(x.num == amt - (i % amt) - 1);
		assert(x.num == y.num);
	}
	assert(sll_empty(l1));
	sll_destroy(l1, NULL);
}
Exemplo n.º 21
0
static void test_11(void) {
	sSLList *l1;
	size_t oldFree;
	test_caseStart("Testing sll_removeFirst");
	oldFree = heapspace();

	l1 = sll_create();
	sll_append(l1,(void*)4);
	sll_append(l1,(void*)3);
	sll_append(l1,(void*)2);
	test_assertSize(sll_length(l1),3);
	test_assertPtr(sll_removeFirst(l1),(void*)4);
	test_assertSize(sll_length(l1),2);
	test_assertPtr(sll_removeFirst(l1),(void*)3);
	test_assertSize(sll_length(l1),1);
	test_assertPtr(sll_removeFirst(l1),(void*)2);
	test_assertSize(sll_length(l1),0);
	test_assertPtr(sll_removeFirst(l1),NULL);
	sll_destroy(l1,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 22
0
static void test_4(void) {
	ulong x = 0x100;
	size_t i,oldFree;
	sSLList *list;
	test_caseStart("Create & append & destroy");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 200; i++) {
		sll_append(list,(void*)x++);
	}
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 23
0
/**
 * This function will create a PCB. It will also create the PCB linked list.
 *
 * @return  NULL if there are no resources to create a PCB.
 *          Otherwise,  pointer to a new PCB is returned.
 *
 *  @pre     (key != NULL) and (data != NULL)
 */
static ccsip_publish_cb_t *get_new_pcb (void)
{
    ccsip_publish_cb_t *pcb_p;

    /*
     * If PCB list is not created yet, create the list.
     */
    if (s_PCB_list == NULL) {
        s_PCB_list = sll_create(is_matching_pcb);
        if (s_PCB_list == NULL) {
            return NULL;
        }
    }

    pcb_p = (ccsip_publish_cb_t *)cpr_malloc(sizeof(ccsip_publish_cb_t));
    if (pcb_p == NULL) {
        return NULL;
    }
    memset(pcb_p, 0, sizeof(ccsip_publish_cb_t));
    pcb_p->pub_handle = generate_new_pub_handle();
    pcb_p->hb.cb_type = PUBLISH_CB;
    pcb_p->hb.dn_line = 1; // for now set it to primary line. This will change when we do line based PUBLISH.
    /*
     * set up dest & src ip addr and port number.
     */
    ccsip_common_util_set_dest_ipaddr_port(&pcb_p->hb);
    ccsip_common_util_set_src_ipaddr(&pcb_p->hb);
    pcb_p->hb.local_port = sipTransportGetListenPort(pcb_p->hb.dn_line, NULL);
    pcb_p->retry_timer.timer = cprCreateTimer("PUBLISH retry timer",
                                              SIP_PUBLISH_RETRY_TIMER,
                                              TIMER_EXPIRATION,
                                              sip_msgq);
    if (pcb_p->retry_timer.timer == NULL) {
        cpr_free(pcb_p);
        return NULL;
    }
    pcb_p->pending_reqs = sll_create(NULL);
    if (pcb_p->pending_reqs == NULL) {
        (void)cprDestroyTimer(pcb_p->retry_timer.timer);
        cpr_free(pcb_p);
        return NULL;
    }
    (void) sll_append(s_PCB_list, pcb_p);

    return pcb_p;
}
Exemplo n.º 24
0
/*
 * net_buffer_write
 * @fd: File descriptor.
 * @data: Buffer pointer needed to be written on this descriptor.
 * @nbytes: Number of bytes, should always be size of a pointer.
 * @return: Number of bytes written.
 * This function will write a networking buffer and queue it for further
 * processing.
 */
static int32_t net_buffer_write(void *fd, uint8_t *data, int32_t nbytes)
{
    NET_BUFFER_FS *net_buffer = (NET_BUFFER_FS *)fd;

    /* Unused parameter. */
    UNUSED_PARAM(nbytes);

    /* Caller already has the lock for net buffer data. */

    /* Push the buffer on the network buffer queue. */
    sll_append(&net_buffer->buffer_list, (FS_BUFFER *)data, OFFSETOF(FS_BUFFER, next));

    /* Tell the file system that there is some data available on this file descriptor. */
    fd_data_available(fd);

    /* Return the number of bytes. */
    return (sizeof(FS_BUFFER *));

} /* net_buffer_write */
Exemplo n.º 25
0
extern void updateNewScannedPage (int docid, char *ocrText, int page) {

  char *sql = o_strdup("UPDATE docs SET pages = ?, ocrText = ocrText || ? WHERE docid = ?");

  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_INT );
  sll_append(vars, &page );
  sll_append(vars, DB_TEXT );
  sll_append(vars, ocrText );
  sll_append(vars, DB_INT );
  sll_append(vars, &docid );

  runUpdate_db(sql, vars);
  free(sql);

}
Exemplo n.º 26
0
static void test_2(void) {
	ulong x = 0x100;
	size_t i,len,oldFree;
	sSLList *list;
	test_caseStart("Append & remove first (NULL)");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 2; i++) {
		sll_append(list,(void*)x++);
	}
	for(i = 0; i < 2; i++) {
		sll_removeFirstWith(list,NULL);
	}

	len = sll_length(list);
	test_assertSize(len,0);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
Exemplo n.º 27
0
/*
 * scheduler_task_add
 * @tcb: Task control block that is needed to be added in the system.
 * @priority: Priority for this task.
 * This function adds a task in the system, the task must be initialized before
 * adding.
 */
void scheduler_task_add(TASK *tcb, uint8_t priority)
{
    INT_LVL interrupt_level;

    /* Disable interrupts. */
    interrupt_level = GET_INTERRUPT_LEVEL();
    DISABLE_INTERRUPTS();

    /* Update the task control block. */
    tcb->priority = priority;

    /* Enqueue this task in the ready list. */
    scheduler_task_yield(tcb, YIELD_INIT);

#ifdef TASK_STATS
    /* Append this task to the global task list. */
    sll_append(&sch_task_list, tcb, OFFSETOF(TASK, next_global));
#endif /* TASK_STATS */

    /* Restore old interrupt level. */
    SET_INTERRUPT_LEVEL(interrupt_level);

} /* scheduler_task_add */
Exemplo n.º 28
0
extern void updateScanProgress (char *uuid, int status, int value) {

  char *progressUpdate = o_strdup("UPDATE scan_progress \
                                   SET status = ?, \
                                       value = ? \
                                   WHERE client_id = ? ");

  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_INT );
  sll_append(vars, &status );
  sll_append(vars, DB_INT );
  sll_append(vars, &value );
  sll_append(vars, DB_TEXT );
  sll_append(vars, uuid );

  runUpdate_db(progressUpdate, vars);
  free(progressUpdate);

}
Exemplo n.º 29
0
extern int setScanParam(char *uuid, int param, char *vvalue) {

  int rc;
  char *sql = o_strdup("INSERT OR REPLACE \
                        INTO scan_params \
                        (client_id, param_option, param_value) \
                        VALUES (?, ?, ?);");

  struct simpleLinkedList *vars = sll_init();
  sll_append(vars, DB_TEXT );
  sll_append(vars, uuid );
  sll_append(vars, DB_INT );
  sll_append(vars, &param );
  sll_append(vars, DB_TEXT );
  sll_append(vars, vvalue );

  rc = runUpdate_db(sql, vars);
  free(sql);

  return rc;
}
Exemplo n.º 30
0
/*
 *  Function: get_state()
 *
 *  Parameters: request_id - unique id assigned by the platform to this subscription. Platform
 *                           uses this to track the status updates and to make subsequent termination
 *                           request.
 *              duration - how long the subscription is requested to be valid.
 *              watcher - entity that is requesting the presence state.
 *              presentity - entity whose presence state is requested.
 *              app_id - application that is making the subscription.
 *                       0: indicates call list blf application.
 *                       1..n: indicates the speeddial/blf associated with (1..n)th line button.
 *              feature_mask - indicates the additional features enabled.
 *
 *  Description:  is invoked by platform side whenever it needs to susbcribe
 *                for presence state of a presentity. This stores the susbcription
 *                data in a linked list and posts SIPSPI_EV_CC_SUBSCRIBE
 *                to SIP stack. We need to store the subscription data so that
 *                SUBSCRIBE response and NOTIFYs can be mapped to subscriptions.
 *
 *  Returns: void
 */
static void
get_state (int request_id,
           int duration,
           const char *watcher,
           const char *presentity,
           int app_id,
           int feature_mask)
{
    static const char fname[] = "get_state";
    pres_subscription_req_t *sub_req_p;

    DEF_DEBUG(DEB_F_PREFIX"REQ %d: TM %d: WTR %s: PRT %s: FMSK %d: APP %d",
         DEB_F_PREFIX_ARGS(BLF_INFO, fname),
         request_id, duration, watcher, presentity, feature_mask, app_id);
    /*
     * if there is no subscription list yet, create one.
     */
    if (s_pres_req_list == NULL) {
        s_pres_req_list = sll_create(find_matching_node);
        if (s_pres_req_list == NULL) {
            /* let platform know that we can not continue */
            ui_BLF_notification(request_id, CC_SIP_BLF_REJECTED, app_id);
            BLF_ERROR(MISC_F_PREFIX"Exiting : request list creation failed", fname);
            return;
        }
    }
    /*
     * check if a request is already created by walking through the list. if not, create one.
     */
    if ((sub_req_p = (pres_subscription_req_t *)
                sll_find(s_pres_req_list, &request_id)) == NULL) {
        /*
         * populate subscription request and append it to the list.
         */
        sub_req_p = (pres_subscription_req_t *)
            cpr_malloc(sizeof(pres_subscription_req_t));
        if (sub_req_p == NULL) {
            BLF_ERROR(MISC_F_PREFIX"Exiting : malloc failed", fname);
            return;
        }

        sub_req_p->request_id = request_id;
        sub_req_p->sub_id = CCSIP_SUBS_INVALID_SUB_ID;
        sub_req_p->highest_cseq = 0;
        sub_req_p->duration = duration;
        sstrncpy(sub_req_p->presentity, presentity, CC_MAX_DIALSTRING_LEN);
        sstrncpy(sub_req_p->watcher, watcher, CC_MAX_DIALSTRING_LEN);
        sub_req_p->app_id = app_id;
        sub_req_p->feature_mask = feature_mask;
        sub_req_p->blf_state = CC_SIP_BLF_UNKNOWN;

        (void) sll_append(s_pres_req_list, sub_req_p);
    } else { /* already exists. just update the duration */
        sub_req_p->duration = duration;
    }

    /*
     * post SIPSPI_EV_CC_SUBSCRIBE to SIP stack
     */
    if (send_subscribe_ev_to_sip_task(sub_req_p) != CC_RC_SUCCESS) {
        /*
         * remove the node from the list of subscriptions.
         */
        free_sub_request(sub_req_p);
        /* let platform know that we can not continue */
        ui_BLF_notification(request_id, CC_SIP_BLF_REJECTED, app_id);
        BLF_ERROR(MISC_F_PREFIX"Exiting : Unable to send SUBSCRIBE", fname);
        return;
    }

    BLF_DEBUG(DEB_F_PREFIX"Exiting : request made successfully", DEB_F_PREFIX_ARGS(BLF, fname));
    return;
}