Functions

comm_encode.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "comm_encode.h"
#include "comm_data.h"
#include "utility.h"
Include dependency graph for comm_encode.c:

Go to the source code of this file.

Functions

int gs_encode_cancel_notification (char **msg, char *server_cid, char *request_id, int agent_taskid)
int gs_decode_cancel_notification (char *msg, char **server_cid, char **request_id, int *agent_taskid)
int gs_encode_failure_notification (char **msg, char *server_cid, char *request_id, int agent_taskid)
int gs_decode_failure_notification (char *msg, char **server_cid, char **request_id, int *agent_taskid)
int gs_encode_problem_complete_notification (char **msg, char *server_cid, char *request_id, int agent_taskid, double run_time)
int gs_decode_problem_complete_notification (char *msg, char **server_cid, char **request_id, int *agent_taskid, double *run_time)
int gs_encode_problem_solve_notification (char **msg, char *problem_name, double est_time, char *server_cid, char *user_name, char *host_name, char *client_cid, char *request_id, int agent_taskid, double agent_est_time)
int gs_decode_problem_solve_notification (char *msg, char **problem_name, double *est_time, char **server_cid, char **user_name, char **host_name, char **client_cid, char **request_id, int *agent_taskid, double *agent_est_time)
int gs_encode_problem_solve_request (char **msg, char *problem_name, char *user_name, char *host_name, char *domain_name, char *client_cid, int dsig, int agent_taskid, double agent_est_time)
int gs_decode_problem_solve_request (char *msg, char **problem_name, char **user_name, char **full_host_name, char **client_cid, int *dsig, int *agent_taskid, double *agent_est_time)
int gs_decode_problem_submit_request (char *msg, char **problem_name, int *dsig, char **criteria)
int gs_encode_problem_submit_request (char **msg, char *problem_name, int dsig, char *criteria)
int gs_encode_problem_submit_response (char **msg, char **server_list, int num_servers)
int gs_decode_problem_submit_response (char *msg, char ***server_list, int *num_servers)
int gs_decode_model_update (char *strp, char **name, char **expr)
int gs_encode_model_update (char **s, char *name, char *expr)
int gs_encode_infolist (char **s, gs_info_t *list)
int gs_decode_infolist (char *strp, gs_info_t **list)
int gs_encode_smart_info (char **encoding, gs_server_t *server, gs_server_t **server_list, double *times, int count)
int gs_decode_smart_info (char *encoding, gs_server_pings_t ***pings, int *np)
int gs_encode_server (char **encoding, gs_server_t *gs_server)
int gs_decode_server (char *encoding, gs_server_t *gs_server)
int gs_encode_availability_request (char **encoding, gs_server_t *gs_server)
int gs_decode_availability_request (char *encoding, gs_server_t *gs_server)
int gs_encode_workload_report (char **msg, int workload, int nproblems, char *server_cid)
int gs_decode_workload_report (char *msg, int *workload, int *nproblems, char *server_cid)
int gs_encode_problem (char **problemstring, gs_problem_t *problem)
int gs_decode_problem (char *problemstring, gs_problem_t *problem)
int gs_decode_dsi_object (char *encoding, DSI_OBJECT *obj)
int gs_encode_dsi_object (char **msg, DSI_OBJECT *obj)

Detailed Description

This file contains the encode/decode routines for different types of messages. The routines will adhere to the following naming convention: gs_decode_foo(char *msg, ...message specific arguments...) -decodes message of type "Foo" found in 'msg' gs_encode_foo(char **msg, ...message specific arguments...) -encodes message of type "Foo" to be stored in 'msg'

Definition in file comm_encode.c.


Function Documentation

int gs_decode_availability_request ( char *  encoding,
gs_server_t *  gs_server 
)

Decodes an availability request string into a gs_server_t struct from its XML representation. This server struct only contains the few necessary fields required to perform the test.

Parameters:
encoding -- contains the encoded request
gs_server -- on return, containts the decoded server info
Returns:
0 on success, -1 on failure.

Definition at line 817 of file comm_encode.c.

{
  int rv = -1, nchars;
  gs_server_t *s = gs_server;  
  char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
    proxy_dottedIP[20];

  if(!encoding)
    return -1;

  rv = sscanf(encoding, "<conn_test> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> </conn_test>\n %n", server_dottedIP, &s->port, proxy_dottedIP, &s->proxyport, componentid_string, &nchars);

  if (rv != 5) {
    ERRPRINTF("Server decoding '%s' failed with %d items decoded \n", 
      encoding, rv);
    return -1;
  }

  s->sa_list = NULL;
  
  proxy_str_to_cid(s->componentid, componentid_string);
  proxy_str_to_ip(&s->ipaddress, server_dottedIP);
  proxy_str_to_ip(&s->proxyip, proxy_dottedIP);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_decode_cancel_notification ( char *  msg,
char **  server_cid,
char **  request_id,
int *  agent_taskid 
)

Decode a notification to the agent that a client has cancelled the request.

Parameters:
msg -- the encoded problem solve notification message
server_cid -- on return, contains the component id of the server handling the request
request_id -- on return, contains the request id
agent_taskid -- on return, contains the task id assigned by the agent
Returns:
0 on success, -1 on failure.

Definition at line 63 of file comm_encode.c.

{
  if(!msg)
    return -1;

  sscanf(msg, "%s %s %d", *server_cid, *request_id, agent_taskid);
  return 0;
}

Here is the caller graph for this function:

int gs_decode_dsi_object ( char *  encoding,
DSI_OBJECT *  obj 
)

Convert a string representation of a DSI object back to a DSI data structure.

The object should be allocated, but its components are dynamically allocated in this routine and should be freed later.

Parameters:
encoding -- the encoded DSI object
obj -- on return, contains the decoded DSI struct
Returns:
0 on success, -1 on failure.

Definition at line 1147 of file comm_encode.c.

{
  int nchars;
  char *tmp;

  if(!obj) return -1;

  tmp = (char *)malloc(strlen(encoding)+1);

  if(!tmp) return -1;

  obj->dsi_file = (DSI_FILE *)malloc(sizeof(DSI_FILE));

  if(!obj->dsi_file) {
    free(tmp);
    return -1;
  }

  if(sscanf(encoding, "<dsi_object> <flag> %d </flag>\n%n", 
       &(obj->dsi_file->flag), &nchars) != 1)
    goto scan_error;
  encoding += nchars;

  if(sscanf(encoding, "<perm> %d </perm>\n%n", 
       &(obj->dsi_file->perm), &nchars) != 1)
    goto scan_error;
  encoding += nchars;

  if(sscanf(encoding, "<uid> %d </uid>\n%n", 
       &(obj->dsi_file->uid), &nchars) != 1)
    goto scan_error;
  encoding += nchars;

  if(sscanf(encoding, "<written_count> %d </written_count>\n%n",
       &(obj->dsi_file->written_count), &nchars) != 1)
    goto scan_error;
  encoding += nchars;

  if(sscanf(encoding, "<offset> %d </offset>\n%n", 
       &(obj->offset), &nchars) != 1)
    goto scan_error;
  encoding += nchars;

  if(sscanf(encoding, "<storage_system> %d </storage_system>\n%n",
       &(obj->dsi_file->storage_system), &nchars) != 1)
    goto scan_error;
  encoding += nchars;

  if(obj->dsi_file->storage_system == GS_DSI_IBP) {
#ifdef DSI_IBP
    obj->dsi_file->dsi_specifics.ibp.depot = 
           (IBP_depot)malloc(sizeof(struct ibp_depot));

    if(!obj->dsi_file->dsi_specifics.ibp.depot) {
      free(tmp);
      if(obj->dsi_file) free(obj->dsi_file);
      return -1;
    }
      
    obj->dsi_file->dsi_specifics.ibp.cap = 
           (IBP_set_of_caps)malloc(sizeof(struct ibp_set_of_caps));

    if(!obj->dsi_file->dsi_specifics.ibp.cap) {
      free(tmp);
      if(obj->dsi_file) 
        free(obj->dsi_file);
      if(obj->dsi_file->dsi_specifics.ibp.depot)
        free(obj->dsi_file->dsi_specifics.ibp.depot);
      return -1;
    }
      
    if(sscanf(encoding, "<host> %s </host>\n%n", 
      obj->dsi_file->dsi_specifics.ibp.depot->host, &nchars) != 1)
      goto scan_error;
    encoding += nchars;

    if(sscanf(encoding, "<port> %d </port>\n%n",
      &(obj->dsi_file->dsi_specifics.ibp.depot->port), &nchars) != 1)
      goto scan_error;
    encoding += nchars;

    if(sscanf(encoding, "<readcap> %s </readcap>\n%n", tmp, &nchars) != 1)
      goto scan_error;
    obj->dsi_file->dsi_specifics.ibp.cap->readCap = strdup(tmp);
    encoding += nchars;

    if(sscanf(encoding, "<writecap> %s </writecap>\n%n", tmp, &nchars) != 1)
      goto scan_error;
    obj->dsi_file->dsi_specifics.ibp.cap->writeCap = strdup(tmp);
    encoding += nchars;

    if(sscanf(encoding, "<managecap> %s </managecap>\n%n", tmp, &nchars) != 1)
      goto scan_error;
    obj->dsi_file->dsi_specifics.ibp.cap->manageCap = strdup(tmp);
#endif
  }

  free(tmp);

  return 0;

scan_error:
  free(tmp);
  return -1;
}

Here is the caller graph for this function:

int gs_decode_failure_notification ( char *  msg,
char **  server_cid,
char **  request_id,
int *  agent_taskid 
)

Decode a notification to the agent that a server is handling this problem solve.

Parameters:
msg -- the encoded problem solve notification message
server_cid -- on return, contains the component id of the server handling the request
request_id -- on return, contains the request id
agent_taskid -- on return, contains the task id assigned by the agent
Returns:
0 on success, -1 on failure.

Definition at line 113 of file comm_encode.c.

{
  if(!msg)
    return -1;

  sscanf(msg, "%s %s %d", *server_cid, *request_id, agent_taskid);
  return 0;
}

int gs_decode_infolist ( char *  strp,
gs_info_t **  list 
)

Decode an infolist, which is a list of attribute/value pairs.

Parameters:
strp -- the encoded list
list -- on return, contains the list of gs_info_t structs (attribute/value pairs)
Returns:
0 on success, -1 on failure.

Definition at line 536 of file comm_encode.c.

{
  int n, nchars, count, idx, maxlen;
  gs_info_t *info, *ip;

  maxlen = strlen(strp);

  n = sscanf(strp, " <infolist count=\"%d\">\n %n", &count, &nchars);
  strp = strp+nchars;   /* move past processed chars */

  for (nchars=0, idx=0; idx<count; idx++) {
    info = (gs_info_t*)CALLOC(1, sizeof(gs_info_t));
    if(!info) return -1;

    info->next = NULL;

    info->type = (char *)CALLOC(maxlen, sizeof(char));
    if(!info->type) return -1;

    info->value = (char *)CALLOC(maxlen, sizeof(char));
    if(!info->value) return -1;

    n = sscanf(strp, "  <info type=\"%[^\"]\" value=\"%[^\"]\" />\n %n", 
          info->type, info->value, &nchars);

    strp = strp+nchars; /* move past processed chars */
    info->type = REALLOC(info->type, strlen(info->type)+1);
    info->value = REALLOC(info->value, strlen(info->value)+1);

    if(!info->type || !info->value) return -1;

    if (*list == NULL)
      *list = info;
    else {
      for (ip=*list; ip->next!=NULL; ip=ip->next) {}
      ip->next = info;
    }
  }
  n = sscanf(strp, " </infolist>\n %n", &nchars);
  strp = strp+nchars;   /* move past processed chars */

  return 0;
}

Here is the caller graph for this function:

int gs_decode_model_update ( char *  strp,
char **  name,
char **  expr 
)

Definition at line 464 of file comm_encode.c.

{
  int maxlen;
  
  maxlen = strlen(strp);
  
  *name = (char *)calloc(maxlen, sizeof(char));
  if(!*name) return -1;
  
  *expr = (char *)calloc(maxlen, sizeof(char));
  if(!*expr) return -1;
  
  sscanf(strp, "<model_update prob_name=\"%[^\"]\" expr=\"%[^\"]\"/>\n",
          *name, *expr);

  return 0;
}

Here is the caller graph for this function:

int gs_decode_problem ( char *  problemstring,
gs_problem_t *  problem 
)

Convert a string representation of a problem back to a problem data structure.

The problem structure should be allocated, but its components are dynamically allocated in this routine and should be freed later.

Parameters:
problemstring -- the encoded problem descriptor
problem -- on return, contains the decoded problem descriptor
Returns:
0 on success, -1 on failure.

Definition at line 976 of file comm_encode.c.

{
  int n, nchars, count, enum_count, idx, maxlen = strlen(problemstring)+1;
  char *strp = problemstring, *inout, *datatype, *objecttype, *ptype;
  gs_argument_t *arg, *ap;
 
  n = nchars = count = enum_count = idx = 0;

  problem->arglist = NULL;
  problem->next = NULL;
  problem->infolist = NULL;
  problem->work = NULL;
  problem->worksize = 0;

  ptype = CALLOC(maxlen, sizeof(char));

  problem->name = CALLOC(maxlen, sizeof(char));
  problem->description = CALLOC(maxlen, sizeof(char));
  problem->callsig = CALLOC(maxlen, sizeof(char));
  n = sscanf(strp, "<problem name=\"%[^\"]\" type=\"%[^\"]\" description=\"%[^\"]\" major=\"%d\" callsig=\"%[^\"]\">\n %n", problem->name, ptype, problem->description, &(problem->major), problem->callsig, &nchars);
  strp = strp+nchars;   /* move past processed chars */
  problem->name = REALLOC(problem->name, strlen(problem->name)+1);
  problem->description = REALLOC(problem->description, strlen(problem->description)+1);

  problem->type = gs_parse_probtype(ptype);
  free(ptype);
  if(problem->type == GS_BAD_PTYPE) {
    ERRPRINTF("bad problem type specified.\n");
    return -1;
  }

  n = sscanf(strp, " <arglist count=\"%d\">\n %n", &count, &nchars);
  strp = strp+nchars;   /* move past processed chars */
  
  inout = CALLOC(maxlen, sizeof(char));
  datatype = CALLOC(maxlen, sizeof(char));
  objecttype = CALLOC(maxlen, sizeof(char));

  for (nchars=0,idx=0; idx<count; idx++) {
    arg = (gs_argument_t*)CALLOC(1, sizeof(gs_argument_t));
    arg->data_handle = 0;
    arg->pass_back = 1;
    arg->next = NULL;
    arg->prob = problem;
    arg->name = CALLOC(maxlen, sizeof(char));
    arg->rowexp = CALLOC(maxlen, sizeof(char));
    arg->colexp = CALLOC(maxlen, sizeof(char));
    arg->sparse_attr.nnzexp = CALLOC(maxlen, sizeof(char));
    arg->sparse_attr.indices = CALLOC(maxlen, sizeof(char));
    arg->sparse_attr.pointer = CALLOC(maxlen, sizeof(char));
    arg->description = CALLOC(maxlen, sizeof(char));
    arg->arg_enum = NULL;

    n = sscanf(strp, "  <arg name=\"%[^\"]\" inout=\"%[^\"]\" datatype=\"%[^\"]\" objecttype=\"%[^\"]\" rowexp=\"%[^\"]\" colexp=\"%[^\"]\" nnzexp=\"%[^\"]\" indices=\"%[^\"]\" pointer=\"%[^\"]\" enum_count=\"%d\" description=\"%[^\"]\">\n %n", arg->name, inout, datatype, objecttype, arg->rowexp, arg->colexp, arg->sparse_attr.nnzexp, arg->sparse_attr.indices, arg->sparse_attr.pointer, &enum_count, arg->description, &nchars);
    strp = strp+nchars; /* move past processed chars */

    if(enum_count > 0) {
      gs_arg_enum_t *ap;
      char *enum_string;
      int i;

      enum_string = (char *)malloc(maxlen);
      if(!enum_string) {
        ERRPRINTF("malloc.\n");
        return -1;
      }

      n = sscanf(strp, "    <arg_enum>\n %n", &nchars);
      strp = strp+nchars;   /* move past processed chars */

      ap = (gs_arg_enum_t *) malloc(enum_count * sizeof(gs_arg_enum_t));
      if(!ap) {
        ERRPRINTF("malloc.\n");
        return -1;
      }

      /* i have allocated an array of gs_arg_enum_t, but i'm going to construct
       * it sort of like a linked list, linking ap[i].next to the address of
       * a[i+1].
       */

      for(i=0; i < enum_count; i++) {
        n = sscanf(strp, "      <enum_val val=\"%[^\"]\"/>\n %n", enum_string, &nchars);
        strp = strp+nchars; /* move past processed chars */

        ap[i].val = strdup(enum_string);
        if(!ap[i].val) {
          ERRPRINTF("malloc.\n");
          return -1;
        }
    
        ap[i].next = &ap[i+1];
      }

      ap[i-1].next = NULL;
      arg->arg_enum = ap;

      n = sscanf(strp, "    </arg_enum>\n %n", &nchars);
      strp = strp+nchars;   /* move past processed chars */

      free(enum_string);
    }

    n = sscanf(strp, " </arg>\n %n", &nchars);
    strp = strp+nchars; /* move past processed chars */

    arg->name = REALLOC(arg->name, strlen(arg->name)+1);
    
    arg->inout = gs_parse_inout(inout);
    if(arg->inout == GS_BAD_INOUT) {
      ERRPRINTF("bad in/out specified.\n");
      return -1;
    }

    arg->datatype = gs_parse_datatype(datatype);
    if(arg->datatype == GS_BAD_DTYPE) {
      ERRPRINTF("bad data type specified.\n");
      return -1;
    }

    arg->objecttype = gs_parse_objecttype(objecttype);
    if(arg->objecttype == GS_BAD_OTYPE) {
      ERRPRINTF("bad object type specified.\n");
      return -1;
    }

    arg->rowexp = REALLOC(arg->rowexp, strlen(arg->rowexp)+1);
    arg->colexp = REALLOC(arg->colexp, strlen(arg->colexp)+1);
    arg->sparse_attr.nnzexp = REALLOC(arg->sparse_attr.nnzexp, 
      strlen(arg->sparse_attr.nnzexp)+1);
    arg->sparse_attr.indices = REALLOC(arg->sparse_attr.indices, 
      strlen(arg->sparse_attr.indices)+1);
    arg->sparse_attr.pointer = REALLOC(arg->sparse_attr.pointer, 
      strlen(arg->sparse_attr.pointer)+1);
    arg->description = REALLOC(arg->description, strlen(arg->description)+1);
    if (problem->arglist == NULL) problem->arglist = arg;
    else {
      for (ap=problem->arglist; ap->next!=NULL; ap=ap->next) {}
      ap->next = arg;
    }
  }

  n = sscanf(strp, " </arglist>\n %n", &nchars);
  strp = strp+nchars;   /* move past processed chars */

  gs_decode_infolist(strp, &problem->infolist);

  n = sscanf(strp, " </problem>\n %n", &nchars);
  strp = strp+nchars;   /* move past processed chars */
  
  free(inout);
  free(datatype);
  free(objecttype);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_decode_problem_complete_notification ( char *  msg,
char **  server_cid,
char **  request_id,
int *  agent_taskid,
double *  run_time 
)

Decode a notification to the agent that a server has successfully completed this request.

Parameters:
msg -- the encoded problem solve notification message
server_cid -- on return, contains the component id of the server handling the request
request_id -- on return, contains the request id
agent_taskid -- on return, contains the task id assigned by the agent
run_time -- on return, contains the server execution time for this job
Returns:
0 on success, -1 on failure.

Definition at line 166 of file comm_encode.c.

{
  if(!msg)
    return -1;

  sscanf(msg, "%s %s %d %lf", *server_cid, *request_id, agent_taskid, run_time);
  return 0;
}

Here is the caller graph for this function:

int gs_decode_problem_solve_notification ( char *  msg,
char **  problem_name,
double *  est_time,
char **  server_cid,
char **  user_name,
char **  host_name,
char **  client_cid,
char **  request_id,
int *  agent_taskid,
double *  agent_est_time 
)

Decode a notification to the agent that a server is handling this problem solve.

Parameters:
msg -- the encoded problem solve notification message
problem_name -- on return, contains the name of the remote procedure to be called
server_cid -- on return, contains the component id of the server handling the request
user_name -- on return, contains the user id of the client making the request
host_name -- on return, contains the host name of the client machine
client_cid -- on return, contains the component id of the client
request_id -- on return, contains the request id
agent_taskid -- on return, contains the task id assigned by the agent
agent_est_time -- on return, contains the agent's estimate of run time
Returns:
0 on success, -1 on failure.

Definition at line 233 of file comm_encode.c.

{
  if(!msg)
    return -1;

  *problem_name = CALLOC(strlen(msg), sizeof(char));
  *server_cid = CALLOC(strlen(msg), sizeof(char));
  *user_name = CALLOC(strlen(msg), sizeof(char));
  *host_name = CALLOC(strlen(msg), sizeof(char));
  *client_cid = CALLOC(strlen(msg), sizeof(char));
  *request_id = CALLOC(strlen(msg), sizeof(char));

  sscanf(msg, "%s %lf %s %s %s %s %s %d %lf", *problem_name, est_time, *server_cid,
    *user_name, *host_name, *client_cid, *request_id, agent_taskid, agent_est_time);

  return 0;
}

Here is the caller graph for this function:

int gs_decode_problem_solve_request ( char *  msg,
char **  problem_name,
char **  user_name,
char **  full_host_name,
char **  client_cid,
int *  dsig,
int *  agent_taskid,
double *  agent_est_time 
)

Decode a request to solve a problem.

Parameters:
msg -- the problem solve request message
problem_name -- on return, will contain the name of the procedure the requester wants to call
user_name -- on return, contains the user id of the client making the request
full_host_name -- on return, contains the host name of the client machine
client_cid -- on return, contains the component id of the client
dsig -- on return, will contain the requester's data signature
agent_taskid -- on return, will contain the task id assigned by the agent.
agent_est_time -- on return, will contain the agent's estimate of the elapsed time.
Returns:
0 on success, -1 on failure.

Definition at line 308 of file comm_encode.c.

{
  if(!msg)
    return -1;

  sscanf(msg, "%s %s %s %s %d %d %lf", *problem_name, *user_name, *full_host_name, 
    *client_cid, dsig, agent_taskid, agent_est_time);
  return 0;
}

Here is the caller graph for this function:

int gs_decode_problem_submit_request ( char *  msg,
char **  problem_name,
int *  dsig,
char **  criteria 
)

Encode a request to the agent to lookup a problem and return server information for that problem. the format of this request is: <problem name>=""> <data signature>="">

the old netsolve used the following information, so these may be incorporated later: -nickname -input_size -output_size -problem_size -username -hostname

Parameters:
msg -- the problem submit request message
problem_name -- on return, will contain the name of the procedure the requester wants to call
dsig -- on return, will contain the requester's data signature
criteria -- on return, will contain the requester's criteria string. if there was no criteria string present, this will be set to NULL.
Returns:
0 on success, -1 on failure.

Definition at line 346 of file comm_encode.c.

{
  int nchars;
  
  if(!msg)
    return -1;
    
  /* since the message consists of only the problem name, we
   * just dup it and return.
   */
  *problem_name = (char *)CALLOC(strlen(msg), sizeof(char));
  sscanf(msg, "%s %d %n", *problem_name, dsig, &nchars);
  
  if(msg[nchars] != 0) {
    *criteria = strdup(msg + nchars);
    
    if(!*criteria) {
      printf("failed to alloc criteria\n");
      return -1;
    }
  } 
  else
    *criteria = NULL;

  return 0;
}

Here is the caller graph for this function:

int gs_decode_problem_submit_response ( char *  msg,
char ***  server_list,
int *  num_servers 
)

Decode the response to a problem submit request.

Parameters:
msg -- the problem submit response message
server_list -- on return, will contain the list of servers that can execute the function
num_servers -- on return, will contain the number of servers in 'server_list'
Returns:
0 on success, -1 on failure.

Definition at line 441 of file comm_encode.c.

{
  int i;

  if(!msg) 
    return -1;

  *num_servers = atoi(strtok(msg, " "));

  *server_list = (char **)CALLOC(*num_servers, sizeof(char *));

  if(!*server_list) {
    ERRPRINTF("decodeProblemSubmitResponse: malloc failed\n");
    return -1;
  }

  for(i=0;i<*num_servers;i++) 
    (*server_list)[i] = strdup(strtok(NULL," " ));

  return 0;
}

int gs_decode_server ( char *  encoding,
gs_server_t *  gs_server 
)

Decodes a server string back into a gs_server_t struct from its XML representation.

Parameters:
encoding -- contains the encoded server
gs_server -- on return, containts the decoded server info
Returns:
0 on success, -1 on failure.

Definition at line 721 of file comm_encode.c.

{
  int rv = -1, nchars;
  gs_server_t *s = gs_server;  
  char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
    proxy_dottedIP[20];

  if(!encoding)
    return -1;

  s->hostname = (char *)CALLOC(strlen(encoding)+1, sizeof(char));
  s->arch = (char *)CALLOC(strlen(encoding)+1, sizeof(char));
  s->agenthost = (char *)CALLOC(strlen(encoding)+1, sizeof(char));

  if(!s->hostname || !s->arch || !s->agenthost) {
    if(s->hostname) free(s->hostname);
    if(s->arch) free(s->arch);
    if(s->agenthost) free(s->agenthost);
    return -1;
  }

  rv = sscanf(encoding, "<server> <hostname> %s </hostname> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> <arch> %s </arch> <data_format> %d </data_format> <kflops> %d </kflops> <workload> %d </workload> <ncpu> %d </ncpu> <status> %d </status> <availcpu> %lg </availcpu> <availmem> %lg </availmem> <nproblems> %d </nproblems> <agenthost> %s </agenthost> <agentport> %d </agentport> <score> %lg </score> <smart> %d </smart> </server>\n %n", s->hostname, server_dottedIP, &s->port, proxy_dottedIP, &s->proxyport, componentid_string, s->arch, &s->data_format, &s->kflops, &s->workload, &s->ncpu, &s->status, &s->availcpu, &s->availmem, &s->nproblems, s->agenthost, &s->agentport, &s->score, &s->smart, &nchars);

  if (rv != 19) {
    ERRPRINTF("Server decoding '%s' failed with %d items decoded \n", 
      encoding, rv);
    FREE(s->hostname);
    FREE(s->arch);
    FREE(s->agenthost);
    return -1;
  }

  s->sa_list = NULL;
  
  encoding += nchars;
  gs_decode_infolist(encoding,&s->sa_list);

  s->hostname = REALLOC(s->hostname, strlen(s->hostname)+1);
  s->arch = REALLOC(s->arch, strlen(s->arch)+1);
  s->agenthost = REALLOC(s->agenthost, strlen(s->agenthost)+1);

  if(!s->hostname || !s->arch || !s->agenthost) {
    ERRPRINTF("Server decoding failed to realloc memory\n");
    FREE(s->hostname);
    FREE(s->arch);
    FREE(s->agenthost);
    return -1;
  }

  proxy_str_to_cid(s->componentid, componentid_string);
  proxy_str_to_ip(&s->ipaddress, server_dottedIP);
  proxy_str_to_ip(&s->proxyip, proxy_dottedIP);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_decode_smart_info ( char *  encoding,
gs_server_pings_t ***  pings,
int *  np 
)

Definition at line 615 of file comm_encode.c.

{
  int i, n, count, maxlen, nchars;
  gs_server_pings_t **parr;
  char *strp, *cid_tmp;

  *np = 0;
  *pings = NULL;

  strp = encoding;
  maxlen = strlen(strp);

  cid_tmp = (char *)calloc(maxlen, sizeof(char));
  if(!cid_tmp) return -1;

  n = sscanf(strp, "<smart_info>\n %n", &nchars);
  strp = strp+nchars;

  n = sscanf(strp, "<count> %d </count>\n %n", &count, &nchars);
  strp = strp+nchars;

  parr = (gs_server_pings_t **) malloc(count * sizeof(gs_server_pings_t *));
  if(!parr) {
    free(cid_tmp);
    return -1;
  }

  for(i=0;i<count;i++) {
    parr[i] = (gs_server_pings_t *) malloc(sizeof(gs_server_pings_t));
    if(!parr[i]) {
      /* probably need to free parr[1 through i-1] too */
      free(parr);
      free(cid_tmp);
      return -1;
    }

    n = sscanf(strp, "<componentid> %s </componentid>  <time> %lg </time>\n %n",
          cid_tmp, &(parr[i]->comm_time), &nchars);
    strp = strp+nchars;
    proxy_str_to_cid(parr[i]->componentid, cid_tmp);
  }

  n = sscanf(strp, "</smart_info>\n %n", &nchars);
  strp = strp+nchars;

  *np = count;
  *pings = parr;

  return 0;
}

Here is the call graph for this function:

int gs_decode_workload_report ( char *  msg,
int *  workload,
int *  nproblems,
char *  server_cid 
)

Decodes a workload report message.

Parameters:
msg -- the workload report message
workload -- on return, contains the remote machine's current workload
server_cid -- on return, contains the remote machine's component id
Returns:
0 on success, -1 on failure.

Definition at line 878 of file comm_encode.c.

{
  if(!msg)
    return -1;

  sscanf(msg, "%d %d %s", workload, nproblems, server_cid);

  return 0;
}

Here is the caller graph for this function:

int gs_encode_availability_request ( char **  encoding,
gs_server_t *  gs_server 
)

Encodes a request to the agent to perform a connectivity test.

Parameters:
encoding -- on return, contains the encoded request
gs_server -- the server info to be encoded
Returns:
0 on success, -1 on failure.

Definition at line 787 of file comm_encode.c.

{
  gs_server_t *s = gs_server;   /* just a shortcut name */
  char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
    proxy_dottedIP[20];

  if(!gs_server)
    return -1;

  proxy_cid_to_str(componentid_string, s->componentid);
  proxy_ip_to_str(s->ipaddress, server_dottedIP);
  proxy_ip_to_str(s->proxyip, proxy_dottedIP);

  *encoding = dstring_sprintf("<conn_test> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> </conn_test>\n", server_dottedIP, s->port, proxy_dottedIP, s->proxyport, componentid_string);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_cancel_notification ( char **  msg,
char *  server_cid,
char *  request_id,
int  agent_taskid 
)

Encode a notification to the agent that a client has cancelled the request.

Parameters:
msg -- on return, contains the encoded message
server_cid -- component id of the server handling the request
request_id -- request id
agent_taskid -- task id assigned by the agent.
Returns:
0 on success, -1 on failure.

Definition at line 36 of file comm_encode.c.

{ 
  if(!server_cid || !request_id) {
    *msg = NULL;
    return -1;
  }

  *msg = dstring_sprintf("%s %s %d", server_cid, request_id, agent_taskid);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_dsi_object ( char **  msg,
DSI_OBJECT *  obj 
)

Convert a DSI structure to a string representation.

The string is dynamically allocated in this routine and should be freed later.

Parameters:
msg -- on return, contains the encoded DSI object
obj -- the DSI object to be encoded
Returns:
0 on success, -1 on failure.

Definition at line 1266 of file comm_encode.c.

{
  char *tmp;

  *msg = dstring_sprintf("<dsi_object>\n");

  tmp = dstring_sprintf("  <flag> %d </flag>\n", obj->dsi_file->flag);
  *msg = dstring_append_free(*msg, tmp);
  tmp = dstring_sprintf("  <perm> %d </perm>\n", obj->dsi_file->perm);
  *msg = dstring_append_free(*msg, tmp);
  tmp = dstring_sprintf("  <uid> %d </uid>\n", obj->dsi_file->uid);
  *msg = dstring_append_free(*msg, tmp);
  tmp = dstring_sprintf("  <written_count> %d </written_count>\n", 
      obj->dsi_file->written_count);
  *msg = dstring_append_free(*msg, tmp);
  tmp = dstring_sprintf("  <offset> %d </offset>\n", obj->offset);
  *msg = dstring_append_free(*msg, tmp);
  tmp = dstring_sprintf("  <storage_system> %d </storage_system>\n", 
      obj->dsi_file->storage_system);
  *msg = dstring_append_free(*msg, tmp);

  if(obj->dsi_file->storage_system == GS_DSI_IBP) {
#ifdef DSI_IBP
    tmp = dstring_sprintf("  <host> %s </host>\n", 
       obj->dsi_file->dsi_specifics.ibp.depot->host);
    *msg = dstring_append_free(*msg, tmp);
    tmp = dstring_sprintf("  <port> %d </port>\n", 
       obj->dsi_file->dsi_specifics.ibp.depot->port);
    *msg = dstring_append_free(*msg, tmp);
    tmp = dstring_sprintf("  <readcap> %s </readcap>\n", 
       obj->dsi_file->dsi_specifics.ibp.cap->readCap);
    *msg = dstring_append_free(*msg, tmp);
    tmp = dstring_sprintf("  <writecap> %s </writecap>\n", 
       obj->dsi_file->dsi_specifics.ibp.cap->writeCap);
    *msg = dstring_append_free(*msg, tmp);
    tmp = dstring_sprintf("  <managecap> %s </managecap>\n", 
       obj->dsi_file->dsi_specifics.ibp.cap->manageCap);
    *msg = dstring_append_free(*msg, tmp);
#endif
  }

  tmp = dstring_sprintf("</dsi_object>\n");
  *msg = dstring_append_free(*msg, tmp);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_failure_notification ( char **  msg,
char *  server_cid,
char *  request_id,
int  agent_taskid 
)

Encode a notification to the agent that a server has failed to handle the request.

Parameters:
msg -- on return, contains the encoded message
server_cid -- component id of the server handling the request
request_id -- request id
agent_taskid -- task id assigned by the agent.
Returns:
0 on success, -1 on failure.

Definition at line 86 of file comm_encode.c.

{ 
  if(!server_cid || !request_id) {
    *msg = NULL;
    return -1;
  }

  *msg = dstring_sprintf("%s %s %d", server_cid, request_id, agent_taskid);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_infolist ( char **  s,
gs_info_t *  list 
)

Encode an infolist, which is a list of attribute/value pairs.

Parameters:
s -- on return, contains the encoded list
list -- the list of gs_info_t structs (attribute/value pairs)
Returns:
0 on success, -1 on failure.

Definition at line 501 of file comm_encode.c.

{
  int count = 0;
  char *stmp = NULL;
  gs_info_t* info = NULL;

  for (count=0,info=list; info!=NULL; info=info->next) 
    count++;

  stmp = dstring_sprintf(" <infolist count=\"%d\">\n", count);
  *s = dstring_append_free(*s, stmp);


  for (info=list; info!=NULL; info=info->next) {
    stmp = dstring_sprintf("  <info type=\"%s\" value=\"%s\" />\n", info->type, info->value);
    *s = dstring_append_free(*s, stmp);
  }
  stmp = dstring_sprintf(" </infolist>\n");

  *s = dstring_append_free(*s, stmp);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_model_update ( char **  s,
char *  name,
char *  expr 
)

Definition at line 483 of file comm_encode.c.

{
  *s = dstring_sprintf("<model_update prob_name=\"%s\" expr=\"%s\"/>\n",
          name, expr);

  return *s ? 0 : -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_problem ( char **  problemstring,
gs_problem_t *  problem 
)

Convert a problem structure to a string representation.

The string is dynamically allocated in this routine and should be freed later.

Parameters:
problemstring -- on return, contains the encoded problem descriptor
problem -- the problem descriptor to be encoded
Returns:
0 on success, -1 on failure.

Definition at line 902 of file comm_encode.c.

{
  int count = 0, enum_count = 0;
  gs_argument_t *arg = NULL;
  gs_arg_enum_t *arg_enum = NULL;
  char *s = NULL;
  char *stmp = NULL;
  char *callsig;

  if(!problem)
    return -1;
  
  callsig = problem->callsig ? problem->callsig : GS_NO_CALL_SIG;

  s = dstring_sprintf("<problem name=\"%s\" type=\"%s\" description=\"%s\" major=\"%d\" callsig=\"%s\">\n", problem->name, gs_probtype[problem->type], problem->description, problem->major, callsig);

  for (count=0,arg=problem->arglist; arg!=NULL; arg=arg->next) 
    count++;

  stmp = dstring_sprintf(" <arglist count=\"%d\">\n", count);
  s = dstring_append_free(s,stmp);

  for (arg=problem->arglist; arg!=NULL; arg=arg->next) {
    for (enum_count=0,arg_enum=arg->arg_enum; arg_enum!=NULL; arg_enum=arg_enum->next) 
      enum_count++;

    stmp = dstring_sprintf("  <arg name=\"%s\" inout=\"%s\" datatype=\"%s\" objecttype=\"%s\" rowexp=\"%s\" colexp=\"%s\" nnzexp=\"%s\" indices=\"%s\" pointer=\"%s\" enum_count=\"%d\" description=\"%s\">\n", arg->name, gs_inout[arg->inout], gs_c_datatype[arg->datatype], gs_objecttype[arg->objecttype], arg->rowexp, arg->colexp, arg->sparse_attr.nnzexp, arg->sparse_attr.indices, arg->sparse_attr.pointer, enum_count, arg->description);
    s = dstring_append_free(s, stmp);

    if(enum_count > 0) {
      stmp = dstring_sprintf("    <arg_enum>\n");
      s = dstring_append_free(s, stmp);

      for(arg_enum=arg->arg_enum; arg_enum!=NULL; arg_enum=arg_enum->next) {
        stmp = dstring_sprintf("      <enum_val val=\"%s\"/>\n", arg_enum->val);
        s = dstring_append_free(s, stmp);
      }

      stmp = dstring_sprintf("    </arg_enum>\n");
      s = dstring_append_free(s, stmp);
    }

    stmp = dstring_sprintf("  </arg>\n");
    s = dstring_append_free(s, stmp);
  }

  stmp = dstring_sprintf(" </arglist>\n");
  s = dstring_append_free(s, stmp);
 
  if(gs_encode_infolist(&s, problem->infolist) <0)
    return -1;

  stmp = dstring_sprintf("</problem>");
  s = dstring_append_free(s, stmp);

  *problemstring = s;
  
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_problem_complete_notification ( char **  msg,
char *  server_cid,
char *  request_id,
int  agent_taskid,
double  run_time 
)

Encode a notification to the agent that a server has successfully completed this request.

Parameters:
msg -- on return, contains the encoded message
server_cid -- component id of the server handling the request
request_id -- request id
agent_taskid -- task id assigned by the agent.
run_time -- server execution time for this job
Returns:
0 on success, -1 on failure.

Definition at line 137 of file comm_encode.c.

{ 
  if(!server_cid || !request_id) {
    *msg = NULL;
    return -1;
  }

  *msg = dstring_sprintf("%s %s %d %lf", server_cid, request_id, agent_taskid,
     run_time);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_problem_solve_notification ( char **  msg,
char *  problem_name,
double  est_time,
char *  server_cid,
char *  user_name,
char *  host_name,
char *  client_cid,
char *  request_id,
int  agent_taskid,
double  agent_est_time 
)

Encode a notification to the agent that a server is handling this problem solve.

Parameters:
msg -- on return, contains the encoded message
problem_name -- the name of the remote procedure to be called
est_time -- server's estimate of run time
server_cid -- component id of the server handling the request
user_name -- user id of the client making the request
host_name -- host name of the client machine
client_cid -- component id of the client
request_id -- request id
agent_taskid -- task id assigned by the agent.
agent_est_time -- agent's estimate of run time
Returns:
0 on success, -1 on failure.

Definition at line 195 of file comm_encode.c.

{
  if(!problem_name) {
    *msg = NULL;
    return -1;
  }

  *msg = dstring_sprintf("%s %lf %s %s %s %s %s %d %lf", problem_name, est_time,
     server_cid, user_name, host_name, client_cid, request_id, agent_taskid,
     agent_est_time);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_problem_solve_request ( char **  msg,
char *  problem_name,
char *  user_name,
char *  host_name,
char *  domain_name,
char *  client_cid,
int  dsig,
int  agent_taskid,
double  agent_est_time 
)

Encode a request to solve a problem. the format of this request is: <problem name>=""> <user name>=""> <host name>=""> <data signature>="">

Parameters:
msg -- on return, contains the encoded message
problem_name -- the name of the remote procedure to be called
user_name -- user id of the client making the request
host_name -- host name of the client machine
domain_name -- domain name of the client machine
client_cid -- component id of the client
dsig -- this machine's data signature.
agent_taskid -- task id assigned by the agent.
agent_est_time -- agent's estimate of elapsed time.
Returns:
0 on success, -1 on failure.

Definition at line 272 of file comm_encode.c.

{
  if(!problem_name) {
    *msg = NULL;
    return -1;
  }
   
  *msg = dstring_sprintf("%s %s %s.%s %s %d %d %lf ", problem_name, user_name,
     host_name, domain_name, client_cid, dsig, agent_taskid, agent_est_time);
  
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_problem_submit_request ( char **  msg,
char *  problem_name,
int  dsig,
char *  criteria 
)

Encode a problem submit request. See the decode function for a description of the format.

Parameters:
msg -- on return, contains the encoded message
problem_name -- the name of the remote procedure to be looked up
dsig -- this machine's data signature.
dsig -- the request criteria string.
Returns:
0 on success, -1 on failure.

Definition at line 386 of file comm_encode.c.

{
  if(!problem_name) 
    return -1;

  *msg = dstring_sprintf("%s %d %s", problem_name, dsig, criteria ? criteria : "");

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_problem_submit_response ( char **  msg,
char **  server_list,
int  num_servers 
)

Encode the response to a problem submit request. This consists of a list of servers separated by spaces. The first number in the string is the number of servers that will be returned. For example: "3 server1 server2 server3"

Parameters:
msg -- on return, contains the encoded message
server_list -- the list of servers that can execute the function
num_servers -- the number of servers in 'server_list'
Returns:
0 on success, -1 on failure.

Definition at line 410 of file comm_encode.c.

{
  int i;

  if(!server_list) 
    return -1;

  *msg = dstring_sprintf("%d ", num_servers);

  for(i=0;i<num_servers;i++) {

    *msg = dstring_append(*msg, server_list[i]);
    *msg = dstring_append(*msg, " ");
  }

  return 0;
}

Here is the call graph for this function:

int gs_encode_server ( char **  encoding,
gs_server_t *  gs_server 
)

Encodes all the necessary information about a server to XML data.

Parameters:
encoding -- on return, contains the encoded server
gs_server -- the server to be encoded
Returns:
0 on success, -1 on failure.

Definition at line 677 of file comm_encode.c.

{
  gs_server_t *s = gs_server;   /* just a shortcut name */
  char componentid_string[CID_LEN*2+1], server_dottedIP[20], 
    proxy_dottedIP[20];

  if(!gs_server)
    return -1;

  proxy_cid_to_str(componentid_string, s->componentid);
  proxy_ip_to_str(s->ipaddress, server_dottedIP);
  proxy_ip_to_str(s->proxyip, proxy_dottedIP);

  *encoding = dstring_sprintf("<server> <hostname> %s </hostname> <ipaddress> %s </ipaddress> <port> %hu </port> <proxyip> %s </proxyip> <proxyport> %hu </proxyport> <componentid> %s </componentid> <arch> %s </arch> <data_format> %d </data_format> <kflops> %d </kflops> <workload> %d </workload> <ncpu> %d </ncpu> <status> %d </status> <availcpu> %lg </availcpu> <availmem> %lg </availmem> <nproblems> %d </nproblems> <agenthost> %s </agenthost> <agentport> %d </agentport> <score> %g </score> <smart> %d </smart> </server>\n", s->hostname, server_dottedIP, s->port, proxy_dottedIP, s->proxyport, componentid_string, s->arch, s->data_format, s->kflops, s->workload, s->ncpu, s->status, s->availcpu, s->availmem, s->nproblems, s->agenthost, s->agentport, s->score, s->smart);

  if(gs_encode_infolist(encoding,s->sa_list) < 0)
    return -1;
 /* 
#ifdef GS_SMART_GRIDSOLVE
   *encoding = dstring_sprintf("<smart_info>");
   int i =0;
   int numSmartServers;
   for (i=0; i<numSmartServers; i++) {
     *encoding = dstring_sprintf("<componentid> %s </componentid>  <time> %f </time> \n", server[i]->comp_id, server[i]->time);
   }
  *encoding = dstring_sprintf("</smart_info>");
#endif
  */

  DBGPRINTF("server strlen %d encoding %s\n", (int)(strlen(*encoding)), *encoding);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gs_encode_smart_info ( char **  encoding,
gs_server_t *  server,
gs_server_t **  server_list,
double *  times,
int  count 
)

Encodes all the ping timing information of server-server links

Parameters:
encoding -- on return, contains the encoded server-server link data
gs_server -- the server which does the pinging
Returns:
0 on success, -1 on failure.

Definition at line 591 of file comm_encode.c.

                                                                                                               {

  char componentid_string[CID_LEN*2+1];
  char *stmp = NULL;
  int i;    
  gs_server_t **s = server_list;   /* just a shortcut name */
  *encoding = dstring_sprintf("<smart_info>\n");
  stmp = dstring_sprintf("<count> %d </count>\n", count);
  *encoding = dstring_append_free(*encoding , stmp);

  for(i=0;i<count;i++){
    if(!s[i]){
      return -1;
    }
    proxy_cid_to_str(componentid_string, s[i]->componentid);
    stmp = dstring_sprintf("<componentid> %s </componentid>  <time> %f </time> \n", componentid_string, times[i]);
    *encoding = dstring_append_free(*encoding, stmp);
  }
   stmp = dstring_sprintf("</smart_info>");
   *encoding = dstring_append_free(*encoding, stmp);
  return 0;
}

Here is the call graph for this function:

int gs_encode_workload_report ( char **  msg,
int  workload,
int  nproblems,
char *  server_cid 
)

Encodes a workload report message. The format is: <workload> <server component="" id>="">

Parameters:
msg -- on return, contains the encoded message
workload -- this machine's current workload
server_cid -- this machine's component id
Returns:
0 on success, -1 on failure.

Definition at line 856 of file comm_encode.c.

{
  if(!server_cid)
    return -1;

  *msg = dstring_sprintf("%d %d %s", workload, nproblems, server_cid);

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: