Example #1
0
/**
 * 获取关注和拉黑某人的用户列表
 * @param[in] uid 要查询的用户ID
 * @param[out] followers 关注该用户的用户列表
 * @param[out] blacklisters 拉黑该用户的用户列表
 */
void friend_load_followers_and_blacklisters(user_id_t uid,
		friend_uid_list_t **followers, friend_uid_list_t **blacklisters)
{
	if (!followers || !blacklisters)
		return;

	query_t *q = query_new(0);
	query_select(q, "follower");
	query_from(q, "follows");
	query_where(q, "user_id = %"DBIdUID, uid);
	*followers = query_exec(q);

	q = query_new(0);
	query_select(q, "user_id");
	query_from(q, "blacklists");
	query_where(q, "blocked = %"DBIdUID, uid);
	*blacklisters = query_exec(q);
}
Example #2
0
/*
{
	groups: [
		{
			name: OPTIONAL TEXT,
			descr: OPTIONAL TEXT,
			boards: [
				{ id: INTEGER, name: TEXT, unread: OPTIONAL BOOLEAN },
				...
			]
		},
		...
	]
}
*/
int api_board_fav(void)
{
	if (!session_id())
		return WEB_ERROR_LOGIN_REQUIRED;

	xml_node_t *root = set_response_root("bbs-board-fav",
			XML_NODE_ANONYMOUS_JSON, XML_ENCODING_UTF8);
	xml_node_t *groups = xml_new_node("groups", XML_NODE_CHILD_ARRAY);
	xml_add_child(root, groups);

	query_t *q = query_new(0);
	query_select(q, "board, name, folder");
	query_from(q, "fav_boards");
	query_where(q, "user_id = %"DBIdUID, session_uid());
	db_res_t *boards = query_exec(q);

	q = query_new(0);
	query_select(q, "id, name, descr");
	query_from(q, "fav_board_folders");
	query_where(q, "user_id = %"DBIdUID, session_uid());
	db_res_t *folders = query_exec(q);

	if (folders && boards) {
		attach_group(groups, boards, FAV_BOARD_ROOT_FOLDER);
		for (int i = db_res_rows(folders) - 1; i >= 0; --i) {
			int id = db_get_integer(folders, i, 0);
			xml_node_t *group = attach_group(groups, boards, id);
			xml_attr_string(group, "name", db_get_value(folders, i, 1), true);
			xml_attr_string(group, "descr", db_get_value(folders, i, 2), true);
		}
	}

	db_clear(folders);
	db_clear(boards);
	return WEB_OK;
}
Example #3
0
File: engine.c Project: fizx/sit
void
_each_query(Callback *cb, void *vnode) {
	QueryNode *node = vnode;
  Callback *user_callback = cb->user_data;
	
	Callback *qc = node->callback;
  Term **terms = NULL;
	int term_count = 0;
	while(qc) {
		if (terms == NULL) {
			terms = _get_terms(node, &term_count);
		}
    conjunction_t *cjs[1];
    cjs[0] = conjunction_new(terms, term_count);
		Query *query = query_new(cjs, 1, qc);
		user_callback->handler(user_callback, query);
		qc = qc->next;
	}
}
Example #4
0
xc_result_t
xCOM_QueryInterface (
   xc_handle_t componentHandle,
   const char *interfaceName,
   unsigned int interfaceMajorVersion,
   unsigned int interfaceMinorVersion,
   const char *queriedComponentName,
   const char *queriedPortName,
   unsigned int queryFlags,
   xc_handle_t *queryHandlePtr,
   unsigned int *matchCountPtr
) {

   xc_result_t result;

   TRACE3 ((
      "called with componentHandle=%u, interfaceName='%s', interfaceMajorVersion=%u, "
      "interfaceMinorVersion=%u, queriedComponentName='%s', queriedPortName='%s', "
      "queryFlags=0x%x, queryHandlePtr=%p, matchCountPtr=%p", componentHandle,
      interfaceName, interfaceMajorVersion, interfaceMinorVersion, queriedComponentName,
      queriedPortName, queryFlags, queryHandlePtr, matchCountPtr
   ));

   if (componentHandle == XC_INVALID_HANDLE) {
      componentHandle = component_get_anonymous ();
   }

   if ((componentHandle == XC_INVALID_HANDLE) ||
       (interfaceName == NULL) ||
       (queryHandlePtr == NULL)) {
      TRACE1 (("called with invalid parameters!"));
      result = XC_ERR_INVAL;
   }
   else {
      result = query_new (
         componentHandle, NULL, interfaceName, interfaceMajorVersion, interfaceMinorVersion,
         queriedComponentName, queriedPortName, queryFlags, queryHandlePtr, matchCountPtr
      );
   }

   TRACE3 (("exiting with result=%d", result));
   return result;
}
Example #5
0
void ape_gethostbyname(char *name, void (*callback)(char *, void *, acetables *), void *data, acetables *g_ape)
{
   
    struct in_addr addr;
	struct query *q;
    unsigned char dn[DNS_MAXDN];
	int abs = 0;
	enum dns_type l_qtyp = 0;

    if (dns_pton(AF_INET, name, &addr) > 0) {
		/* We have an IP */
		callback(xstrdup(name), data, g_ape);
		return;
    } else if (!dns_ptodn(name, strlen(name), dn, sizeof(dn), &abs)) {
		/* We have an invalid domain name */
		return;
	} else {
		l_qtyp = DNS_T_A;
	}
	
	q = query_new(name, dn, l_qtyp);
	
	q->data = data;
	q->callback = callback;
	q->g_ape = g_ape;
	
	if (abs) {
		abs = DNS_NOSRCH;
	}
    if (!dns_submit_dn(NULL, dn, qcls, l_qtyp, abs, 0, dnscb, q)) {
		query_free(q);
		return;
	}
	
	dns_timeouts(NULL, -1, 0);
}
int main(int argc, char *argv[])
{
	struct query_keyword keyword;
	struct query         qry;
	struct indices       indices;
	int                  opt;
	char                *index_path = NULL;

	/* initialize text segmentation module */
	text_segment_init("../jieba/fork/dict");

	/* a single new query */
	qry = query_new();

	while ((opt = getopt(argc, argv, "hp:t:m:x:")) != -1) {
		switch (opt) {
		case 'h':
			printf("DESCRIPTION:\n");
			printf("testcase of search function.\n");
			printf("\n");
			printf("USAGE:\n");
			printf("%s -h |"
			       " -p <index path> |"
			       " -t <term> |"
			       " -m <tex> |"
			       " -x <text>"
			       "\n", argv[0]);
			printf("\n");
			goto exit;

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

		case 't':
			keyword.type = QUERY_KEYWORD_TERM;
			wstr_copy(keyword.wstr, mbstr2wstr(optarg));
			query_push_keyword(&qry, &keyword);
			break;

		case 'm':
			keyword.type = QUERY_KEYWORD_TEX;
			keyword.pos = 0; /* do not care for now */
			wstr_copy(keyword.wstr, mbstr2wstr(optarg));
			query_push_keyword(&qry, &keyword);
			break;

		case 'x':
			query_digest_utf8txt(&qry, optarg);
			break;

		default:
			printf("bad argument(s). \n");
			goto exit;
		}
	}

	/*
	 * check program arguments.
	 */
	if (index_path == NULL || qry.len == 0) {
		printf("not enough arguments.\n");
		goto exit;
	}

	/*
	 * print program arguments.
	 */
	printf("index path: %s\n", index_path);
	query_print_to(qry, stdout);

	/*
	 * open indices
	 */
	printf("opening index...\n");
	indices = indices_open(index_path);
	if (indices.open_err) {
		printf("index open failed.\n");
		goto close;
	}

	/* setup cache */
	indices_cache(&indices, 32 MB);

	/* search query */
	indices_run_query(&indices, qry);

close:
	/*
	 * close indices
	 */
	printf("closing index...\n");
	indices_close(&indices);

exit:
	/*
	 * free program arguments
	 */
	if (index_path)
		free(index_path);

	/*
	 * free other program modules
	 */
	query_delete(qry);
	text_segment_free();
	return 0;
}
Example #7
0
query_t *query_albums_new()
{
  query_t *query = query_new();
  query->format = &album_query;
  return query;
}
Example #8
0
query_t *query_artists_new()
{
  query_t *query = query_new();
  query->format = &artist_query;
  return query;
}
Example #9
0
query_t *query_tracks_new()
{
  query_t *query = query_new();
  query->format = &track_query;
  return query;
}
Example #10
0
TF EXPFUNC p_db_query(ENGid eid)
/* db_query/5
   ex.
   db_query(HConnect, PQuery,
      $select mother, father from person where name = ?$,
      ['Someones Name'],
      [string, string]). */
{
   HSTMT   hstmt;
   HDBC    hdbc;
   char*   sQ = NULL;
   int     iParm = 1;
   int     iCol = 1;
   TERM    tParms, tCols;
   char*   sBuf = NULL;
   char    sType[80];
   TERM    t;
   pTYPE   ptyp;
   QUERY*  pq;
   char*   s;
   long    len;
   long*   pl;
   float*  pf;
   double* pd;
   long    i;
   //float   f;
   double  g;
   DATE_STRUCT* pdate;
   TIME_STRUCT* ptime;
   char   sMsg[512];
#ifdef _DEBUG
char xbuf1[512], xbuf2[512];
#endif

   if (pVAR != lsGetParmType(eid, 2))
   {
      lsErrRaise(eid, "db_query instantiation error: arg 2 must be var");
      return FALSE;
   }

   /* create stmt structure */

   pq = query_new();

   /* add stmt handle to structure */

   g_lsRC = lsGetParm(eid, 1, cADDR, &hdbc);
   if (g_lsRC != OK) goto LS_ERROR;

/* #ifdef _DEBUG
xtest(hdbc);
#endif */

   g_RC = SQLAllocStmt(hdbc, &hstmt);
   /* set up error handler */
   g_hDBC = hdbc;
   g_hSTMT = hstmt;
   g_eid = eid;
   ERROR_CHK("SQLAllocStmt");

   pq->hstmt = hstmt;

   /* get query string from Prolog */

   sQ = (char*)malloc(lsStrParmLen(eid, 3)+1);
   g_lsRC = lsGetParm(eid, 3, cSTR, sQ);
   if (g_lsRC != OK) goto LS_ERROR;

   /* prepare SQL query */

   //g_RC = SQLPrepare(hstmt, (UCHAR*)sQ, SQL_NTS);
   //errchk("lsODBC");

   /* get parameter list from Prolog */

   g_lsRC = lsGetParm(eid, 4, cTERM, &tParms);
   if (g_lsRC != OK) goto LS_ERROR;

#ifdef _DEBUG
lsTermToStrQ(eid, tParms, xbuf1, 500);
#endif

   /* walk input list */

   while (OK == lsPopList(eid, &tParms, cTERM, &t))
   {
      /* bind parameter for each */
      ptyp = lsGetTermType(eid, t);
      switch(ptyp)
      {
      case pATOM:
      case pSTR:
         sBuf = (char*)malloc(lsStrTermLen(eid, t) + 1);
         g_lsRC = lsGetTerm(eid, t, cSTR, sBuf);
         if (g_lsRC != OK) goto LS_ERROR;
         len = strlen(sBuf) + 1;
         s = query_addstrparm(pq, sBuf);
         g_ParmSize = SQL_NTS;
         g_RC = SQLBindParameter(hstmt, (UWORD)iParm, SQL_PARAM_INPUT, SQL_C_CHAR,
               SQL_CHAR, (UDWORD)len, 0, s, (SDWORD)len, &g_ParmSize);
         ERROR_CHK("SQLBindParameter");
         break;
      case pINT:
         g_lsRC = lsGetTerm(eid, t, cLONG, &i);
         if (g_lsRC != OK) goto LS_ERROR;
         pl = query_addintparm(pq, i);
         g_ParmSize = 0;
         g_RC = SQLBindParameter(hstmt, (UWORD)iParm, SQL_PARAM_INPUT, SQL_C_SLONG,
               SQL_INTEGER, 4, 0, pl, 4, &g_ParmSize);
         ERROR_CHK("SQLBindParameter");
         break;
      case pFLOAT:
         g_lsRC = lsGetTerm(eid, t, cDOUBLE, &g);
         if (g_lsRC != OK) goto LS_ERROR;
         pd = query_adddoubleparm(pq, g);
         g_ParmSize = 0;
         g_RC = SQLBindParameter(hstmt, (UWORD)iParm, SQL_PARAM_INPUT, SQL_C_DOUBLE,
               SQL_DOUBLE, 8, 0, pd, 8, &g_ParmSize);
         ERROR_CHK("SQLBindParameter");
         break;
      default:
         messout("Unsupported Prolog type for ODBC input");
      }
      iParm++;
   }

   /* get column list from Prolog */

   g_lsRC = lsGetParm(eid, 5, cTERM, &tCols);
   if (g_lsRC != OK) goto LS_ERROR;
#ifdef _DEBUG
lsTermToStrQ(eid, tCols, xbuf2, 500);
#endif
   /* walk output list */

   while (OK == lsPopList(eid, &tCols, cSTR, sType))
   {
      /* bind col for each */
      switch(sType[0])
      {
      case 'a':
         len = 1 + atol(&sType[1]);
         s = query_addstrcol(pq, pdATOM, len);
         g_ColSize = SQL_NO_TOTAL;
         g_RC = SQLBindCol(hstmt, (UWORD)iCol, SQL_C_CHAR, s,
               len, &g_ColSize);
         ERROR_CHK("SQLBindCol");
         break;        
      case 's':
         len = 1 + atol(&sType[1]);
         s = query_addstrcol(pq, pdSTR, len);
         g_ColSize = SQL_NO_TOTAL;
         g_RC = SQLBindCol(hstmt, (UWORD)iCol, SQL_C_CHAR, s,
               len, &g_ColSize);
         ERROR_CHK("SQLBindCol");
         break;        
      case 'i':
         pl = query_addintcol(pq);
         g_ColSize = 0;
         g_RC = SQLBindCol(hstmt, (UWORD)iCol, SQL_C_SLONG, pl,
               4, &g_ColSize);
         ERROR_CHK("SQLBindCol");
         break;
      case 'f':
         pf = query_addfloatcol(pq);
         g_ColSize = 0;
         g_RC = SQLBindCol(hstmt, (UWORD)iCol, SQL_C_FLOAT, pf,
               4, &g_ColSize);
         ERROR_CHK("SQLBindCol");
         break;
      case 'g':
         pd = query_adddoublecol(pq);
         g_ColSize = 0;
         g_RC = SQLBindCol(hstmt, (UWORD)iCol, SQL_C_DOUBLE, pd,
               8, &g_ColSize);
         ERROR_CHK("SQLBindCol");
         break;
      case 'd':
         pdate = query_adddatecol(pq);
         g_ColSize  = 0;  // ignored for date
         g_RC = SQLBindCol(hstmt, (UWORD)iCol, SQL_C_DATE, pdate,
               6, &g_ColSize);
         ERROR_CHK("SQLBindCol");
         break;
      case 't':
         ptime = query_addtimecol(pq);
         g_RC = SQLBindCol(hstmt, (UWORD)iCol, SQL_C_TIME, ptime,
               6, &g_ColSize);
         ERROR_CHK("SQLBindCol");
         break;
      default:
         sprintf(sMsg,
            "Unsupported Prolog type '%c' for ODBC output", sType[0]);
         messout(sMsg);
      }
      iCol++;
   }

   /* execute query and return pointer to query */

   //g_RC = SQLExecute(hstmt);
   //errchk("lsODBC");

   g_RC = SQLExecDirect(hstmt, (UCHAR*)sQ, SQL_NTS);
   ERROR_CHK("SQLExecDirect");

   lsUnifyParm(eid, 2, cADDR, &pq);
   if (sQ != NULL) free(sQ);
   if (sBuf != NULL) free(sBuf);
   return TRUE;
LS_ERROR:
   if (sQ != NULL) free(sQ);
   if (sBuf != NULL) free(sBuf);
   return(lserror());
ODBC_ERROR:
   if (sQ != NULL) free(sQ);
   if (sBuf != NULL) free(sBuf);
   return FALSE;
}
Example #11
0
xc_result_t
xCOM_QueryPort (
   xc_handle_t componentHandle,
   const char *portName,
   unsigned int queryFlags,
   xc_handle_t *queryHandlePtr,
   unsigned int *matchCountPtr
) {
   component_t *componentPtr;
   port_t *portPtr;
   xc_result_t result;

   TRACE3 ((
      "called with componentHandle=%u, portName='%s', queryFlags=%u, "
      "queryHandlePtr=%p, matchCountPtr=%p", componentHandle, portName,
      queryFlags, queryHandlePtr, matchCountPtr
   ));

   if ((componentHandle == XC_INVALID_HANDLE) || (portName == NULL)) {
      TRACE1 (("Invalid arguments!"));
      result = XC_ERR_INVAL;
   }
   else {

      componentPtr = component_ref (componentHandle);
      if (componentPtr != NULL) {
         portPtr = component_ref_port (componentPtr, portName);
         if (portPtr != NULL) {
            if (XC_PORTF_IS_REQUIRED (portPtr->flags) && XC_PORTF_IS_RUNTIME (portPtr->flags)) {
               result = query_new (
                  componentHandle,
                  portPtr->name,
                  portPtr->interfaceSpec.name,
                  portPtr->interfaceSpec.vmajor,
                  portPtr->interfaceSpec.vminor,
                  portPtr->componentName,
                  portPtr->port,
                  queryFlags,
                  queryHandlePtr,
                  matchCountPtr
               );
            }
            else {
               TRACE1 (("port '%s' of '%s' is not a runtime import!", portPtr->name, componentPtr->name));
               result = XC_ERR_INVAL;
            }
            component_unref_port (componentPtr, portPtr);
         }
         else {
            TRACE1 (("no port named '%s' in %s", portName, componentPtr->name));
            result = XC_ERR_NOENT;
         } 
         component_unref (componentPtr);
      }
      else {
         TRACE1 (("Invalid component handle %u!", componentHandle));
         result = XC_ERR_NOENT;
      }
   }

   TRACE3 (("exiting with result=%d", result));
   return result;
}