grr/server/grr_response_server/databases/mysql_flows.py
def _ReadCurrentFlowInfo(self, responses, currently_available_requests,
                           next_request_by_flow, responses_expected_by_request,
                           current_responses_by_request, cursor):
    """Reads stored data for flows we want to modify."""
    flow_conditions = []
    flow_args = []
    req_conditions = []
    req_args = []
    for r in responses:
      flow_conditions.append("(client_id=%s AND flow_id=%s)")
      flow_args.append(mysql_utils.ClientIDToInt(r.client_id))
      flow_args.append(mysql_utils.FlowIDToInt(r.flow_id))

      req_conditions.append("(client_id=%s AND flow_id=%s AND request_id=%s)")
      req_args.append(mysql_utils.ClientIDToInt(r.client_id))
      req_args.append(mysql_utils.FlowIDToInt(r.flow_id))
      req_args.append(r.request_id)

    flow_query = ("SELECT client_id, flow_id, next_request_to_process "
                  "FROM flows WHERE ")
    flow_query += " OR ".join(flow_conditions)

    req_query = ("SELECT client_id, flow_id, request_id, responses_expected "
                 "FROM flow_requests WHERE ")
    req_query += " OR ".join(req_conditions)

    res_query = ("SELECT client_id, flow_id, request_id, response_id "
                 "FROM flow_responses WHERE ")
    res_query += " OR ".join(req_conditions)

    cursor.execute(flow_query, flow_args)

    for row in cursor.fetchall():
      client_id_int, flow_id_int, next_request_to_process = row
      client_id = mysql_utils.IntToClientID(client_id_int)
      flow_id = mysql_utils.IntToFlowID(flow_id_int)
      next_request_by_flow[(client_id, flow_id)] = next_request_to_process

    cursor.execute(req_query, req_args)

    for row in cursor.fetchall():
      client_id_int, flow_id_int, request_id, responses_expected = row
      client_id = mysql_utils.IntToClientID(client_id_int)
      flow_id = mysql_utils.IntToFlowID(flow_id_int)
      request_key = (client_id, flow_id, request_id)
      currently_available_requests.add(request_key)
      if responses_expected:
        responses_expected_by_request[request_key] = responses_expected

    cursor.execute(res_query, req_args)

    for row in cursor.fetchall():
      client_id_int, flow_id_int, request_id, response_id = row
      client_id = mysql_utils.IntToClientID(client_id_int)
      flow_id = mysql_utils.IntToFlowID(flow_id_int)
      request_key = (client_id, flow_id, request_id)
      current_responses_by_request.setdefault(request_key,
                                              set()).add(response_id)
Reads stored data for flows we want to modify.
Reads stored data for flows we want to modify.
Reads stored data for flows we want to modify .
def _ReadCurrentFlowInfo(self, responses, currently_available_requests,
                           next_request_by_flow, responses_expected_by_request,
                           current_responses_by_request, cursor):
    flow_conditions = []
    flow_args = []
    req_conditions = []
    req_args = []
    for r in responses:
      flow_conditions.append("(client_id=%s AND flow_id=%s)")
      flow_args.append(mysql_utils.ClientIDToInt(r.client_id))
      flow_args.append(mysql_utils.FlowIDToInt(r.flow_id))
      req_conditions.append("(client_id=%s AND flow_id=%s AND request_id=%s)")
      req_args.append(mysql_utils.ClientIDToInt(r.client_id))
      req_args.append(mysql_utils.FlowIDToInt(r.flow_id))
      req_args.append(r.request_id)
    flow_query = ("SELECT client_id, flow_id, next_request_to_process "
                  "FROM flows WHERE ")
    flow_query += " OR ".join(flow_conditions)
    req_query = ("SELECT client_id, flow_id, request_id, responses_expected "
                 "FROM flow_requests WHERE ")
    req_query += " OR ".join(req_conditions)
    res_query = ("SELECT client_id, flow_id, request_id, response_id "
                 "FROM flow_responses WHERE ")
    res_query += " OR ".join(req_conditions)
    cursor.execute(flow_query, flow_args)
    for row in cursor.fetchall():
      client_id_int, flow_id_int, next_request_to_process = row
      client_id = mysql_utils.IntToClientID(client_id_int)
      flow_id = mysql_utils.IntToFlowID(flow_id_int)
      next_request_by_flow[(client_id, flow_id)] = next_request_to_process
    cursor.execute(req_query, req_args)
    for row in cursor.fetchall():
      client_id_int, flow_id_int, request_id, responses_expected = row
      client_id = mysql_utils.IntToClientID(client_id_int)
      flow_id = mysql_utils.IntToFlowID(flow_id_int)
      request_key = (client_id, flow_id, request_id)
      currently_available_requests.add(request_key)
      if responses_expected:
        responses_expected_by_request[request_key] = responses_expected
    cursor.execute(res_query, req_args)
    for row in cursor.fetchall():
      client_id_int, flow_id_int, request_id, response_id = row
      client_id = mysql_utils.IntToClientID(client_id_int)
      flow_id = mysql_utils.IntToFlowID(flow_id_int)
      request_key = (client_id, flow_id, request_id)
      current_responses_by_request.setdefault(request_key,
                                              set()).add(response_id)
def _ReadCurrentFlowInfo ( self , responses , currently_available_requests , next_request_by_flow , responses_expected_by_request , current_responses_by_request , cursor ) : flow_conditions = [ ] flow_args = [ ] req_conditions = [ ] req_args = [ ] for r in responses : flow_conditions . append ( "(client_id=%s AND flow_id=%s)" ) flow_args . append ( mysql_utils . ClientIDToInt ( r . client_id ) ) flow_args . append ( mysql_utils . FlowIDToInt ( r . flow_id ) ) req_conditions . append ( "(client_id=%s AND flow_id=%s AND request_id=%s)" ) req_args . append ( mysql_utils . ClientIDToInt ( r . client_id ) ) req_args . append ( mysql_utils . FlowIDToInt ( r . flow_id ) ) req_args . append ( r . request_id ) flow_query = ( "SELECT client_id, flow_id, next_request_to_process " "FROM flows WHERE " ) flow_query += " OR " . join ( flow_conditions ) req_query = ( "SELECT client_id, flow_id, request_id, responses_expected " "FROM flow_requests WHERE " ) req_query += " OR " . join ( req_conditions ) res_query = ( "SELECT client_id, flow_id, request_id, response_id " "FROM flow_responses WHERE " ) res_query += " OR " . join ( req_conditions ) cursor . execute ( flow_query , flow_args ) for row in cursor . fetchall ( ) : client_id_int , flow_id_int , next_request_to_process = row client_id = mysql_utils . IntToClientID ( client_id_int ) flow_id = mysql_utils . IntToFlowID ( flow_id_int ) next_request_by_flow [ ( client_id , flow_id ) ] = next_request_to_process cursor . execute ( req_query , req_args ) for row in cursor . fetchall ( ) : client_id_int , flow_id_int , request_id , responses_expected = row client_id = mysql_utils . IntToClientID ( client_id_int ) flow_id = mysql_utils . IntToFlowID ( flow_id_int ) request_key = ( client_id , flow_id , request_id ) currently_available_requests . add ( request_key ) if responses_expected : responses_expected_by_request [ request_key ] = responses_expected cursor . execute ( res_query , req_args ) for row in cursor . fetchall ( ) : client_id_int , flow_id_int , request_id , response_id = row client_id = mysql_utils . IntToClientID ( client_id_int ) flow_id = mysql_utils . IntToFlowID ( flow_id_int ) request_key = ( client_id , flow_id , request_id ) current_responses_by_request . setdefault ( request_key , set ( ) ) . add ( response_id )
Reads stored data for flows we want to modify.
Reads stored data for flows we want to modify .
"""Reads stored data for flows we want to modify."""
self
responses
currently_available_requests
next_request_by_flow
responses_expected_by_request
current_responses_by_request
cursor