![]() | ![]() | ![]() |
![]() ![]() ![]() |
srvaddr.sun_family = AF_UNIX;
strncpy(srvaddr.sun_path, sockfile, sizeof(srvaddr.sun_path));
r = connect(s, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
if (r == -1) {
if (reply) *reply="Cannot connect to midwared server";
syslog(LOG_ERR,"[%s]:connect: %m",fname);
return CMD_ERR_SYS;
}
/*
* connected with the unix-domain socket ,next
* prepare the parameters for midwared server
*/
iov[iovcount].iov_base = (char *)cmd;
iov[iovcount].iov_len = strlen(cmd)+1;
/* check sqlcmd */
if ( sqlcmd && *sqlcmd ){
iovcount++;
iov[iovcount].iov_base = (char *)sqlcmd;
iov[iovcount].iov_len = strlen(sqlcmd)+1;
} else {
goto startsend;
}
/* check parameter2 */
if ( param2 && *param2 ){
iovcount++;
iov[iovcount].iov_base = (char *)param2;
iov[iovcount].iov_len = strlen(param2)+1;
} else {
goto startsend;
}
/* check parameter3 */
if ( param3 && *param3 ){
iovcount++;
iov[iovcount].iov_base = (char *)param3;
iov[iovcount].iov_len = strlen(param3)+1;
} else {
goto startsend;
}
/* check parameter4 */
if ( param4 && *param4 ){
iovcount++;
iov[iovcount].iov_base = (char *)param4;
iov[iovcount].iov_len = strlen(param4)+1;
}
startsend:
retry_writev(s, iov, iovcount+1);
/* get reply from midwared server */
start = 0;
while (start n = read(s, response+start, sizeof(response) - 1 - start);
if (n <1) break;
start += n;
} /* while */
close(s);
/* marshell the reply for client call */
if ( start <) =1 {
/* failurely got the reply */
if ( reply ) {
*reply=response;
}
return CMD_ERR_SYS;
} else {
/* successfully got the reply */
response[start] = '\0';
if (reply) {
*reply=response;
}
return CMD_OK;
}
} /* sendCmd */
/*
*--------------------------------------------------------------
*
* mid_query
* - exported for end user directly
*
* ARG -
* key: used for cache
*
* PRECON:
* argument 'result' must be initialized before this call
*
*--------------------------------------------------------------
*/
midQueryResult
mid_query(char *sqlcmd,const char *key,int useCache,char result[])
{
extern char *cache_mapstr(int);
const char fname[]="mid_query";
char *reply;
int r = 0;
if ( midInited == 0 ) {
mid_init(NULL);
}
switch ( dbserver ) {
case db_mysql:
r = sendCmd(REQ_MYSQL_QUERY,sqlcmd,key,cache_mapstr(useCache),
NULL,(char **)&reply);
break;